Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example in getting started guide fails because t2.micro requires a VPC #4367

Closed
WillAbides opened this issue Dec 17, 2015 · 32 comments · Fixed by #4405
Closed

Example in getting started guide fails because t2.micro requires a VPC #4367

WillAbides opened this issue Dec 17, 2015 · 32 comments · Fixed by #4405

Comments

@WillAbides
Copy link

The example in the getting started guide fails because the t2.micro instance requires a VPC and no VPC is specified in the example. I worked around by reverting to t1.micro and the ami listed in this version of the doc.

 ~/hack/terraform-test    terraform apply
aws_instance.example: Creating...
  ami:                      "" => "ami-d05e75b8"
  availability_zone:        "" => "<computed>"
  ebs_block_device.#:       "" => "<computed>"
  ephemeral_block_device.#: "" => "<computed>"
  instance_type:            "" => "t2.micro"
  key_name:                 "" => "<computed>"
  placement_group:          "" => "<computed>"
  private_dns:              "" => "<computed>"
  private_ip:               "" => "<computed>"
  public_dns:               "" => "<computed>"
  public_ip:                "" => "<computed>"
  root_block_device.#:      "" => "<computed>"
  security_groups.#:        "" => "<computed>"
  source_dest_check:        "" => "1"
  subnet_id:                "" => "<computed>"
  tenancy:                  "" => "<computed>"
  vpc_security_group_ids.#: "" => "<computed>"
Error applying plan:

1 error(s) occurred:

* aws_instance.example: Error launching source instance: VPCResourceNotSpecified: The specified instance type can only be used in a VPC. A subnet ID or network interface ID is required to carry out the request.
    status code: 400, request id:

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.
@stack72
Copy link
Contributor

stack72 commented Dec 17, 2015

@WillAbides do you mean on this page? https://terraform.io/intro/getting-started/build.html

@WillAbides
Copy link
Author

@stack72 Yes, that's the page I meant. Although after going through the rest of the getting started documentation I had to keep substituting the old images for the ones on the current page.

@catsby
Copy link
Member

catsby commented Dec 18, 2015

Hey @WillAbides sorry for that, I changed them all recently in #4330 to try and update the docs, but I clearly overlooked this situation (my account has a default VPC). I'll get this cleaned up

@donwb
Copy link

donwb commented Dec 18, 2015

interesting that we're hitting this at almost the exact same time. I checked the PR above, but it seemed to be changing things to use ami-d05e75b8 with t2.micro, which doesn't work for me. I switched to m3.large and didn't have any problems. What is the suggested way to launch a t2.micro?

@jhovell
Copy link

jhovell commented Dec 19, 2015

@donwb as the subject of this issue states t2 instances must be launched into a VPC. So, to launch one you need to create or specify a VPC, Subnet, etc which isn't included in the tutorial. I think you're just running into this issue now because the docs recently changed. Maybe the old m1.small instance types will work for you...

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/t2-instances.html

@drusellers
Copy link

Just hit this today

@samirspatel
Copy link

samirspatel commented Nov 1, 2016

I ran into this exact same issue while trying to get started with terraform. I corrected the issue by switching to an m3.medium

resource "aws_instance" "example" {
  ami           = "ami-408c7f28"
  instance_type = "m3.medium"
}

The error message

Error applying plan:

1 error(s) occurred:

* aws_instance.example: Error launching source instance: VPCResourceNotSpecified: The specified instance type can only be used in a VPC. A subnet ID or network interface ID is required to carry out the request.
        status code: 400, request id: 38266bc0-f95d-4fc3-a0bf-ebd9a11b0623

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.

@djandruczyk
Copy link

djandruczyk commented Nov 15, 2016

Attempting to use the above:

Example Resource

