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

Terraform aws - not able to output vpc main_route_table_id #4398

Closed
worldspawn opened this issue Dec 20, 2015 · 5 comments · Fixed by #4762
Closed

Terraform aws - not able to output vpc main_route_table_id #4398

worldspawn opened this issue Dec 20, 2015 · 5 comments · Fixed by #4762

Comments

@worldspawn
Copy link

Hi,

i'm trying to output a newly created vpc's main_route_table_id attribute.

output "main_route_table_id" {
  value "${aws_vpc.main.main_route_table_id}"
}

However it always comes out as blank.

image

As you can see I don't have trouble outputting other values.

I can see it's being set in the tfstate file.

"aws_vpc.main": {
                    "type": "aws_vpc",
                    "primary": {
                        "id": "vpc-7471e011",
                        "attributes": {
                            "cidr_block": "10.0.0.0/16",
                            "default_network_acl_id": "acl-510f6634",
                            "default_security_group_id": "sg-0d360968",
                            "dhcp_options_id": "dopt-18f6177d",
                            "enable_dns_hostnames": "true",
                            "enable_dns_support": "true",
                            "id": "vpc-7471e011",
                            "instance_tenancy": "default",
                            "main_route_table_id": "rtb-26fe9443",
                            "tags.#": "2",
                            "tags.Application": "test2",
                            "tags.Production": "0"
                        }
                    }
                }

Not sure what I'm doing wrong :'(

(Terraform v0.6.8)

@jen20
Copy link
Contributor

jen20 commented Dec 21, 2015

Hi @worldspawn. Thanks for reporting this - your configuration looks correct as far as I can see, so this looks like a bug. Could you post the resource definitions for your VPC and routing table as well, and I'll try to reproduce/fix?

@worldspawn
Copy link
Author

Here it is:

variable "aws_access_key" {}
variable "aws_secret_key" {}
variable "application_name" {}
variable "region" {
  default = "ap-southeast-2"
}
variable "production" {
  default = "false"
}

provider "aws" {
    access_key = "${var.aws_access_key}"
    secret_key = "${var.aws_secret_key}"
    region = "${var.region}"
}

resource "aws_vpc" "main" {
    cidr_block = "10.0.0.0/16"
    instance_tenancy = "default"
    enable_dns_support = true
    enable_dns_hostnames = true

    tags {
        Application = "${var.application_name}"
        Production = "${var.production}"
    }
}

resource "aws_subnet" "main" {
    vpc_id = "${aws_vpc.main.id}"
    cidr_block = "10.0.0.0/24"
    availability_zone = "${var.region}a"

    tags {
        Application = "${var.application_name}"
        Production = "${var.production}"
    }
}

resource "aws_subnet" "alt" {
    vpc_id = "${aws_vpc.main.id}"
    cidr_block = "10.0.1.0/24"
    availability_zone = "${var.region}b"

    tags {
        Application = "${var.application_name}"
        Production = "${var.production}"
    }
}

resource "aws_internet_gateway" "gw" {
    vpc_id = "${aws_vpc.main.id}"

    tags {
      Application = "${var.application_name}"
      Production = "${var.production}"
    }
}

output "vpc_id" {
  value = "${aws_vpc.main.id}"
}

output "main_subnet_id" {
  value = "${aws_subnet.main.id}"
}

output "alt_subnet_id" {
  value = "${aws_subnet.alt.id}"
}

output "main_route_table_id" {
  value "${aws_vpc.main.main_route_table_id}"
}

Note i'm not defining a route table, i'm expecting it to give me the name of the default route table created when i create the vpc.

@phinze
Copy link
Contributor

phinze commented Jan 20, 2016

Hi @worldspawn - just dug into this and verified the code is correct. That's when I noticed the cause - your main_route_table_id output is missing an equals sign. Easy fix! 😀

I'll look into whether we can provide a better error message for this, but in the meantime that should get you the proper behavior.

phinze added a commit that referenced this issue Jan 20, 2016
Also lists out invalid keys in errmsg when they are present

Closes #4398
phinze added a commit that referenced this issue Jan 20, 2016
Also lists out invalid keys in errmsg when they are present

Closes #4398
phinze added a commit that referenced this issue Jan 20, 2016
Also lists out invalid keys in errmsg when they are present

Closes #4398
@worldspawn
Copy link
Author

Sorry about that :) thanks

bigkraig pushed a commit to bigkraig/terraform that referenced this issue Mar 1, 2016
Also lists out invalid keys in errmsg when they are present

Closes hashicorp#4398
@ghost
Copy link

ghost commented Apr 28, 2020

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 Apr 28, 2020
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.

3 participants