azure.network.SubnetNatGatewayAssociation

Explore with Pulumi AI

Associates a NAT Gateway with a Subnet within a Virtual Network.

Example Usage

using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Azure = Pulumi.Azure;

return await Deployment.RunAsync(() => 
{
    var exampleResourceGroup = new Azure.Core.ResourceGroup("exampleResourceGroup", new()
    {
        Location = "West Europe",
    });

    var exampleVirtualNetwork = new Azure.Network.VirtualNetwork("exampleVirtualNetwork", new()
    {
        AddressSpaces = new[]
        {
            "10.0.0.0/16",
        },
        Location = exampleResourceGroup.Location,
        ResourceGroupName = exampleResourceGroup.Name,
    });

    var exampleSubnet = new Azure.Network.Subnet("exampleSubnet", new()
    {
        ResourceGroupName = exampleResourceGroup.Name,
        VirtualNetworkName = exampleVirtualNetwork.Name,
        AddressPrefixes = new[]
        {
            "10.0.2.0/24",
        },
    });

    var exampleNatGateway = new Azure.Network.NatGateway("exampleNatGateway", new()
    {
        Location = exampleResourceGroup.Location,
        ResourceGroupName = exampleResourceGroup.Name,
    });

    var exampleSubnetNatGatewayAssociation = new Azure.Network.SubnetNatGatewayAssociation("exampleSubnetNatGatewayAssociation", new()
    {
        SubnetId = exampleSubnet.Id,
        NatGatewayId = exampleNatGateway.Id,
    });

});
package main

import (
	"github.com/pulumi/pulumi-azure/sdk/v5/go/azure/core"
	"github.com/pulumi/pulumi-azure/sdk/v5/go/azure/network"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		exampleResourceGroup, err := core.NewResourceGroup(ctx, "exampleResourceGroup", &core.ResourceGroupArgs{
			Location: pulumi.String("West Europe"),
		})
		if err != nil {
			return err
		}
		exampleVirtualNetwork, err := network.NewVirtualNetwork(ctx, "exampleVirtualNetwork", &network.VirtualNetworkArgs{
			AddressSpaces: pulumi.StringArray{
				pulumi.String("10.0.0.0/16"),
			},
			Location:          exampleResourceGroup.Location,
			ResourceGroupName: exampleResourceGroup.Name,
		})
		if err != nil {
			return err
		}
		exampleSubnet, err := network.NewSubnet(ctx, "exampleSubnet", &network.SubnetArgs{
			ResourceGroupName:  exampleResourceGroup.Name,
			VirtualNetworkName: exampleVirtualNetwork.Name,
			AddressPrefixes: pulumi.StringArray{
				pulumi.String("10.0.2.0/24"),
			},
		})
		if err != nil {
			return err
		}
		exampleNatGateway, err := network.NewNatGateway(ctx, "exampleNatGateway", &network.NatGatewayArgs{
			Location:          exampleResourceGroup.Location,
			ResourceGroupName: exampleResourceGroup.Name,
		})
		if err != nil {
			return err
		}
		_, err = network.NewSubnetNatGatewayAssociation(ctx, "exampleSubnetNatGatewayAssociation", &network.SubnetNatGatewayAssociationArgs{
			SubnetId:     exampleSubnet.ID(),
			NatGatewayId: exampleNatGateway.ID(),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.azure.core.ResourceGroup;
import com.pulumi.azure.core.ResourceGroupArgs;
import com.pulumi.azure.network.VirtualNetwork;
import com.pulumi.azure.network.VirtualNetworkArgs;
import com.pulumi.azure.network.Subnet;
import com.pulumi.azure.network.SubnetArgs;
import com.pulumi.azure.network.NatGateway;
import com.pulumi.azure.network.NatGatewayArgs;
import com.pulumi.azure.network.SubnetNatGatewayAssociation;
import com.pulumi.azure.network.SubnetNatGatewayAssociationArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var exampleResourceGroup = new ResourceGroup("exampleResourceGroup", ResourceGroupArgs.builder()        
            .location("West Europe")
            .build());

        var exampleVirtualNetwork = new VirtualNetwork("exampleVirtualNetwork", VirtualNetworkArgs.builder()        
            .addressSpaces("10.0.0.0/16")
            .location(exampleResourceGroup.location())
            .resourceGroupName(exampleResourceGroup.name())
            .build());

        var exampleSubnet = new Subnet("exampleSubnet", SubnetArgs.builder()        
            .resourceGroupName(exampleResourceGroup.name())
            .virtualNetworkName(exampleVirtualNetwork.name())
            .addressPrefixes("10.0.2.0/24")
            .build());

        var exampleNatGateway = new NatGateway("exampleNatGateway", NatGatewayArgs.builder()        
            .location(exampleResourceGroup.location())
            .resourceGroupName(exampleResourceGroup.name())
            .build());

        var exampleSubnetNatGatewayAssociation = new SubnetNatGatewayAssociation("exampleSubnetNatGatewayAssociation", SubnetNatGatewayAssociationArgs.builder()        
            .subnetId(exampleSubnet.id())
            .natGatewayId(exampleNatGateway.id())
            .build());

    }
}
import pulumi
import pulumi_azure as azure

example_resource_group = azure.core.ResourceGroup("exampleResourceGroup", location="West Europe")
example_virtual_network = azure.network.VirtualNetwork("exampleVirtualNetwork",
    address_spaces=["10.0.0.0/16"],
    location=example_resource_group.location,
    resource_group_name=example_resource_group.name)
example_subnet = azure.network.Subnet("exampleSubnet",
    resource_group_name=example_resource_group.name,
    virtual_network_name=example_virtual_network.name,
    address_prefixes=["10.0.2.0/24"])
example_nat_gateway = azure.network.NatGateway("exampleNatGateway",
    location=example_resource_group.location,
    resource_group_name=example_resource_group.name)
example_subnet_nat_gateway_association = azure.network.SubnetNatGatewayAssociation("exampleSubnetNatGatewayAssociation",
    subnet_id=example_subnet.id,
    nat_gateway_id=example_nat_gateway.id)
import * as pulumi from "@pulumi/pulumi";
import * as azure from "@pulumi/azure";

const exampleResourceGroup = new azure.core.ResourceGroup("exampleResourceGroup", {location: "West Europe"});
const exampleVirtualNetwork = new azure.network.VirtualNetwork("exampleVirtualNetwork", {
    addressSpaces: ["10.0.0.0/16"],
    location: exampleResourceGroup.location,
    resourceGroupName: exampleResourceGroup.name,
});
const exampleSubnet = new azure.network.Subnet("exampleSubnet", {
    resourceGroupName: exampleResourceGroup.name,
    virtualNetworkName: exampleVirtualNetwork.name,
    addressPrefixes: ["10.0.2.0/24"],
});
const exampleNatGateway = new azure.network.NatGateway("exampleNatGateway", {
    location: exampleResourceGroup.location,
    resourceGroupName: exampleResourceGroup.name,
});
const exampleSubnetNatGatewayAssociation = new azure.network.SubnetNatGatewayAssociation("exampleSubnetNatGatewayAssociation", {
    subnetId: exampleSubnet.id,
    natGatewayId: exampleNatGateway.id,
});
resources:
  exampleResourceGroup:
    type: azure:core:ResourceGroup
    properties:
      location: West Europe
  exampleVirtualNetwork:
    type: azure:network:VirtualNetwork
    properties:
      addressSpaces:
        - 10.0.0.0/16
      location: ${exampleResourceGroup.location}
      resourceGroupName: ${exampleResourceGroup.name}
  exampleSubnet:
    type: azure:network:Subnet
    properties:
      resourceGroupName: ${exampleResourceGroup.name}
      virtualNetworkName: ${exampleVirtualNetwork.name}
      addressPrefixes:
        - 10.0.2.0/24
  exampleNatGateway:
    type: azure:network:NatGateway
    properties:
      location: ${exampleResourceGroup.location}
      resourceGroupName: ${exampleResourceGroup.name}
  exampleSubnetNatGatewayAssociation:
    type: azure:network:SubnetNatGatewayAssociation
    properties:
      subnetId: ${exampleSubnet.id}
      natGatewayId: ${exampleNatGateway.id}

Create SubnetNatGatewayAssociation Resource

new SubnetNatGatewayAssociation(name: string, args: SubnetNatGatewayAssociationArgs, opts?: CustomResourceOptions);
@overload
def SubnetNatGatewayAssociation(resource_name: str,
                                opts: Optional[ResourceOptions] = None,
                                nat_gateway_id: Optional[str] = None,
                                subnet_id: Optional[str] = None)
@overload
def SubnetNatGatewayAssociation(resource_name: str,
                                args: SubnetNatGatewayAssociationArgs,
                                opts: Optional[ResourceOptions] = None)
func NewSubnetNatGatewayAssociation(ctx *Context, name string, args SubnetNatGatewayAssociationArgs, opts ...ResourceOption) (*SubnetNatGatewayAssociation, error)
public SubnetNatGatewayAssociation(string name, SubnetNatGatewayAssociationArgs args, CustomResourceOptions? opts = null)
public SubnetNatGatewayAssociation(String name, SubnetNatGatewayAssociationArgs args)
public SubnetNatGatewayAssociation(String name, SubnetNatGatewayAssociationArgs args, CustomResourceOptions options)
type: azure:network:SubnetNatGatewayAssociation
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

name string
The unique name of the resource.
args SubnetNatGatewayAssociationArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name str
The unique name of the resource.
args SubnetNatGatewayAssociationArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name string
The unique name of the resource.
args SubnetNatGatewayAssociationArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args SubnetNatGatewayAssociationArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name String
The unique name of the resource.
args SubnetNatGatewayAssociationArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

SubnetNatGatewayAssociation Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

The SubnetNatGatewayAssociation resource accepts the following input properties:

NatGatewayId string

The ID of the NAT Gateway which should be associated with the Subnet. Changing this forces a new resource to be created.

SubnetId string

The ID of the Subnet. Changing this forces a new resource to be created.

NatGatewayId string

The ID of the NAT Gateway which should be associated with the Subnet. Changing this forces a new resource to be created.

SubnetId string

The ID of the Subnet. Changing this forces a new resource to be created.

natGatewayId String

The ID of the NAT Gateway which should be associated with the Subnet. Changing this forces a new resource to be created.

subnetId String

The ID of the Subnet. Changing this forces a new resource to be created.

natGatewayId string

The ID of the NAT Gateway which should be associated with the Subnet. Changing this forces a new resource to be created.

subnetId string

The ID of the Subnet. Changing this forces a new resource to be created.

nat_gateway_id str

The ID of the NAT Gateway which should be associated with the Subnet. Changing this forces a new resource to be created.

subnet_id str

The ID of the Subnet. Changing this forces a new resource to be created.

natGatewayId String

The ID of the NAT Gateway which should be associated with the Subnet. Changing this forces a new resource to be created.

subnetId String

The ID of the Subnet. Changing this forces a new resource to be created.

Outputs

All input properties are implicitly available as output properties. Additionally, the SubnetNatGatewayAssociation resource produces the following output properties:

Id string

The provider-assigned unique ID for this managed resource.

Id string

The provider-assigned unique ID for this managed resource.

id String

The provider-assigned unique ID for this managed resource.

id string

The provider-assigned unique ID for this managed resource.

id str

The provider-assigned unique ID for this managed resource.

id String

The provider-assigned unique ID for this managed resource.

Look up Existing SubnetNatGatewayAssociation Resource

Get an existing SubnetNatGatewayAssociation resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: SubnetNatGatewayAssociationState, opts?: CustomResourceOptions): SubnetNatGatewayAssociation
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        nat_gateway_id: Optional[str] = None,
        subnet_id: Optional[str] = None) -> SubnetNatGatewayAssociation
