Closed mossholderm closed 12 months ago
A little more info...
Removing the count = var.instances
reference AND leaving the two target_device blocks works.
However, using count and a single target_devices block which references count.index as the array index fails with the same errors as in the initial post (code follows):
resource "fmc_policy_devices_assignments" "policy_assignment" {
count = var.instances
policy {
id = data.fmc_ftd_nat_policies.nat_policy.id
type = data.fmc_ftd_nat_policies.nat_policy.type
}
target_devices {
id = data.fmc_devices.device[count.index].id
type = data.fmc_devices.device[count.index].type
}
}
Could it be that fmc_policy_devices_assignments is broken when it comes to using the count keyword?
I found a solution... for those that might run into the same issue. You need to use a dynamic block to build out the target_devices blocks programmatically.
resource "fmc_policy_devices_assignments" "policy_assignment" {
policy {
id = data.fmc_ftd_nat_policies.nat_policy.id
type = data.fmc_ftd_nat_policies.nat_policy.type
}
dynamic "target_devices" {
for_each = toset(data.fmc_devices.device[*])
iterator = target_device
content {
id = target_device.value.id
type = target_device.value.type
}
}
}
Solution found.
Hey, not sure if this is just my lack of knowledge of Terraform, or something that is missing from the provider, so sorry in advance if this is covered elsewhere!
I'm trying to assign a NAT policy all of the FTD sensors created in the Terraform plan, but can't work out how to assign to more than one device. I have code that I think should work, but seems to fail. Sometimes the policy gets assigned to the devices (two in my current setup), but fails with this error:
Looking in the FMC after this run, the policy was assigned to both sensors, and I had removed all mappings prior to running the terraform code.
The code that produces the error is here:
Is there a way to make the code more dynamic? Is there method to add X many target devices blocks? I can't seem to work it out, and the examples don't seem to cover it.
Thanks so much!