rhythmic-receptionist-62263
02/09/2023, 10:22 PMpolicySet = [{'policyid' : '/providers/Microsoft.Authorization/policyDefinitions/4f11b553-d42e-4e3a-89be-32ca364cad4c',
'policyname' : '3 Max SubOwners'},
{'policyid' : '/providers/Microsoft.Authorization/policyDefinitions/044985bb-afe1-42cd-8a36-9d5d42424537',
'policyname' : 'AuditExpiredStorageKeys'}]
count = 0
for policyObject in policySet:
count = count + 1
assignmentName = "policyAssignment" + str(count)
policy_assignment = authorization.PolicyAssignment(assignmentName,
policy_assignment_name=policyObject['policyname'],
policy_definition_id=policyObject['policyid'],
scope=managementGroup)
First question is, what is the best approach here? Ideally I'd like to get this array from an external file be it json/whatever. The documentation doesn't delve very deep into using external data or more complex configurations beyond simple key/values.
I initially though I could leverage the config but when using a yaml array of objects it gets translated into an array of strings when its accessed using the Config(). So I tried the above by just creating an inline array, but when this ran through it was only showing that it would create a single policy assignment rather than 2.steep-toddler-94095
02/10/2023, 12:30 AMpolicyname
in your JSON object.
The documentation doesn't delve very deep into using external data or more complex configurations beyond simple key/values.i think this is on purpose. the best way to retrieve outside data depends on your specific situation, and since you're given the full power of a general purpose language, there's a lot of options. In your specific case, where is the "source of truth" for this configuration data you want to pass into Pulumi?
rhythmic-receptionist-62263
02/10/2023, 12:53 AMsteep-toddler-94095
02/10/2023, 1:06 AMjson.load
f = open("./path/to/yourData.json")
policySet = json.load(f)
...
rhythmic-receptionist-62263
02/10/2023, 2:38 AM