# AzureNatGatewayExtensions Methods

- Package: [Aspire.Hosting.Azure.Network](/reference/api/csharp/aspire.hosting.azure.network.md)
- Type: [AzureNatGatewayExtensions](/reference/api/csharp/aspire.hosting.azure.network/azurenatgatewayextensions.md)
- Kind: `Methods`
- Members: `2`

Provides extension methods for adding Azure NAT Gateway resources to the application model.

## AddNatGateway(IDistributedApplicationBuilder, string)

- Name: `AddNatGateway(IDistributedApplicationBuilder, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureNatGatewayResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Azure.Network/AzureNatGatewayExtensions.cs#L44-L56)

Adds an Azure NAT Gateway resource to the application model.

```csharp
public static class AzureNatGatewayExtensions
{
    public static IResourceBuilder<AzureNatGatewayResource> AddNatGateway(
        this IDistributedApplicationBuilder builder,
        string name)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
  The builder for the distributed application.
- `name` (`string`)
  The name of the Azure NAT Gateway resource.

## Returns

`IResourceBuilder<AzureNatGatewayResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## Remarks

The NAT Gateway is created with Standard SKU. If no Public IP Address is explicitly associated via [AzureNatGatewayExtensions.WithPublicIPAddress(IResourceBuilder<AzureNatGatewayResource>, IResourceBuilder<AzurePublicIPAddressResource>)](/reference/api/csharp/aspire.hosting.azure.network/azurenatgatewayextensions/methods.md#withpublicipaddress-iresourcebuilder-azurenatgatewayresource-iresourcebuilder-azurepublicipaddressresource), a Public IP Address is automatically created in the NAT Gateway's bicep module with Standard SKU and Static allocation.

## Examples

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

```csharp
var natGateway = builder.AddNatGateway("nat");

var vnet = builder.AddAzureVirtualNetwork("vnet");
var subnet = vnet.AddSubnet("aca-subnet", "10.0.0.0/23")
    .WithNatGateway(natGateway);
```

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithPublicIPAddress(IResourceBuilder<AzureNatGatewayResource>, IResourceBuilder<AzurePublicIPAddressResource>)

- Name: `WithPublicIPAddress(IResourceBuilder<AzureNatGatewayResource>, IResourceBuilder<AzurePublicIPAddressResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureNatGatewayResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Azure.Network/AzureNatGatewayExtensions.cs#L82-L86)

Associates an explicit Public IP Address resource with the NAT Gateway.

```csharp
public static class AzureNatGatewayExtensions
{
    public static IResourceBuilder<AzureNatGatewayResource> WithPublicIPAddress(
        this IResourceBuilder<AzureNatGatewayResource> builder,
        IResourceBuilder<AzurePublicIPAddressResource> publicIPAddress)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureNatGatewayResource>`)
  The NAT Gateway resource builder.
- `publicIPAddress` (`IResourceBuilder<AzurePublicIPAddressResource>`)
  The Public IP Address resource to associate.

## Returns

`IResourceBuilder<AzureNatGatewayResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1` for chaining.

## Remarks

When an explicit Public IP Address is provided, the NAT Gateway will not auto-create one.

## Examples

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

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

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.
