本文介绍了地形>强制安全组上的新资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一段非常简单的 Terraform 代码:
I've got a very simple piece of Terraform code:
provider "aws" {
region = "eu-west-1"
}
module ec2 {
source = "./ec2_instance"
name = "EC2 Instance 1"
}
模块在哪里:
variable "name" {
default = "Default Name from ec2_instance.tf"
}
resource "aws_instance" "example" {
ami = "ami-e5083683"
instance_type = "t2.nano"
subnet_id = "subnet-3e976259"
associate_public_ip_address = true
security_groups = [ "sg-7310e10b" ]
tags {
Name = "${var.name}"
}
}
当我第一次运行它时,我得到这个输出:
When I first run it I get this output:
security_groups.#: "" => "1"
security_groups.1642973399: "" => "sg-7310e10b"
但是,下次我尝试 plan
时,我得到:
However, the next time I try a plan
I get:
security_groups.#: "0" => "1" (forces new resource)
security_groups.1642973399: "" => "sg-7310e10b" (forces new resource)
什么给了?!
推荐答案
您错误地将 vpc_security_group_id 分配到 security_groups 而不是 vpc_security_group_ids.将
security_groups = [ "sg-7310e10b" ]
更改为
vpc_security_group_ids = [ "sg-7310e10b" ] 一切都会好起来的.
You are incorrectly assigning a vpc_security_group_id into security_groups instead of into vpc_security_group_ids. Change
security_groups = [ "sg-7310e10b" ]
to
vpc_security_group_ids = [ "sg-7310e10b" ] and everything will be ok.
这篇关于地形>强制安全组上的新资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!