https://pulumi.com logo
#general
Title
# general
m

melodic-doctor-70522

08/15/2023, 2:27 AM
Hello, does anyone have any idea how to reference the ids of the components in an application gateway in azure native?
Copy code
gateway_ip_configurations=[network.ApplicationGatewayIPConfigurationArgs(
    name=data_conf["appGateway_conf"]["gateway_ip_configurations"]["name"],
    subnet=network.SubnetArgs(
        id=gateway_sbnt.id,
    ),
)],
frontend_ip_configurations=[network.ApplicationGatewayFrontendIPConfigurationArgs(
    name=data_conf["appGateway_conf"]["frontend_ip_configurations"]["name"],
    public_ip_address=network.PublicIPAddressArgs(
        id=gateway_public_ip.id
    )
)],
frontend_ports=[network.ApplicationGatewayFrontendPortArgs(
    name=data_conf["appGateway_conf"]["frontend_ports"]["name"],
    port=data_conf["appGateway_conf"]["frontend_ports"]["port"],
)],
backend_address_pools=[network.ApplicationGatewayBackendAddressPoolArgs(
    name=data_conf["appGateway_conf"]["backend_address_pools"]["name"],
    backend_addresses=[network.ApplicationGatewayBackendAddressArgs(
        ip_address=VM_nic.ip_configurations[0].private_ip_address) for VM_nic in VM_nics]
)],
backend_http_settings_collection=[network.ApplicationGatewayBackendHttpSettingsArgs(
    name= data_conf["appGateway_conf"]["backend_http_settings_collection"]["name"],
    cookie_based_affinity=data_conf["appGateway_conf"]["backend_http_settings_collection"]["cookie_based_affinity"],
    port=data_conf["appGateway_conf"]["backend_http_settings_collection"]["port"],
    protocol=data_conf["appGateway_conf"]["backend_http_settings_collection"]["protocol"],
    request_timeout=data_conf["appGateway_conf"]["backend_http_settings_collection"]["request_timeout"]
)],
http_listeners=[network.ApplicationGatewayHttpListenerArgs(
    name= data_conf["appGateway_conf"]["http_listeners"]["name"],
    protocol=data_conf["appGateway_conf"]["http_listeners"]["protocol"],
    frontend_ip_configuration=network.SubResourceArgs(id=pulumi.Output.all(resourcegroup.name).apply(lambda args: f"/subscriptions/{data_conf['subscription_id']}/resourceGroups/{args[0]}/providers/Microsoft.Network/applicationGateways/frontendIPConfigurations/{data_conf['appGateway_conf']['frontend_ip_configurations']['name']}")),
    frontend_port=network.SubResourceArgs(id=pulumi.Output.all(resourcegroup.name).apply(lambda args:f"/subscriptions/{data_conf['subscription_id']}/resourceGroups/{args[0]}/providers/Microsoft.Network/applicationGateways/frontendPorts/{data_conf['appGateway_conf']['frontend_ports']['name']}")),
)],
request_routing_rules=[network.ApplicationGatewayRequestRoutingRuleArgs(
    name=data_conf["appGateway_conf"]["request_routing_rules"]["name"],
    rule_type=data_conf["appGateway_conf"]["request_routing_rules"]["rule_type"],
    priority=data_conf["appGateway_conf"]["request_routing_rules"]["priority"],
    http_listener=network.SubResourceArgs(id= pulumi.Output.all(resourcegroup.name).apply(lambda args: f"/subscriptions/{data_conf['subscription_id']}/resourceGroups/{args[0]}/providers/Microsoft.Network/applicationGateways/httpListeners/{data_conf['appGateway_conf']['http_listeners']['name']}")),
    backend_address_pool=network.SubResourceArgs(id=pulumi.Output.all(resourcegroup.name).apply(lambda args: f"/subscriptions/{data_conf['subscription_id']}/resourceGroups/{args[0]}/providers/Microsoft.Network/applicationGateways/backendAddressPools/{data_conf['appGateway_conf']['backend_address_pools']['name']}")),
    backend_http_settings=network.SubResourceArgs(id=pulumi.Output.all(resourcegroup.name).apply(lambda args: f"/subscriptions/{data_conf['subscription_id']}/resourceGroups/{args[0]}/providers/Microsoft.Network/applicationGateways/backendHttpSettingsCollection/{data_conf['appGateway_conf']['backend_http_settings_collection']['name']}")),
)]
f

fast-vr-6049

08/15/2023, 7:43 PM
The Azure Native provider recently added the ability to refer to sub-resources via a relative ID, which should save you here. You no longer have to do those big formatted strings! You can instead just write
$self/frontEndConfigurations/my-frontend
, for example. https://www.pulumi.com/registry/packages/azure-native/api-docs/network/applicationgateway/#subresource