Error launching source instance: InvalidSubnetID.NotFound: The subnet ID 'XXX' does not exist

3,451 views
Skip to first unread message

John Kennedy

unread,
May 21, 2015, 1:04:57 PM5/21/15
to terrafo...@googlegroups.com
I am VERY new to Terraform but I like it so far...

We have just started using Terraform in our existing AWS environment. Like many others, we are anxiously awaiting the ability to determine existing AWS environment state to be added.

Until then, we are creating tf files individually per server which I know is not the best way but I have to follow, for now.

I am trying to build an instance (tf file below) and I keep getting the above error. I am using the correct AWS keys and I know the subnet ID is correct. What am I missing? Is there a way to specify the VPC? 

If I remove the subnet line it complains about the default VPC which no longer exists (before I got here).


resource "aws_instance" "<name>" {
  ami = "ami-XXX"
  instance_type = "m3.medium"
  subnet_id = "subnet-XXX"
  associate_public_ip_address = true
  source_dest_check = false
  iam_instance_profile = "<name>"
  user_data = "${replace(replace(file("files/standard-cloud-init.yaml"),"<serverhostname>", "hostname-1"),"<serverenvironment>","prod")}"
  key_name = "<name>"
  security_groups = ["sg-XXX"]
  tags {
      Name = "<hostname"
      Tier = "presentation"
      Customer = "<customer>"
      Profiles = "apache"
      Role = "cloud-proxy"
      Environment = "prod"
  }
  ebs_block_device {
      device_name = "/dev/sdf"
      volume_type = "gp2"
      volume_size = "25"
  }
  ebs_block_device {
      device_name = "/dev/sda"
      volume_type = "gp2"
      volume_size = "8"
  }
}

John Kennedy  (_8(|)
I have a yellow dog:
http://www.theyellowdogproject.com/The_Yellow_Dog_Project/About.html

Anatidaephobia is the fear that somehow, somewhere a duck is watching you - urbandictionary.com

The Dunning-Kruger effect occurs when incompetent people not only fail to realize their incompetence, but consider themselves much more competent than everyone else. Basically - they're too stupid to know that they're stupid.

VGSR Disclaimer: The opinions expressed in this email are mine and do not reflect the opinions of VGSR or their board of directors.

Andrew Langhorn

unread,
May 21, 2015, 1:24:18 PM5/21/15
to John Kennedy, terrafo...@googlegroups.com
Unless I've misunderstood, you should probably look to define your VPC using the aws_vpc provider - details at https://terraform.io/docs/providers/aws/r/vpc.html - inside your Terraform VPC configuration first, then reference it's ID attribute (examples in the docs) to attach your EC2 instance to.

Happy to elaborate further if needs be.
--
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 post to this group, send email to terrafo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/CAD6OLfwgyWEtQz4WGy-Zg2gn0F-Zk7dQ0WTpf-FFJYdzGQUSNw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


--

John Kennedy

unread,
May 21, 2015, 1:34:05 PM5/21/15
to Andrew Langhorn, terrafo...@googlegroups.com
Andrew,
Thanks for the info. If I do this, will Terraform remove and recreate the VPC since it has not been "listed" in the tfstate file or will Terraform go out and find the ID to output?
John


John Kennedy  (_8(|)
I have a yellow dog:
http://www.theyellowdogproject.com/The_Yellow_Dog_Project/About.html

Anatidaephobia is the fear that somehow, somewhere a duck is watching you - urbandictionary.com

The Dunning-Kruger effect occurs when incompetent people not only fail to realize their incompetence, but consider themselves much more competent than everyone else. Basically - they're too stupid to know that they're stupid.

VGSR Disclaimer: The opinions expressed in this email are mine and do not reflect the opinions of VGSR or their board of directors.

Andrew Langhorn

unread,
May 21, 2015, 2:17:47 PM5/21/15
to John Kennedy, terrafo...@googlegroups.com
From memory, I've forgotten. But I think the tfstate file ignores things it previously knows about, so it may try and recreate it if it doesn't know about it regardless of whether it exists. Try creating a test VPC using Terraform then try recreating it again? Should be quite quick to do!
--

John Kennedy

unread,
May 21, 2015, 3:05:27 PM5/21/15
to Andrew Langhorn, terrafo...@googlegroups.com
Thanks. It turns out the problem was permissions on my IAM account...The person responsible has been flogged.

Thanks and sorry to bother everyone with a non-Terraform issue


John Kennedy  (_8(|)
I have a yellow dog:
http://www.theyellowdogproject.com/The_Yellow_Dog_Project/About.html

Anatidaephobia is the fear that somehow, somewhere a duck is watching you - urbandictionary.com

The Dunning-Kruger effect occurs when incompetent people not only fail to realize their incompetence, but consider themselves much more competent than everyone else. Basically - they're too stupid to know that they're stupid.

VGSR Disclaimer: The opinions expressed in this email are mine and do not reflect the opinions of VGSR or their board of directors.

Reply all
Reply to author
Forward
0 new messages