subnets
Creates, updates, deletes or gets a subnet resource or lists subnets in a region
Overview
| Name | subnets |
| Type | Resource |
| Description | Specifies a subnet for the specified VPC. For an IPv4 only subnet, specify an IPv4 CIDR block. If the VPC has an IPv6 CIDR block, you can create an IPv6 only subnet or a dual stack subnet instead. For an IPv6 only subnet, specify an IPv6 CIDR block. For a dual stack subnet, specify both an IPv4 CIDR block and an IPv6 CIDR block. For more information, see [Subnets for your VPC](https://docs.aws.amazon.com/vpc/latest/userguide/configure-subnets.html) in the *Amazon VPC User Guide*. |
| Id | awscc.ec2.subnets |
Fields
- get (all properties)
- list (identifiers only)
| Name | Datatype | Description |
|---|---|---|
assign_ipv6_address_on_creation | boolean | Indicates whether a network interface created in this subnet receives an IPv6 address. The default value is ``false``.<br />If you specify ``AssignIpv6AddressOnCreation``, you must also specify an IPv6 CIDR block. |
vpc_id | string | The ID of the VPC the subnet is in.<br />If you update this property, you must also update the ``CidrBlock`` property. |
map_public_ip_on_launch | boolean | Indicates whether instances launched in this subnet receive a public IPv4 address. The default value is ``false``.<br />AWS charges for all public IPv4 addresses, including public IPv4 addresses associated with running instances and Elastic IP addresses. For more information, see the *Public IPv4 Address* tab on the [VPC pricing page](https://docs.aws.amazon.com/vpc/pricing/). |
enable_lni_at_device_index | integer | 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). |
network_acl_association_id | string | |
availability_zone | string | The Availability Zone of the subnet.<br />If you update this property, you must also update the ``CidrBlock`` property. |
availability_zone_id | string | The AZ ID of the subnet. |
cidr_block | string | The IPv4 CIDR block assigned to the subnet.<br />If you update this property, we create a new subnet, and then delete the existing one. |
subnet_id | string | |
ipv6_cidr_blocks | array | |
ipv6_cidr_block | string | The IPv6 CIDR block.<br />If you specify ``AssignIpv6AddressOnCreation``, you must also specify an IPv6 CIDR block. |
outpost_arn | string | The Amazon Resource Name (ARN) of the Outpost. |
ipv6_native | boolean | Indicates whether this is an IPv6 only subnet. For more information, see [Subnet basics](https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Subnets.html#subnet-basics) in the *User Guide*. |
enable_dns64 | boolean | Indicates whether DNS queries made to the Amazon-provided DNS Resolver in this subnet should return synthetic IPv6 addresses for IPv4-only destinations.<br />You must first configure a NAT gateway in a public subnet (separate from the subnet containing the IPv6-only workloads). For example, the subnet containing the NAT gateway should have a ``0.0.0.0/0`` route pointing to the internet gateway. For more information, see [Configure DNS64 and NAT64](https://docs.aws.amazon.com/vpc/latest/userguide/nat-gateway-nat64-dns64.html#nat-gateway-nat64-dns64-walkthrough) in the *User Guide*. |
private_dns_name_options_on_launch | object | The hostname type for EC2 instances launched into this subnet and how DNS A and AAAA record queries to the instances should be handled. For more information, see [Amazon EC2 instance hostname types](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-naming.html) in the *User Guide*.<br />Available options:<br />+ EnableResourceNameDnsAAAARecord (true | false)<br />+ EnableResourceNameDnsARecord (true | false)<br />+ HostnameType (ip-name | resource-name) |
tags | array | Any tags assigned to the subnet. |
ipv4_ipam_pool_id | string | An IPv4 IPAM pool ID for the subnet. |
ipv4_netmask_length | integer | An IPv4 netmask length for the subnet. |
ipv6_ipam_pool_id | string | An IPv6 IPAM pool ID for the subnet. |
ipv6_netmask_length | integer | An IPv6 netmask length for the subnet. |
block_public_access_states | object | |
region | string | AWS region. |
| Name | Datatype | Description |
|---|---|---|
subnet_id | string | |
region | string | AWS region. |
For more information, see AWS::EC2::Subnet.
Methods
| Name | Resource | Accessible by | Required Params |
|---|---|---|---|
create_resource | subnets | INSERT | VpcId, region |
delete_resource | subnets | DELETE | Identifier, region |
update_resource | subnets | UPDATE | Identifier, PatchDocument, region |
list_resources | subnets_list_only | SELECT | region |
get_resource | subnets | SELECT | Identifier, region |
SELECT examples
- get (all properties)
- list (identifiers only)
Gets all properties from an individual subnet.
SELECT
region,
assign_ipv6_address_on_creation,
vpc_id,
map_public_ip_on_launch,
enable_lni_at_device_index,
network_acl_association_id,
availability_zone,
availability_zone_id,
cidr_block,
subnet_id,
ipv6_cidr_blocks,
ipv6_cidr_block,
outpost_arn,
ipv6_native,
enable_dns64,
private_dns_name_options_on_launch,
tags,
ipv4_ipam_pool_id,
ipv4_netmask_length,
ipv6_ipam_pool_id,
ipv6_netmask_length,
block_public_access_states
FROM awscc.ec2.subnets
WHERE
region = 'us-east-1' AND
Identifier = '{{ subnet_id }}';
Lists all subnets in a region.
SELECT
region,
subnet_id
FROM awscc.ec2.subnets_list_only
WHERE
region = 'us-east-1';
INSERT example
Use the following StackQL query and manifest file to create a new subnet resource, using stack-deploy.
- Required Properties
- All Properties
- Manifest
/*+ create */
INSERT INTO awscc.ec2.subnets (
VpcId,
region
)
SELECT
'{{ vpc_id }}',
'{{ region }}';
/*+ create */
INSERT INTO awscc.ec2.subnets (
AssignIpv6AddressOnCreation,
VpcId,
MapPublicIpOnLaunch,
EnableLniAtDeviceIndex,
AvailabilityZone,
AvailabilityZoneId,
CidrBlock,
Ipv6CidrBlock,
OutpostArn,
Ipv6Native,
EnableDns64,
PrivateDnsNameOptionsOnLaunch,
Tags,
Ipv4IpamPoolId,
Ipv4NetmaskLength,
Ipv6IpamPoolId,
Ipv6NetmaskLength,
region
)
SELECT
'{{ assign_ipv6_address_on_creation }}',
'{{ vpc_id }}',
'{{ map_public_ip_on_launch }}',
'{{ enable_lni_at_device_index }}',
'{{ availability_zone }}',
'{{ availability_zone_id }}',
'{{ cidr_block }}',
'{{ ipv6_cidr_block }}',
'{{ outpost_arn }}',
'{{ ipv6_native }}',
'{{ enable_dns64 }}',
'{{ private_dns_name_options_on_launch }}',
'{{ tags }}',
'{{ ipv4_ipam_pool_id }}',
'{{ ipv4_netmask_length }}',
'{{ ipv6_ipam_pool_id }}',
'{{ ipv6_netmask_length }}',
'{{ region }}';
version: 1
name: stack name
description: stack description
providers:
- aws
globals:
- name: region
value: '{{ vars.AWS_REGION }}'
resources:
- name: subnet
props:
- name: assign_ipv6_address_on_creation
value: '{{ assign_ipv6_address_on_creation }}'
- name: vpc_id
value: '{{ vpc_id }}'
- name: map_public_ip_on_launch
value: '{{ map_public_ip_on_launch }}'
- name: enable_lni_at_device_index
value: '{{ enable_lni_at_device_index }}'
- name: availability_zone
value: '{{ availability_zone }}'
- name: availability_zone_id
value: '{{ availability_zone_id }}'
- name: cidr_block
value: '{{ cidr_block }}'
- name: ipv6_cidr_block
value: '{{ ipv6_cidr_block }}'
- name: outpost_arn
value: '{{ outpost_arn }}'
- name: ipv6_native
value: '{{ ipv6_native }}'
- name: enable_dns64
value: '{{ enable_dns64 }}'
- name: private_dns_name_options_on_launch
value:
hostname_type: '{{ hostname_type }}'
enable_resource_name_dns_arecord: '{{ enable_resource_name_dns_arecord }}'
enable_resource_name_dns_aa_aa_record: '{{ enable_resource_name_dns_aa_aa_record }}'
- name: tags
value:
- key: '{{ key }}'
value: '{{ value }}'
- name: ipv4_ipam_pool_id
value: '{{ ipv4_ipam_pool_id }}'
- name: ipv4_netmask_length
value: '{{ ipv4_netmask_length }}'
- name: ipv6_ipam_pool_id
value: '{{ ipv6_ipam_pool_id }}'
- name: ipv6_netmask_length
value: '{{ ipv6_netmask_length }}'
UPDATE example
Use the following StackQL query and manifest file to update a subnet resource, using stack-deploy.
/*+ update */
UPDATE awscc.ec2.subnets
SET PatchDocument = string('{{ {
"AssignIpv6AddressOnCreation": assign_ipv6_address_on_creation,
"MapPublicIpOnLaunch": map_public_ip_on_launch,
"EnableLniAtDeviceIndex": enable_lni_at_device_index,
"Ipv6CidrBlock": ipv6_cidr_block,
"EnableDns64": enable_dns64,
"PrivateDnsNameOptionsOnLaunch": private_dns_name_options_on_launch,
"Tags": tags
} | generate_patch_document }}')
WHERE
region = '{{ region }}' AND
Identifier = '{{ subnet_id }}';
DELETE example
/*+ delete */
DELETE FROM awscc.ec2.subnets
WHERE
Identifier = '{{ subnet_id }}' AND
region = 'us-east-1';
Permissions
To operate on the subnets resource, the following permissions are required:
- Create
- Read
- Update
- Delete
- List
ec2:DescribeSubnets,
ec2:CreateSubnet,
ec2:CreateTags,
ec2:ModifySubnetAttribute
ec2:DescribeSubnets,
ec2:DescribeNetworkAcls
ec2:DescribeSubnets,
ec2:ModifySubnetAttribute,
ec2:CreateTags,
ec2:DeleteTags,
ec2:AssociateSubnetCidrBlock,
ec2:DisassociateSubnetCidrBlock
ec2:DescribeSubnets,
ec2:DeleteSubnet
ec2:DescribeSubnets,
ec2:DescribeNetworkAcls