https://pulumi.com logo
Title
c

colossal-room-15708

03/31/2020, 11:00 PM
What's the best way to achieve this
for
loop here?
vnet = network.VirtualNetwork('ssvc-vnet',
  resource_group_name=resource_group.name,
  name="ssvc-vnet-{0}".format(stack_name),
  address_spaces=[ssvc_vnet_space],
  subnets= [
    for subnet in subnet_config:
      {
        name=subnet[0],
        address_prefix=subnet[1],
        virtual_network_name=vnet.name
      )
      },
  ]
)
It's syntactically incorrect, so I'm wondering what the best way to get this done anyways might be.
okay, this works:
custom_subnets = []
for subnet in subnet_config:
  custom_subnets.append({"name":subnet[0],"address_prefix":subnet[1]})

# networking resources
vnet = network.VirtualNetwork('ssvc-vnet',
  resource_group_name=resource_group.name,
  name="ssvc-vnet-{0}".format(stack_name),
  address_spaces=[ssvc_vnet_space],
  subnets=custom_subnets
)
n

nutritious-shampoo-16116

04/01/2020, 7:42 AM
alternatively, using list comprehension:
subnets = [
    {
        name=subnet[0],
        address_prefix=subnet[1],
        virtual_network_name=vnet.name
    } for subnet in subnet_config
]
👍🏽 2
c

colossal-room-15708

04/01/2020, 9:26 AM
oh, that's so much nicer!
n

nutritious-shampoo-16116

04/01/2020, 10:00 AM
subnets = [
    {
        "name":subnet[0],
        "address_prefix": subnet[1],
        "virtual_network_name": vnet.name
    } for subnet in subnet_config
]
fixed the dict, = wont' work