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

TF silently fails to set AWS tags #4163

Closed
feliksik opened this issue Dec 4, 2015 · 1 comment
Closed

TF silently fails to set AWS tags #4163

feliksik opened this issue Dec 4, 2015 · 1 comment

Comments

@feliksik
Copy link

feliksik commented Dec 4, 2015

Using the AWS provider, it seems that setting a tag with a a failed lookup() value prevents any tag from being set. I think we should receive an error here?

summary:

        # this would be good
        #Name = "${var.prefix} subnet ${ lookup(var.zones, count.index+1) }"

        # this silently fails so set the tags, because I forgot the .index in count
        Name = "${var.prefix} subnet ${ lookup(var.zones, count+1) }"
        Maintainer = "${var.maintainer}"

full tf file:

variable "aws_access_key" {}
variable "aws_secret_key" {}
variable "prefix" {}
variable "maintainer" {}

variable "az_count" { default = 3 }

variable "zones" {
    default = {
        "1" = "eu-west-1a"
        "2" = "eu-west-1b"
        "3" = "eu-west-1c"
    }
}

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

output "subnet_ids" { 
        value = "${ join(\",\", aws_subnet.sdnet.*.id) }" 
}

provider "aws" {
    access_key = "${var.aws_access_key}"
    secret_key = "${var.aws_secret_key}"
    region = "eu-west-1"
}

resource "aws_vpc" "main" {
    cidr_block = "10.10.0.0/16"
    enable_dns_support = true
    enable_dns_hostnames = true
    tags {
        Name = "${var.prefix} vpc"
        Maintainer = "${var.maintainer}"
    }
}

resource "aws_internet_gateway" "main" {
    vpc_id = "${aws_vpc.main.id}"
    tags {
        Name = "${var.prefix} gateway"
        Maintainer = "${var.maintainer}"
    }
}

resource "aws_route_table" "main" {
    vpc_id = "${aws_vpc.main.id}"
    route {
        cidr_block = "0.0.0.0/0"
        gateway_id = "${aws_internet_gateway.main.id}"
    }
    tags {
        Name = "${var.prefix} route table"
        Maintainer = "${var.maintainer}"
    }
}

resource "aws_route_table_association" "main" {
    subnet_id = "${element(aws_subnet.sdnet.*.id, count.index)}"
    route_table_id = "${aws_route_table.main.id}"
}

resource "aws_subnet" "sdnet" {
    count = "${var.az_count}"
    vpc_id = "${aws_vpc.main.id}"
    availability_zone = "${ lookup(var.zones, count.index+1) }"
    cidr_block = "10.10.${count.index+1}.0/24"
    map_public_ip_on_launch = true
    tags {

        # this would be good
        #Name = "${var.prefix} subnet ${ lookup(var.zones, count.index+1) }"

        # this silently fails so set the tags
        Name = "${var.prefix} subnet ${ lookup(var.zones, count+1) }"
        Maintainer = "${var.maintainer}"
    }
}

@ghost
Copy link

ghost commented Apr 11, 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 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants