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

Graph not resolving correctly using modules #2188

Closed
jjshoe opened this issue Jun 2, 2015 · 2 comments · Fixed by #2477
Closed

Graph not resolving correctly using modules #2188

jjshoe opened this issue Jun 2, 2015 · 2 comments · Fixed by #2477
Assignees

Comments

@jjshoe
Copy link

jjshoe commented Jun 2, 2015

I've bumped into a situation where the graph doesn't seem to depend on a module correctly. I've boiled it down to a simple test case:

The main terraform file:

variable "aws_region" {}
variable "aws_access_key" {}
variable "aws_secret_key" {}

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

resource "aws_vpc" "env_vpc" {
    cidr_block = "10.1.0.0/16"

    tags {
        Name = "test-vpc"
    }
}

resource "aws_subnet" "env_subnet" {
    vpc_id = "${aws_vpc.env_vpc.id}"
    cidr_block = "10.2.0.0/20"
    availability_zone = "us-east-1a"
    map_public_ip_on_launch = true

    tags {
        Name = "test-subnet"
    }
}

module "accounts" {
    source = "../modules/test_app"

    service_subnets = "${join(",", aws_subnet.env_subnet.*.id)}"
}

The module:

variable "service_subnets" {}

output "test" {
    value = "${var.service_subnets}"
}

Expected:
A list of subnets made

Received:

  • Resource 'aws_subnet.env_subnet' does not have attribute 'id' for variable 'aws_subnet.env_subnet.*.id'

Graph:
graph

@jjshoe
Copy link
Author

jjshoe commented Jun 2, 2015

Workaround:

variable "aws_region" {}
variable "aws_access_key" {}
variable "aws_secret_key" {}

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

resource "aws_vpc" "env_vpc" {
    cidr_block = "10.1.0.0/16"

    tags {
        Name = "test-vpc"
    }
}

resource "aws_subnet" "env_subnet" {
    vpc_id = "${aws_vpc.env_vpc.id}"
    cidr_block = "10.2.0.0/20"
    availability_zone = "us-east-1a"
    map_public_ip_on_launch = true

    tags {
        Name = "test-subnet"
    }
}

resource "template_file" "workaround" {
    filename = "./terraform/templates/workaround.tpl"

    vars {
        subnets = "${join(",", aws_subnet.env_subnet.*.id)}"
    }
}

module "accounts" {
    source = "../modules/test_app"

    service_subnets = "${template_file.workaround.vars.subnets}"
}

@ghost
Copy link

ghost commented May 2, 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 May 2, 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