VPCIdNotSpecified: No default VPC for this user

538 views
Skip to first unread message

Tony Wong

unread,
Jun 30, 2020, 10:45:33 AM6/30/20
to terrafo...@googlegroups.com
ANy idea why I am getting this error?


aws_security_group.instance: Creating...

Error: Error creating Security Group: VPCIdNotSpecified: No default VPC for this user
        status code: 400, request id: b1eba04c-45db-4f26-b991-b075f7ffa807

  on main.tf line 29, in resource "aws_security_group" "instance":
  29: resource "aws_security_group" "instance" {




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"]
}
}

Jamie Gruener

unread,
Jun 30, 2020, 12:11:18 PM6/30/20
to terrafo...@googlegroups.com

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.

Reply all
Reply to author
Forward
0 new messages