پرش به مطلب اصلی

arvancloud_vpc_subnet (Resource)

Manages a VPC Subnet in a specific availability zone.

Example Usage

# Create a subnet in an existing VPC with required fields.
resource "arvancloud_vpc_subnet" "example" {
name = "my-subnet"
vpc_id = arvancloud_vpc.example.id
cidr_block = "10.0.1.0/24"
availability_zone = "ir-central1-a"
}

# Create multiple subnets in different availability zones.
resource "arvancloud_vpc_subnet" "subnet_a" {
name = "app-subnet-a"
vpc_id = arvancloud_vpc.app_vpc.id
cidr_block = "172.16.1.0/24"
availability_zone = "ir-central1-a"
}

resource "arvancloud_vpc_subnet" "subnet_b" {
name = "app-subnet-b"
vpc_id = arvancloud_vpc.app_vpc.id
cidr_block = "172.16.2.0/24"
availability_zone = "ir-central1-b"
}

# Output subnet attributes.
output "example_subnet_id" {
value = arvancloud_vpc_subnet.example.id
}

output "example_subnet_region" {
value = arvancloud_vpc_subnet.example.region
}

output "example_subnet_state" {
value = arvancloud_vpc_subnet.example.state
}

output "example_subnet_created_at" {
value = arvancloud_vpc_subnet.example.created_at
}

# Output attached servers with private IPs.
output "example_subnet_attached_servers" {
value = arvancloud_vpc_subnet.example.attached_servers
}

# Access private IP of a specific attached server.
output "first_server_private_ip" {
value = length(arvancloud_vpc_subnet.example.attached_servers) > 0 ? arvancloud_vpc_subnet.example.attached_servers[0].private_ip : null
}

Schema

Required

  • availability_zone (String) Availability zone where the subnet will be created (e.g., ir-central1-a). Changing this value forces a new resource to be created.
  • cidr_block (String) CIDR block for the subnet (e.g., 10.0.1.0/24). Must be within the VPC's CIDR block and between /16 and /28. Changing this value forces a new resource to be created.
  • name (String) Name of the subnet.
  • vpc_id (String) ID of the VPC this subnet belongs to. Changing this value forces a new resource to be created.

Read-Only

  • attached_servers (Attributes List) List of servers attached to this subnet with their assigned private IP addresses. (see below for nested schema)
  • created_at (String) Timestamp when the subnet was created.
  • id (String) Unique identifier of the subnet assigned by the API.
  • region (String) Region where the subnet is located.
  • state (String) Current state of the subnet (e.g., READY, CREATING).

Nested Schema for attached_servers

Read-Only:

  • port_id (String) Port ID of the network interface (used for detaching).
  • private_ip (String) Private IP address assigned to the server in this subnet.
  • server_id (String) UUID of the attached server.
  • server_name (String) Name of the attached server.
  • status (String) Current status of the server (e.g., ACTIVE, SHUTOFF).

Import

Import is supported using the following syntax:

terraform import arvancloud_vpc_subnet.example subnet-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx