Skip to content
Docs Try Aspire

AzureNatGatewayExtensions Methods

Class Methods 2 members
Provides extension methods for adding Azure NAT Gateway resources to the application model.
AddNatGateway(IDistributedApplicationBuilder, string) Section titled AddNatGateway(IDistributedApplicationBuilder, string) extension IResourceBuilder<AzureNatGatewayResource>
Adds an Azure NAT Gateway resource to the application model.
public static class AzureNatGatewayExtensions
{
public static IResourceBuilder<AzureNatGatewayResource> AddNatGateway(
this IDistributedApplicationBuilder builder,
string name)
{
// ...
}
}
builder IDistributedApplicationBuilder The builder for the distributed application.
name string The name of the Azure NAT Gateway resource.
IResourceBuilder<AzureNatGatewayResource> A reference to the ApplicationModel.IResourceBuilder`1.
The NAT Gateway is created with Standard SKU. If no Public IP Address is explicitly associated via AzureNatGatewayExtensions.WithPublicIPAddress, a Public IP Address is automatically created in the NAT Gateway's bicep module with Standard SKU and Static allocation.

This example creates a NAT Gateway and associates it with a subnet:

var natGateway = builder.AddNatGateway("nat");
var vnet = builder.AddAzureVirtualNetwork("vnet");
var subnet = vnet.AddSubnet("aca-subnet", "10.0.0.0/23")
.WithNatGateway(natGateway);
WithPublicIPAddress(IResourceBuilder<AzureNatGatewayResource>, IResourceBuilder<AzurePublicIPAddressResource>) Section titled WithPublicIPAddress(IResourceBuilder<AzureNatGatewayResource>, IResourceBuilder<AzurePublicIPAddressResource>) extension IResourceBuilder<AzureNatGatewayResource>
Associates an explicit Public IP Address resource with the NAT Gateway.
public static class AzureNatGatewayExtensions
{
public static IResourceBuilder<AzureNatGatewayResource> WithPublicIPAddress(
this IResourceBuilder<AzureNatGatewayResource> builder,
IResourceBuilder<AzurePublicIPAddressResource> publicIPAddress)
{
// ...
}
}
builder IResourceBuilder<AzureNatGatewayResource> The NAT Gateway resource builder.
publicIPAddress IResourceBuilder<AzurePublicIPAddressResource> The Public IP Address resource to associate.
IResourceBuilder<AzureNatGatewayResource> A reference to the ApplicationModel.IResourceBuilder`1 for chaining.
When an explicit Public IP Address is provided, the NAT Gateway will not auto-create one.

This example creates a NAT Gateway with an explicit Public IP:

var pip = builder.AddPublicIPAddress("nat-pip");
var natGateway = builder.AddNatGateway("nat")
.WithPublicIPAddress(pip);