我正在尝试使用此设置创建EC2服务器。 plan
并未抱怨任何内容,但在运行apply
时出现此错误:
* aws_instance.example: Failed to update vpc_security_group_ids
on "i-04b724c52ac598fd8", which does not contain a primary network interface
知道可能出错的是什么? 我正在使用Terraform v0.9.6
main.tf
provider "aws" {
region = "us-east-1"
}
resource "aws_instance" "example" {
ami = "ami-40d28157"
instance_type = "m3.medium"
vpc_security_group_ids = ["${aws_security_group.instance.id}"]
tags {
Name = "up-and-running"
}
}
resource "aws_security_group" "instance" {
name = "terraform-example-instance-1"
ingress {
from_port = 8080
to_port = 8080
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
答案 0 :(得分:0)
您应使用vpc_id
param为安全组资源指明您的安全组是在哪个VPC中创建的。它必须指向您正在创建ec2实例的相同VPC:
resource "aws_security_group" "instance" {
name = "terraform-example-instance-1"
vpc_id = "${var.your_vpc_id}"
ingress {
from_port = 8080
to_port = 8080
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}