resource "aws_instance" "example" {
ami = "ami-408c7f28"
instance_type = "m3.medium"
}
fails for me...
terraform apply
aws_instance.example: Creating...
ami: "" => "ami-408c7f28"
associate_public_ip_address: "" => ""
availability_zone: "" => ""
ebs_block_device.#: "" => ""
ephemeral_block_device.#: "" => ""
instance_state: "" => ""
instance_type: "" => "m3.medium"
key_name: "" => ""
network_interface_id: "" => ""
placement_group: "" => ""
private_dns: "" => ""
private_ip: "" => ""
public_dns: "" => ""
public_ip: "" => ""
root_block_device.#: "" => ""
security_groups.#: "" => ""
source_dest_check: "" => "true"
subnet_id: "" => ""
tenancy: "" => ""
vpc_security_group_ids.#: "" => ""
Error applying plan:

1 error(s) occurred:

  • aws_instance.example: Error launching source instance: InvalidAMIID.NotFound: The image id '[ami-408c7f28]' does not exist
    status code: 400, request id: 22a474f8-47e9-4a9a-8740-8e745c77f2da

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.

This is using the latest: Terraform v0.7.10

@nielsonsantana
Copy link

nielsonsantana commented Feb 13, 2017

Images have different iam codes for each region. Per example, Ubuntu 16.04 in São Paulo-BR has code ami-7379e31f and on Virgina-US has code ami-6edd3078 for the same image. Then if you try launch a image from São Paulo(ami-7379e31f) in Virginia, won't work.

@anibalsanchez
Copy link

Same issue. The tutorial is not clear.

@pulyankote
Copy link

any resolution to this? I have the same problem.

@jamtur01
Copy link
Contributor

There's no easy to fix this - it's a moving target of instance types and AMIs - is the existing note not sufficient? I think it's pretty clear but open to ideas to make it clearer.

@pulyankote
Copy link

sorry, am new to this, but which existing note are you referring to? This link gives 404 error
https://github.com/hashicorp/terraform/blob/28d39cd0bc7e9212eeea77f871cf4d4c7df0da73/docs/providers/index.html

@anibalsanchez
Copy link

This is the example that works for aws: https://github.com/hashicorp/terraform/tree/master/examples/aws-two-tier

@jamtur01
Copy link
Contributor

screenshot 2017-03-19 10 20 40

From: https://www.terraform.io/intro/getting-started/build.html

@rodrigoSyscop
Copy link

rodrigoSyscop commented Apr 8, 2017

Or, because old aws accounts doesn't have a default VPC, just use the subnet_id inside aws_instance resource:

resource "aws_instance" "example" {
    ami           = "ami-2757f631"
    instance_type = "t2.micro"
    subnet_id     = "subnet-123abc12"
}

You must create a VPC with that subnet before.

@rodrigoSyscop
Copy link

Oh, and use vpc = true on the next page:

resource "aws_eip" "ip" {
    vpc      = true
    instance = "${aws_instance.example.id}"
}

@MarkusKramer
Copy link

It is really sad when the first example in a getting started guide doesn't work.

@MadOtis
Copy link

MadOtis commented Apr 26, 2017

I was able to work around the issue by adding a security group ID and subnet ID. Basically, this:

provider "aws" {
  region = "us-west-2"
}

resource "aws_instance" "bogus1" {
  ami = "ami-04c14c64"
  instance_type = "t2.micro"
}

becomes this:

provider "aws" {
  region = "us-west-2"
}

resource "aws_instance" "example" {
  ami = "ami-04c14c64"
  instance_type = "t2.micro"
  vpc_security_group_ids = ["<my_security_group_id>"]
  subnet_id = "<my_subnet_id>"
}

...obviously, replacing my_xxxxxx values with your actual subnet and security group ids

So, for documentation, you may want to add an outset that mentions "If you don't have a default VPC created, you may want to also add these two elements to your resource... blah, blah, blah'

@Adron
Copy link

Adron commented May 22, 2017

This is still... not really working. I've run into this myself just now. The AMI listed in the example doesn't work and reports back the whole...

