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

arvancloud_iaas_servers (Data Source)

Lists IaaS server instances, optionally filtered by region or availability zone.

Example Usage

# List all servers across all availability zones
data "arvancloud_iaas_servers" "all" {}

# Filter servers by region
data "arvancloud_iaas_servers" "by_region" {
region = "ir-central1"
}

# Filter servers by availability zone
data "arvancloud_iaas_servers" "by_az" {
availability_zone = "ir-central1-a"
}

# Output examples
output "all_servers" {
description = "List of all servers with their details"
value = data.arvancloud_iaas_servers.all.servers
}

output "server_count" {
description = "Total number of servers"
value = length(data.arvancloud_iaas_servers.all.servers)
}

output "server_ids" {
description = "List of all server IDs"
value = [for s in data.arvancloud_iaas_servers.all.servers : s.id]
}

output "active_servers" {
description = "List of servers in ACTIVE status"
value = [
for s in data.arvancloud_iaas_servers.all.servers : s
if s.status == "ACTIVE"
]
}

output "servers_by_id" {
description = "Map of servers by ID with detailed information"
value = {
for s in data.arvancloud_iaas_servers.all.servers : s.id => {
name = s.name
status = s.status
availability_zone = s.availability_zone
region = s.region
flavor_id = s.flavor_id
image_id = s.image_id
ha_enabled = s.ha_enabled
networks = s.networks
security_groups = [for sg in s.security_groups : sg.name]
ipv4_addresses = s.ipv4_addresses
ipv6_addresses = s.ipv6_addresses
}
}
}

output "ha_enabled_servers" {
description = "List of servers with HA enabled"
value = [
for s in data.arvancloud_iaas_servers.all.servers : {
id = s.id
name = s.name
}
if s.ha_enabled
]
}

output "server_ips" {
description = "Map of servers with their IP addresses (by server ID)"
value = {
for s in data.arvancloud_iaas_servers.all.servers : s.id => {
name = s.name
ipv4_addresses = s.ipv4_addresses
ipv6_addresses = s.ipv6_addresses
}
}
}

output "primary_public_ipv4" {
description = "Primary public IPv4 address for each server (by server ID)"
value = {
for s in data.arvancloud_iaas_servers.all.servers :
s.id => {
name = s.name
ip = try(
[for ip in s.ipv4_addresses : ip.ip if ip.is_public][0],
"No public IPv4"
)
}
}
}

output "private_network_details" {
description = "Private network IP and MAC details (by server ID)"
value = {
for s in data.arvancloud_iaas_servers.all.servers :
s.id => {
name = s.name
ips = [
for ip in s.ipv4_addresses : {
network = ip.network_name
ip = ip.ip
mac = ip.mac
}
if !ip.is_public
]
}
}
}

output "servers_with_ipv6" {
description = "Servers that have IPv6 addresses"
value = [
for s in data.arvancloud_iaas_servers.all.servers : {
name = s.name
ipv6_addresses = [for ip in s.ipv6_addresses : ip.ip]
}
if length(s.ipv6_addresses) > 0
]
}

output "servers_with_volumes" {
description = "Servers with attached volumes and their details"
value = {
for s in data.arvancloud_iaas_servers.all.servers :
s.id => {
name = s.name
volumes = s.volumes
}
if length(s.volumes) > 0
}
}

output "volume_details" {
description = "Detailed volume information for each server"
value = {
for s in data.arvancloud_iaas_servers.all.servers :
s.id => {
server_name = s.name
volumes = [
for vol in s.volumes : {
id = vol.id
name = vol.name
size = vol.size
}
]
}
}
}

output "total_volume_size_by_server" {
description = "Total volume size (in GB) attached to each server"
value = {
for s in data.arvancloud_iaas_servers.all.servers :
s.id => {
name = s.name
total_size = sum([for vol in s.volumes : vol.size])
}
if length(s.volumes) > 0
}
}

Schema

Optional

  • availability_zone (String) Filter servers by availability zone code name (e.g. ir-central1-a).
  • region (String) Filter servers by region code name (e.g. ir-central1).

Read-Only

  • id (String) Unique identifier for this data source.
  • servers (Attributes List) List of servers matching the specified filters. (see below for nested schema)

Nested Schema for servers

Read-Only:

  • availability_zone (String) Availability zone code (e.g. ir-central1-a).
  • created (String) Creation timestamp.
  • dedicated_server_id (String) Dedicated server ID, if applicable.
  • flavor_disk (Number) Root disk size in GB.
  • flavor_id (String) Flavor ID.
  • flavor_name (String) Flavor name.
  • flavor_ram (Number) RAM in MB.
  • flavor_vcpus (Number) Number of vCPUs.
  • ha_enabled (Boolean) Whether high availability is enabled.
  • id (String) Unique identifier of the server.
  • image_id (String) Image ID.
  • image_name (String) Image name.
  • image_os (String) Operating system.
  • image_os_version (String) OS version.
  • ipv4_addresses (Attributes List) List of IPv4 addresses assigned to the server. (see below for nested schema)
  • ipv6_addresses (Attributes List) List of IPv6 addresses assigned to the server. (see below for nested schema)
  • key_name (String) Name of the injected SSH key pair.
  • name (String) Name of the server.
  • networks (List of String) List of attached network IDs.
  • region (String) Region code (e.g. ir-central1).
  • security_groups (Attributes List) Security groups attached to the server. (see below for nested schema)
  • status (String) Current status (e.g. ACTIVE, SHUTOFF).
  • tags (List of String) List of tag names.
  • task_state (String) Current task state.
  • volume_backed (Boolean) Whether the server is volume-backed.
  • volumes (Attributes List) Volumes attached to the server. (see below for nested schema)

Nested Schema for servers.ipv4_addresses

Read-Only:

  • ip (String) The IPv4 address.
  • is_public (Boolean) Whether this is a public IP address.
  • mac (String) The MAC address associated with this IP.
  • network_name (String) The name of the network this IP belongs to.
  • type (String) The address type (e.g., fixed, floating).

Nested Schema for servers.ipv6_addresses

Read-Only:

  • ip (String) The IPv6 address.
  • is_public (Boolean) Whether this is a public IP address.
  • mac (String) The MAC address associated with this IP.
  • network_name (String) The name of the network this IP belongs to.
  • type (String) The address type (e.g., fixed, floating).

Nested Schema for servers.security_groups

Read-Only:

  • description (String) Security group description.
  • id (String) Security group ID.
  • name (String) Security group name.

Nested Schema for servers.volumes

Read-Only:

  • id (String) Volume ID.
  • name (String) Volume name.
  • size (Number) Volume size in GB.