Lookup function is not evaluated to a string

Hi.

I have a following configuration:

locals {
    vol_type = "${lookup(module.config_service_instance.result_map, "NOT_EXISTED!!!", "gp3")}"
    root_block_device = "${list(map("volume_type", local.vol_type, "volume_size", var.root_volume_size, "delete_on_termination", "true"))}"
}

Running terraform plan I’m getting:

Error: module.master_node.module.ec2_instance.aws_instance.this: root_block_device: should be a list

It works as expected if I’m using explicitly defined string:

locals {
    vol_type = "gp3"
    root_block_device = "${list(map("volume_type", local.vol_type, "volume_size", var.root_volume_size, "delete_on_termination", "true"))}"
}

I thing that lookup function doesn’t evaluate correctly or returns a wrong data type.
It should return a string - “gp3”.

Terraform Version

Terraform v0.11.15

Hi @iliyahoo,

Unfortunately you are using a very old version of the Terraform language which has poor support for anything other than simple string values.

I would suggest planning to upgrade at least to the latest v0.12 release as soon as possible, because that is the first version whose language properly supports constructing complex nested data types, such as the list of objects you are trying to construct here.

Upgrading to v0.12 does involve making changes to your configuration to deal with some ambiguity and limitations of the legacy language, but the later v0.11 releases and the v0.12 releases together provide tools to help identify potential problems and, as much as possible, automatically update your configuration. You can learn more about that in the Terraform v0.12 Upgrade Guide.

1 Like