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

arvancloud_vpc_subnets (Data Source)

Lists VPC Subnets with optional filtering by VPC ID, region, or availability zone.

Example Usage

# List all subnets across all VPCs.
data "arvancloud_vpc_subnets" "all" {}

output "all_subnets" {
value = data.arvancloud_vpc_subnets.all.subnets
}

# List subnets in a specific VPC.
data "arvancloud_vpc_subnets" "vpc_subnets" {
vpc_id = arvancloud_vpc.example.id
}

output "vpc_subnet_count" {
value = length(data.arvancloud_vpc_subnets.vpc_subnets.subnets)
}

output "vpc_subnet_names" {
value = [for s in data.arvancloud_vpc_subnets.vpc_subnets.subnets : s.name]
}

# List subnets in a specific region.
data "arvancloud_vpc_subnets" "ir_central" {
region = "ir-central1"
}

output "ir_central_subnet_ids" {
value = [for s in data.arvancloud_vpc_subnets.ir_central.subnets : s.id]
}

# List subnets in a specific availability zone.
data "arvancloud_vpc_subnets" "az_a" {
availability_zone = "ir-central1-a"
}

output "az_a_subnets" {
value = data.arvancloud_vpc_subnets.az_a.subnets
}

# Filter by multiple criteria: VPC and region.
data "arvancloud_vpc_subnets" "filtered" {
vpc_id = arvancloud_vpc_vpc.app_vpc.id
region = "ir-central1"
}

output "filtered_subnet_cidr_blocks" {
value = [for s in data.arvancloud_vpc_subnets.filtered.subnets : s.cidr_block]
}

# Access attached servers and their private IPs from datasource.
output "all_subnet_servers" {
value = {
for s in data.arvancloud_vpc_subnets.all.subnets : s.name => [
for srv in s.attached_servers : {
name = srv.server_name
private_ip = srv.private_ip
status = srv.status
}
]
}
}

# Find subnets with attached servers.
output "subnets_with_servers" {
value = [
for s in data.arvancloud_vpc_subnets.all.subnets : s.name
if length(s.attached_servers) > 0
]
}

Schema

Optional

  • availability_zone (String) Filter subnets by availability zone (e.g., ir-central1-a).
  • region (String) Filter subnets by region (e.g., ir-central1).
  • vpc_id (String) Filter subnets by VPC ID.

Read-Only

  • id (String) Identifier of the datasource.
  • subnets (Attributes List) List of subnets matching the filter criteria. (see below for nested schema)

Nested Schema for subnets

Read-Only:

  • attached_servers (Attributes List) List of servers attached to this subnet with their private IP addresses. (see below for nested schema)
  • availability_zone (String) Availability zone where the subnet is located.
  • cidr_block (String) CIDR block of the subnet.
  • created_at (String) Timestamp when the subnet was created.
  • id (String) Unique identifier of the subnet.
  • name (String) Name of the subnet.
  • region (String) Region where the subnet is located.
  • state (String) Current state of the subnet.
  • vpc_id (String) ID of the VPC this subnet belongs to.

Nested Schema for subnets.attached_servers

Read-Only:

  • port_id (String) Port ID of the network interface.
  • 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.