Subnet Args
Provides an VPC subnet resource.
NOTE: Due to AWS Lambda improved VPC networking changes that began deploying in September 2019, subnets associated with Lambda Functions can take up to 45 minutes to successfully delete.
Example Usage
Basic Usage
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.ec2.Subnet;
import com.pulumi.aws.ec2.SubnetArgs;
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 main = new Subnet("main", SubnetArgs.builder()
.vpcId(aws_vpc.main().id())
.cidrBlock("10.0.1.0/24")
.tags(Map.of("Name", "Main"))
.build());
}
}
Subnets In Secondary VPC CIDR Blocks
When managing subnets in one of a VPC's secondary CIDR blocks created using a aws.ec2.VpcIpv4CidrBlockAssociation
resource, it is recommended to reference that resource's vpc_id
attribute to ensure correct dependency ordering.
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.ec2.VpcIpv4CidrBlockAssociation;
import com.pulumi.aws.ec2.VpcIpv4CidrBlockAssociationArgs;
import com.pulumi.aws.ec2.Subnet;
import com.pulumi.aws.ec2.SubnetArgs;
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 secondaryCidr = new VpcIpv4CidrBlockAssociation("secondaryCidr", VpcIpv4CidrBlockAssociationArgs.builder()
.vpcId(aws_vpc.main().id())
.cidrBlock("172.2.0.0/16")
.build());
var inSecondaryCidr = new Subnet("inSecondaryCidr", SubnetArgs.builder()
.vpcId(secondaryCidr.vpcId())
.cidrBlock("172.2.0.0/24")
.build());
}
}
Import
Subnets can be imported using the subnet id
, e.g.,
$ pulumi import aws:ec2/subnet:Subnet public_subnet subnet-9d4a7b6c
Constructors
Properties
Specify true to indicate that network interfaces created in the specified subnet should be assigned an IPv6 address. Default is false
AZ for the subnet.
AZ ID of the subnet. This argument is not supported in all regions or partitions. If necessary, use availability_zone
instead.
The customer owned IPv4 address pool. Typically used with the map_customer_owned_ip_on_launch
argument. The outpost_arn
argument must be specified when configured.
Indicates whether DNS queries made to the Amazon-provided DNS Resolver in this subnet should return synthetic IPv6 addresses for IPv4-only destinations. Default: false
.
Indicates the device position for local network interfaces in this subnet. For example, 1 indicates local network interfaces in this subnet are the secondary network interface (eth1). A local network interface cannot be the primary network interface (eth0).
Indicates whether to respond to DNS queries for instance hostnames with DNS AAAA records. Default: false
.
Indicates whether to respond to DNS queries for instance hostnames with DNS A records. Default: false
.
The IPv6 network range for the subnet, in CIDR notation. The subnet size must use a /64 prefix length.
Indicates whether to create an IPv6-only subnet. Default: false
.
Specify true
to indicate that network interfaces created in the subnet should be assigned a customer owned IP address. The customer_owned_ipv4_pool
and outpost_arn
arguments must be specified when set to true
. Default is false
.
Specify true to indicate that instances launched into the subnet should be assigned a public IP address. Default is false
.
The Amazon Resource Name (ARN) of the Outpost.
The type of hostnames to assign to instances in the subnet at launch. For IPv6-only subnets, an instance DNS name must be based on the instance ID. For dual-stack and IPv4-only subnets, you can specify whether DNS names use the instance IPv4 address or the instance ID. Valid values: ip-name
, resource-name
.