PaloAltoNetworks/terraform-aws-vmseries-modules

coalesce cannot be used with an empty tuple

Closed this issue · 2 comments

Describe the bug

When vmseries_ami_id is specified in the vmseries module the plan errors out.

Expected behavior

If vmseries_ami_id is specified data.aws_ami.this[0].id should be ignored.

Current behavior

Error: Invalid index

  on ../../modules/vmseries/main.tf line 59, in resource "aws_instance" "this":
  59:   ami = coalesce(var.vmseries_ami_id, data.aws_ami.this[0].id)
    |----------------
    | data.aws_ami.this is empty tuple

The given key does not identify an element in this collection value.

Possible solution

coalesce(var.vmseries_ami_id, try(data.aws_ami.this[0].id, null) )

We should look through the whole code base and fix any issues with coalesce

I've identified only one occurrence of coalesce() used with a tuple in the repository - in the mentioned vmseries module. Will create a PR with a fix.