Skip to content

Resource: awsDefaultSubnet

Provides a resource to manage a default subnet in the current region.

This is an advanced resource and has special caveats to be aware of when using it. Please read this document in its entirety before using this resource.

The awsDefaultSubnet resource behaves differently from normal resources in that if a default subnet exists in the specified Availability Zone, Terraform does not create this resource, but instead "adopts" it into management. If no default subnet exists, Terraform creates a new default subnet. By default, terraformDestroy does not delete the default subnet but does remove the resource from Terraform state. Set the forceDestroy argument to true to delete the default subnet.

Example Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.defaultSubnet.DefaultSubnet(this, "default_az1", {
  availabilityZone: "us-west-2a",
  tags: {
    Name: "Default subnet for us-west-2a",
  },
});

Argument Reference

The arguments of an awsDefaultSubnet differ slightly from those of awsSubnet:

  • availabilityZone is required
  • The availabilityZoneId, cidrBlock and vpcId arguments become computed attributes
  • The default value for mapPublicIpOnLaunch is true

The following additional arguments are supported:

  • forceDestroy - (Optional) Whether destroying the resource deletes the default subnet. Default: false

Attributes Reference

In addition to all arguments above, the following attributes are exported:

  • availabilityZoneId - The AZ ID of the subnet
  • cidrBlock - The IPv4 CIDR block assigned to the subnet
  • vpcId - The ID of the VPC the subnet is in

Import

Subnets can be imported using the subnetId, e.g.,

$ terraform import aws_default_subnet.public_subnet subnet-9d4a7b6c