PaloAltoNetworks / terraform-aws-swfw-modules

Terraform Reusable Modules for Software Firewalls on AWS
https://registry.terraform.io/modules/PaloAltoNetworks/swfw-modules/aws
MIT License
14 stars 11 forks source link

[Bug Report] <Unable to execute plan successfully upon module asg.> #92

Open Karatonev opened 2 weeks ago

Karatonev commented 2 weeks ago

Describe the bug

I am trying to use the ASG module. The invocation of the module is as follows:

module "paloalto" { source = "../../../terraform-aws-swfw-modules/modules/asg" ssh_key_name = "paloalto" interfaces = { mgmt = { device_index = 0 subnet_id = "subnet-xxxxxxxxxxxxxxxxxxx" name = "mgmt" create_public_ip = true source_dest_check = true security_group_ids = ["sg-xxxxxxxxxxxxxxx"] }, public = { device_index = 1 subnet_id = "subnet-xxxxxxxxxxxxxxxxxxx" name = "public" create_public_ip = true source_dest_check = true security_group_ids = ["sg-xxxxxxxxxxxxxxx"] }, private = { device_index = 2 subnet_id = "subnet-xxxxxxxxxxxxxxxxxxx" name = "private" create_public_ip = false source_dest_check = true security_group_ids = ["sg-xxxxxxxxxxxxxxx"] } } global_tags = {} region="eu-west-1" name_prefix = "palo-alto-test" target_group_arn = aws_lb_target_group.this.arn

}

I stumbled across the following:

default_eni_subnet_names = flatten([for k, v in var.interfaces : v.subnet_id if v.device_index == 0]) //Line 29

This is going to produce a list.

Then this: subnet_id = values(local.default_eni_subnet_names[0])[0] // Line 72

Module Version

2.0.16

Terraform version

Terraform v1.9.7

Expected behavior

Run terraform plan successfuly.

Current behavior

│ Error: Error in function call │ │ on ......\terraform-aws-swfw-modules\modules\asg\main.tf line 72, in resource "aws_launch_template" "this": │ 72: subnet_id = values(local.default_eni_subnet_names[0])[0] │ ├──────────────── │ │ while calling values(mapping) │ │ local.default_eni_subnet_names[0] is "subnet-027e04xxxxxx" │ │ Call to function "values" failed: values() requires a map as the first argument.

Anything else to add?

No response

acelebanski commented 1 week ago

Hello @Karatonev, try passing a map to subnet_id where key is availability zone name and value is subnet id.

Like this:

subnet_id = {
  "eu-west-1a" = "sg-xxxxxxxxxxxxxxx"
}

If you're deploying in multiple AZs, you can add more keys to this map.