resource "aws_instance" "test" {
ami = "ami-0d084dc1254addb04"
instance_type = "t2.micro"
count = "${var.instance_count}"
vpc_security_group_ids = [aws_security_group.instance.id]
key_name = "t2micro-1"
#user_data = <<-EOF
# #!/bin/bash
# sudo yum install busybox -y
# echo "Hello, World" > index.html
# nohup busybox httpd -f -p 8080 &
# EOF
tags = {
Name = "terraform-example"
}
}
resource "aws_security_group" "instance" {
name = "terraform-example"
ingress {
from_port = 8080
to_port = 8080
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
Best guess is that you don’t actually have a “default” VPC in whatever region you’re trying to create this security group. The “default” VPC has special qualities. YMMV, but I’ve found that just explicitly defining the VPC is the easiest thing to do. If you haven’t already defined the VPC with aws_vpc, use a data resource to get the ID.
https://www.terraform.io/docs/providers/aws/r/security_group.html
https://www.terraform.io/docs/providers/aws/r/instance.html
--Jamie
--
This mailing list is governed under the HashiCorp Community Guidelines -
https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
terraform-too...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/terraform-tool/CALmkhkrgA2aJQuNEdk29wFKvT6GA7Pwzwdurn4ZhjeEXiVj4_A%40mail.gmail.com.