func GetSubnetNatGatewayAssociation(ctx *Context, name string, id IDInput, state *SubnetNatGatewayAssociationState, opts ...ResourceOption) (*SubnetNatGatewayAssociation, error)
public static SubnetNatGatewayAssociation Get(string name, Input<string> id, SubnetNatGatewayAssociationState? state, CustomResourceOptions? opts = null)
public static SubnetNatGatewayAssociation get(String name, Output<String> id, SubnetNatGatewayAssociationState state, CustomResourceOptions options)
Resource lookup is not supported in YAML
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
The following state arguments are supported:
NatGatewayId string

The ID of the NAT Gateway which should be associated with the Subnet. Changing this forces a new resource to be created.

SubnetId string

The ID of the Subnet. Changing this forces a new resource to be created.

NatGatewayId string

The ID of the NAT Gateway which should be associated with the Subnet. Changing this forces a new resource to be created.

SubnetId string

The ID of the Subnet. Changing this forces a new resource to be created.

natGatewayId String

The ID of the NAT Gateway which should be associated with the Subnet. Changing this forces a new resource to be created.

subnetId String

The ID of the Subnet. Changing this forces a new resource to be created.

natGatewayId string

The ID of the NAT Gateway which should be associated with the Subnet. Changing this forces a new resource to be created.

subnetId string

The ID of the Subnet. Changing this forces a new resource to be created.

nat_gateway_id str

The ID of the NAT Gateway which should be associated with the Subnet. Changing this forces a new resource to be created.

subnet_id str

The ID of the Subnet. Changing this forces a new resource to be created.

natGatewayId String

The ID of the NAT Gateway which should be associated with the Subnet. Changing this forces a new resource to be created.

subnetId String

The ID of the Subnet. Changing this forces a new resource to be created.

Import

Subnet NAT Gateway Associations can be imported using the resource id of the Subnet, e.g.

 $ pulumi import azure:network/subnetNatGatewayAssociation:SubnetNatGatewayAssociation association1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Network/virtualNetworks/myvnet1/subnets/mysubnet1

Package Details

Repository
Azure Classic pulumi/pulumi-azure
License
Apache-2.0
Notes

This Pulumi package is based on the azurerm Terraform Provider.