Terraform Unable to create EC2 instance - VPCIdNotSpecified: No default VPC for this user

1,392 views
Skip to first unread message

sabyasachi dash

unread,
Dec 28, 2018, 7:57:30 AM12/28/18
to Terraform
Hi All,

New to terraform ..have been trying to create a EC2 instance that failed with below error message.Would appreciate any guidance

Error: Error applying plan:

1 error(s) occurred:

* aws_instance.GAL_server: 1 error(s) occurred:

* aws_instance.GAL_server: Error launching source instance: VPCIdNotSpecified: No default VPC for this user
        status code: 400, request id: 9aa484a8-817f-4c4e-b712-da37097a93f1

The apply command created a new VPC and subnets, but unable to associate the instance.

Tried to add the VPC id but no luck ...

c:\terraform\galinfra>terraform plan

Error: aws_instance.GAL_server: : invalid or unknown key: vpc_id

resource "aws_instance" "GAL_server" {
ami = "ami-08935252a36e25f85"
instance_type = "t2.micro"
vpc_id = "${aws_vpc.My_VPC.id}"
tags = {
Name = "Testinstance"
}
}

Valentin Mariette

unread,
Dec 28, 2018, 8:21:32 AM12/28/18
to terrafo...@googlegroups.com
Hello

You have a ressources named default_vpc. You Can used it like a source to tout vpc_id 


Regards 

--
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/b4f524fb-822e-43c6-8ab8-7ddd9f66f27f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

sabyasachi dash

unread,
Dec 28, 2018, 9:17:44 AM12/28/18
to Terraform
Hi Valentin,

Thanks for the suggestion but it did not work.May be because I have already created a VPC earlier and that marked as default.

is there a way to associate existing one to this instance.Tried couple of options but looks like I am doing soemthing silly.

here is the VPC created and I want to link it to my EC2
resource "aws_vpc" "My_VPC" {
cidr_block = "10.0.0.0/16"

tags = {
Name = "MyVPC"
}
}


The Ec2 file has below content

resource "aws_vpc" "My_VPC" {
cidr_block = "10.0.0.0/16"

tags = {
Name = "MyVPC"
}
}

sabyasachi dash

unread,
Dec 31, 2018, 5:54:54 AM12/31/18
to Terraform
Hi all,

The issue is now resolved after crating a default VPC

For some reason the default VPC was missing and new instances were not getting associated with newly created VPC.

Regards,
Sabya

Asad Ullah

unread,
Jan 5, 2019, 10:18:21 AM1/5/19
to Terraform
# Use this for your instance

resource "aws_instance" "MyInstance" {
ami = "${lookup(var.AMIS, var.AWS_REGION)}"
instance_type = "t2.micro"
tags{
Name = "MyInstance"
}

# Use this into your vars.tf for AMI's map
variable "AMIS" {
type = "map"
default = {
us-east-1 = "ami-0f9cf087c1f27d9b1"
us-east-2 = "ami-0653e888ec96eab9b"
eu-west-1 = "ami-844e0bf7"
}
## In above map you can use the zone according to your requirements. and the amis too, below is the link of the Ubuntu AMI's


also create the map of AWS regions to;
Thnaks


Reply all
Reply to author
Forward
0 new messages