==> amazon-ebs: Error launching source instance: VPCResourceNotSpecified: The specified instance type can only be used in a VPC. A subnet ID or network interface ID is required to carry out the request.
==> amazon-ebs:         status code: 400, request id: bdad1b26-c82b-4e13-8c1d-2053dc523c25
==> amazon-ebs: No volumes to clean up, skipping
==> amazon-ebs: Deleting temporary security group...
==> amazon-ebs: Deleting temporary keypair...
Build 'amazon-ebs' errored: Error launching source instance: VPCResourceNotSpecified: The specified instance type can only be used in a VPC. A subnet ID or network interface ID is required to carry out the request.
        status code: 400, request id: bdad1b26-c82b-4e13-8c1d-2053dc523c25

@sinzin91
Copy link

The below worked for me, but requires creating a VPC and subnet:

provider "aws" {
  access_key = "ACCESS_KEY_HERE"
  secret_key = "SECRET_KEY_HERE"
  region = "us-east-1"
}

resource "aws_instance" "example" {
  ami = "ami-2757f631"
  instance_type = "t2.micro"
  subnet_id = "${aws_subnet.us-east-1a-public.id}"
}

resource "aws_vpc" "example" {
  cidr_block = "10.0.0.0/16"
  enable_dns_hostnames = true
  enable_dns_support = true
}

resource "aws_subnet" "us-east-1a-public" {
  vpc_id = "${aws_vpc.example.id}"
  cidr_block = "10.0.1.0/25"
  availability_zone = "us-east-1a"
}

kingdonb pushed a commit to yebyen/tf-ec2-example that referenced this issue Oct 22, 2017
put a t2.micro on the public internet without adding other
infrastructure first

hashicorp/terraform#4367
@NinoSkopac
Copy link

@sinzin91's comment fixed it for me. Really not great when the very first example fails, eh?

@reyou
Copy link

reyou commented Jan 17, 2018

I just hit today, and I believe docs needs to be updated for non VPC users with;

resource "aws_instance" "example" {
  ami           = "ami-408c7f28"
  instance_type = "t1.micro"
}

@nnathan
Copy link

nnathan commented Jun 27, 2018

I also just hit this issue today. I changed instance type to t1.micro and everything worked as usual. Docs still need updating.

@KjetilM
Copy link

KjetilM commented Jan 4, 2019

MadOtis comment helped med get past this. But someone should really have a look at the getting starting docs.
I get that learning by failing is a thing, but maybe let people get started before we start failing and flailing? ;)

@jonathan-schmieg
Copy link

the issue is more than 3 years old and it still has not been fixed 👎

@8wgremlin
Copy link

I'm in region ap-southeast2 and I had to change it to

resource "aws_instance" "example" {
ami = "ami-0c9d48b5db609ad6e"
instance_type = "t2.micro"
}

might be good to get this info right, for first-time users.

@marcellanz
Copy link

that issue just hit me

@danielpacker
Copy link

danielpacker commented Jun 29, 2019

that issue just hit me

Same, just hit me June 29, 2019. 3.5 years after issue opened. Granted, it forced me to learn about VPC dependencies, but as others have said, this example should be updated in the documentation.

@jamtur01 As @MadOtis and others suggested, a gentle reminder that you may need to create the VPC/subnet/security group before the example works would be nice, perhaps with a link to an example like the one @sinzin91 posted that creates said resources. I think people are still getting stuck on this point... not sure why my default VPC wasn't already up to par, but I had to do manual steps. Thanks for otherwise great docs.

PS. It turns out my AWS is old enough that it includes EC2 classic capabilities, so default VPC is not available without having customer support intervene. So if the docs mentioned older accounts need the vpc creation step, rather than default vpc, that would be helpful. Some folks new to terraform might also be new to this limitation as per this thread.

@GenuineUnPerson
Copy link

Hitting this exact problem mid 2019 - why is this issue closed??
(t2 -> t2.micro was the sole fix required here)

@ArtemChekunov
Copy link

I think the best solution is: aws-console -> new support issue -> "Regarding: Account and Billing Support" -> "Service: Account" -> "Category: Convert EC2 Classic to VPC".

@ghost
Copy link

ghost commented Jul 24, 2019

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Jul 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.