Hi All,
I am trying to iterate through a nested map within a templatefile provided from the input variables.
I have seen one other post on this but it doesnt quite make sense to me in my scenario.
I basically have a yaml templatefile which is has the declaration for deploying an azure policy that appends NSG rules to all NSGs and i want to deploy these policies on a per subscription basis (this is my root map) but then for each subscription i want to be able to dynamically specify some of the NSG rule details in particular the list of IP addresses for the source or destination and this is my nested map.
below is the actual templatefile:
%{ for rule, value in subscriptions }
subscription_policy_assignment:
nsg-rule-tcp-inbound:
display_name: "NSG rule 1"
description: "This policy ensures that there is a rule on all nsgs."
enforce: true
policy_definition_name: common-nsg-rule
subscription_id: ${value.subscription_id}
identity: {}
parameters:
name: Allow-Tcp-Inbound
priority: 4000
direction: Inbound
access: Allow
protocol: "Tcp"
sourcePortRange:
- "*"
destinationPortRange:
- "5986"
- "443"
- "1433"
sourceAddressPrefix:
%{ for ranges in value.source_ranges ~}
- ${ranges}
%{ endfor ~}
destinationAddressPrefix:
- "10.0.96.0/19"
- "10.0.128.0/18"
effect: Append
%{ endfor ~}
and below is the input variables i am supplying:
subscriptions:
pr:
subscription_id: "xxx"
source_ranges:
- "10.0.6.0/23"
- "10.0.70.0/23"
everything appears correct to me but it does not work so not sure whether its because this is not possible or i have done something wrong
the error i get is:
│ Error: Error in function call
│
│ on main.tf line 17, in locals:
│ 17: policies = yamldecode(templatefile("./policies.tpl", local.envs[var.env].input_data))
│ ├────────────────
│ │ while calling yamldecode(src)
│ │ local.envs is object with 2 attributes
│ │ var.env is "prod"
│
│ Call to function "yamldecode" failed: on line 454, column 17: did not find
│ expected key.