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 · 24 comments

Comments

Projects
None yet
@WillAbides

WillAbides commented Dec 17, 2015

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

This comment has been minimized.

Show comment
Hide comment
@stack72
Contributor

stack72 commented Dec 17, 2015

@WillAbides

This comment has been minimized.

Show comment
Hide comment
@WillAbides

WillAbides Dec 17, 2015

@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.

WillAbides commented Dec 17, 2015

@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

This comment has been minimized.

Show comment
Hide comment
@catsby

catsby Dec 18, 2015

Member

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

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

This comment has been minimized.

Show comment
Hide comment
@donwb

donwb 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?

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

This comment has been minimized.

Show comment
Hide comment
@jhovell

jhovell 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

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

This comment has been minimized.

Show comment
Hide comment
@drusellers

drusellers Sep 25, 2016

Just hit this today

drusellers commented Sep 25, 2016

Just hit this today

@samirspatel

This comment has been minimized.

Show comment
Hide comment
@samirspatel

samirspatel 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.

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

This comment has been minimized.

Show comment
Hide comment
@djandruczyk

djandruczyk 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

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

This comment has been minimized.

Show comment
Hide comment
@nielsonsantana

nielsonsantana 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.

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

This comment has been minimized.

Show comment
Hide comment
@anibalsanchez

anibalsanchez Mar 18, 2017

Same issue. The tutorial is not clear.

anibalsanchez commented Mar 18, 2017

Same issue. The tutorial is not clear.

@pulyankote

This comment has been minimized.

Show comment
Hide comment
@pulyankote

pulyankote Mar 18, 2017

any resolution to this? I have the same problem.

pulyankote commented Mar 18, 2017

any resolution to this? I have the same problem.

@jamtur01

This comment has been minimized.

Show comment
Hide comment
@jamtur01

jamtur01 Mar 18, 2017

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.

Contributor

jamtur01 commented Mar 18, 2017

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

This comment has been minimized.

Show comment
Hide comment
@pulyankote

pulyankote Mar 18, 2017

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

pulyankote commented Mar 18, 2017

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

This comment has been minimized.

Show comment
Hide comment
@anibalsanchez

anibalsanchez commented Mar 19, 2017

@jamtur01

This comment has been minimized.

Show comment
Hide comment
Contributor

jamtur01 commented Mar 19, 2017

@rodrigoSyscop

This comment has been minimized.

Show comment
Hide comment
@rodrigoSyscop

rodrigoSyscop 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 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

This comment has been minimized.

Show comment
Hide comment
@rodrigoSyscop

rodrigoSyscop Apr 8, 2017

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

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

rodrigoSyscop commented Apr 8, 2017

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

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

This comment has been minimized.

Show comment
Hide comment
@MarkusKramer

MarkusKramer Apr 26, 2017

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

MarkusKramer commented Apr 26, 2017

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

@MadOtis

This comment has been minimized.

Show comment
Hide comment
@MadOtis

MadOtis 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'

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

This comment has been minimized.

Show comment
Hide comment
@Adron

Adron 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

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

This comment has been minimized.

Show comment
Hide comment
@sinzin91

sinzin91 May 23, 2017

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

sinzin91 commented May 23, 2017

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 added a commit to yebyen/tf-ec2-example that referenced this issue Oct 22, 2017

WIP: looks like you can't just...
put a t2.micro on the public internet without adding other
infrastructure first

hashicorp/terraform#4367
@NinoSkopac

This comment has been minimized.

Show comment
Hide comment
@NinoSkopac

NinoSkopac Nov 9, 2017

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

NinoSkopac commented Nov 9, 2017

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

@reyou

This comment has been minimized.

Show comment
Hide comment
@reyou

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

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

This comment has been minimized.

Show comment
Hide comment
@nnathan

nnathan 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.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment