Search code examples
amazon-web-servicesterraformterraform-provider-aws

terraform: unable to set vpc name?


I am starting to learn terraform. I created a vpc thusly:

resource "aws_vpc" "my-vpc" {
  cidr_block = "10.0.0.0/16"

  tags = {
    terraform = "true"
  }
}

I thought it would be named my-vpc in the management console but it wasn't. The name is blank. And on the documentation page there is no "name" attribute: when I tried setting a name I got an error during the apply (An argument named "name" is not expected here.)

I can't believe you can't set a name?! What am I missing?

enter image description here


Solution

  • Name of a VPC is just a tag called Name:

    resource "aws_vpc" "my-vpc" {
      cidr_block = "10.0.0.0/16"
    
      tags = {
        terraform = "true"
        Name = "myvpc"
      }
    }