PaloAltoNetworks / terraform-aws-vmseries-modules

Terraform Reusable Modules for VM-Series on AWS
https://registry.terraform.io/modules/PaloAltoNetworks/vmseries-modules/aws
MIT License
40 stars 49 forks source link

coalesce cannot be used with an empty tuple #248

Closed jac4g09 closed 1 year ago

jac4g09 commented 1 year ago

Describe the bug

When vmseries_ami_id is specified in the asg 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 .terraform/modules/vm_series_asg/modules/asg/main.tf line 28, in resource "aws_launch_template" "this":
│   28:   image_id      = 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: the
│ collection has no elements.

Possible solution

same solution as Issue PR

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

welcome-to-palo-alto-networks[bot] commented 1 year ago

:tada: Thanks for opening your first issue here! Welcome to the community!

pimielowski commented 1 year ago

@jac4g09 thanks for the info! You are right, I test it and the problem exists there.

jac4g09 commented 1 year ago

Thanks for the quick response 😀