Terraform: lookup() may only be used with flat maps, this map contains elements of type list

Created on 9 May 2017  ยท  2Comments  ยท  Source: hashicorp/terraform

Terraform Version: 0.9.4

module
main.tf

resource "aws_vpc_peering_connection" "peering" {
    count           = "${var.enable}"
:
:
:
}

# routing table entry for terraformed stateless environment
resource "aws_route" "peer-routing" {
    count                       = "${var.enable * length(lookup(var.vpc, "route_table_ids"))}"
    route_table_id              = "${element(lookup(var.vpc, "route_table_ids"), count.index)}"
    destination_cidr_block      = "${lookup(var.peer_vpc, "cidr")}"
    vpc_peering_connection_id   = "${aws_vpc_peering_connection.peering.id}"
}

# conditional routing table entry for stateful environment
resource "aws_route" "peer-routing-stateful" {
    #count                       = "${var.enable * length(lookup(var.peer_vpc, "route_table_ids")) * (lookup(var.peer_vpc, "owner_id") == lookup(var.vpc, "owner_id") ? 1 : 0) }"
    count                       = "${var.enable * length(lookup(var.peer_vpc, "route_table_ids")) * (lookup(var.peer_vpc, "owner_id") == lookup(var.vpc, "owner_id") ? 1 : 0) }"
    #count                       = "${length(lookup(var.peer_vpc, "route_table_ids"))}"
    route_table_id              = "${element(lookup(var.peer_vpc, "route_table_ids"), count.index)}"
    destination_cidr_block      = "${lookup(var.vpc, "cidr")}"
    vpc_peering_connection_id   = "${aws_vpc_peering_connection.peering.id}"
}

vpc_peering.tf

module "vpc_peering" "prod_peering" {
    source                  = "../terraform_modules/my-awesome-vpc-peering/"
    enable                  = 1

    environment             = "${var.ct_environment_name}"
    vpc {
        "vpc_id"            = "${module.main_vpc.vpc_id}"
        "owner_id"          = "${var.ct_account_id}"
        "cidr"              = "${var.ct_vpc_cidr}"
        "route_table_ids"   = ["${module.main_vpc.vpc_private_routing_table_id}", "${module.main_vpc.vpc_public_routing_table_id}"]
    }
    peer_vpc {
        "vpc_id"        = "${lookup(var.ct_master_vpc, "vpc_id")}"
        "owner_id"      = "${lookup(var.ct_master_vpc, "account")}"
        "cidr"          = "${var.ct_stateful_vpc_cidr}"
        "route_table_ids"   = [""]
    }
}

terraform plan

1 error(s) occurred:

* module.vpc_peering.aws_route.peer-routing-stateful: lookup: lookup() may only be used with flat maps, this map contains elements of type list in:

${var.enable * length(lookup(var.peer_vpc, "route_table_ids")) * (lookup(var.peer_vpc, "owner_id") == lookup(var.vpc, "owner_id") ? 1 : 0) }

Is there an easy way to get around this apart from moving the list out of the map

question

Most helpful comment

You can just use dictionary syntax without using lookup at all...

${var.enable * length(var.peer_vpc["route_table_ids"]) * (lookup(var.peer_vpc, "owner_id") == lookup(var.vpc, "owner_id") ? 1 : 0) }

All 2 comments

You can just use dictionary syntax without using lookup at all...

${var.enable * length(var.peer_vpc["route_table_ids"]) * (lookup(var.peer_vpc, "owner_id") == lookup(var.vpc, "owner_id") ? 1 : 0) }

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.

Was this page helpful?
0 / 5 - 0 ratings