Resource: aws_subnet#
Manages a subnet.
For more information about subnets, see the documentation on Subnets.
Example usage#
Basic example#
resource "aws_vpc" "example" {
cidr_block = "10.1.0.0/16"
}
resource "aws_subnet" "example" {
vpc_id = aws_vpc.example.id
cidr_block = "10.1.1.0/24"
tags = {
Name = "Main"
}
}
Argument reference#
The following arguments are supported:
vpc_id- (Required, Forces new resource, String) The ID of the VPC.availability_zone- (Optional, Forces new resource, String) The availability zone for the subnet.cidr_block- (Required, Forces new resource, String) The IPv4 CIDR block for the subnet.map_public_ip_on_launch- (Optional, Editable, Boolean, Deprecated) Indicates whether public IP addresses will be associated with instances created in this subnet. Addresses are associated only if there are available allocated Elastic IP addresses.- Default value:
false
- Default value:
tags- (Optional, Editable, Map of strings) Key-value pairs to assign to the resource. If thedefault_tagsconfiguration block block is used within a provider configuration, the tags with matching keys will overwrite those defined at the provider level.
~> Note The map_public_ip_on_launch argument is deprecated and will be removed in future releases.
Removing the map_public_ip_on_launch argument from the configuration disables the automatic association of Elastic IP addresses with new instances in the subnet.
Instances that have already received an address keep it.
Use the aws_eip resource instead.
Attribute reference#
Supported attributes#
In addition to all arguments above, the following attributes are exported:
id- (String) The ID of the subnet.tags_all- (Map of strings) Key-value pairs assigned to the resource, including any tags inherited from thedefault_tagsconfiguration block if used within a provider configuration.
Unsupported attributes#
~> Note These attributes may be present in the terraform.tfstate file, but they have preset values and cannot be specified in configuration files.
The following attributes are not currently supported:
arn, assign_ipv6_address_on_creation, availability_zone_id, customer_owned_ipv4_pool, enable_dns64, enable_resource_name_dns_a_record_on_launch, enable_resource_name_dns_aaaa_record_on_launch, ipv6_cidr_block, ipv6_cidr_block_association_id, ipv6_native, map_customer_owned_ip_on_launch, outpost_arn, owner_id, private_dns_hostname_type_on_launch.
Timeouts#
The timeouts block allows you to specify timeouts for certain actions:
create- (Default10m) How long to wait for a subnet to be created.delete- (Default20m) How long to wait for a subnet to be deleted.
Import#
Subnets can be imported using the id, for example:
$ terraform import aws_subnet.public_subnet subnet-12345678