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

arvancloud_iaas_server_action (Resource)

Manages server actions such as power management and administrative operations. Each resource execution performs one action on the target server.

Example Usage

terraform {
required_providers {
arvancloud = {
source = "ArvanCloud/arvancloud"
}
}
}

# Assuming you have a server already created
# Example server ID: "server-123"

# Power on a server
resource "arvancloud_iaas_server_action" "power_on" {
server_id = "server-123"
action = "power-on"
}

# Power off a server
resource "arvancloud_iaas_server_action" "power_off" {
server_id = "server-123"
action = "power-off"
}

# Reboot a server
resource "arvancloud_iaas_server_action" "reboot" {
server_id = "server-123"
action = "reboot"
}

# Terminate a server (makes it non-bootable but keeps for forensics)
resource "arvancloud_iaas_server_action" "terminate" {
server_id = "server-123"
action = "terminate"
}

# Reset server password - stores the new password in state
resource "arvancloud_iaas_server_action" "reset_password" {
server_id = "server-123"
action = "reset-password"
}

# Output the new password (sensitive)
output "new_server_password" {
value = arvancloud_iaas_server_action.reset_password.new_password
sensitive = true
}

# Get VNC console link
resource "arvancloud_iaas_server_action" "vnc_console" {
server_id = "server-123"
action = "get-vnc-link"
}

# Output the VNC console URL
output "vnc_console_url" {
value = arvancloud_iaas_server_action.vnc_console.vnc_url
}

# Example: Using with a created server
resource "arvancloud_iaas_server" "example" {
name = "example-server"
flavor_id = "flavor-123"
image_id = "image-456"
availability_zone = "ir-central1-a"
}

# Power on the newly created server
resource "arvancloud_iaas_server_action" "example_power_on" {
server_id = arvancloud_iaas_server.example.id
action = "power-on"

# This ensures the server is created before we try to power it on
depends_on = [arvancloud_iaas_server.example]
}

# Example: Conditional action based on variable
variable "should_reboot" {
type = bool
default = false
}

resource "arvancloud_iaas_server_action" "conditional_reboot" {
count = var.should_reboot ? 1 : 0
server_id = arvancloud_iaas_server.example.id
action = "reboot"
}

Schema

Required

  • action (String) Action to perform. Valid values: power-on, power-off, reboot, terminate, reset-password, get-vnc-link.
  • server_id (String) ID of the server to perform the action on.

Read-Only

  • id (String) Composite identifier in the format server_id/action.
  • new_password (String, Sensitive) New password returned when action is reset-password. Null for other actions.
  • vnc_url (String) VNC console URL returned when action is get-vnc-link. Null for other actions.