Skip to content

Conversation

Pearl1594
Copy link
Contributor

@Pearl1594 Pearl1594 commented Aug 29, 2025

Configuration:

terraform {
  required_providers {
    cloudstack = {
      source = "local/dev/cloudstack"
    }
  }
}

provider "cloudstack" {
  api_url    = "http://xx.xx.xx.xx:8080/client/api"
  api_key    = "LIN6rqXuaJwMPfGYFh13qDwYz5VNNz1J2J6qIOWcd3oLQOq0WtD4CwRundBL6rzXToa3lQOC_vKjI3nkHtiD8Q"
  secret_key = "R6QPwRUz09TVXBjXNwZk7grTjcPtsFRphH6xhN1oPvnc12YUk296t4KHytg8zRLczDA0X5NsLVi4d8rfMMx3yg"
  timeout    = 1800  # 30 minutes for template registration
}

resource "cloudstack_network" "autoscale_network" {
  name             = "autoscale-isolated-network"
  display_text     = "Isolated network for autoscale VMs"
  cidr             = "10.0.10.0/24"
  network_offering = "DefaultIsolatedNetworkOfferingWithSourceNatService"
  zone             = "ref-trl-9240-k-Mol8-pearl-dsilva"
}

resource "cloudstack_ipaddress" "lb_public_ip" {
  network_id = cloudstack_network.autoscale_network.id
  zone       = "ref-trl-9240-k-Mol8-pearl-dsilva"
}

resource "cloudstack_firewall" "http_firewall" {
  ip_address_id = cloudstack_ipaddress.lb_public_ip.id

  rule {
    cidr_list = ["0.0.0.0/0"]
    protocol  = "tcp"
    ports     = ["80"]
  }
}

resource "cloudstack_loadbalancer_rule" "autoscale_lb" {
  name          = "autoscale-lb-rule"
  description   = "Load balancer rule for autoscale group"
  ip_address_id = cloudstack_ipaddress.lb_public_ip.id
  network_id    = cloudstack_network.autoscale_network.id
  algorithm     = "roundrobin"
  private_port  = 80
  public_port   = 80
  member_ids    = []
}

resource "cloudstack_instance" "initial_vm" {
  name             = "initial-web-server"
  service_offering = "Small Instance"
  template         = cloudstack_template.ubuntu_template.name
  zone             = "ref-trl-9240-k-Mol8-pearl-dsilva"
  network_id       = cloudstack_network.autoscale_network.id
}

 resource "cloudstack_template" "ubuntu_template" {
  name         = "ubuntu-22.04-cks"
  display_text = "Ubuntu 22.04 CKS Template"
  format       = "QCOW2"
  hypervisor   = "KVM"
  os_type      = "Ubuntu 22.04 LTS"
  url          = "http://10.0.3.130/cks/custom_templates/ubuntu/22.04/cks-ubuntu-2204-kvm.qcow2.bz2"
  zone         = "ref-trl-9240-k-Mol8-pearl-dsilva"
  is_extractable = true
  is_featured    = false
  is_public      = true
  is_ready_timeout = 1800
}

data "cloudstack_counter" "existing_cpu_counter" {
  id = "cec1072a-784e-11f0-bc3a-1e0030000242"
}

resource "cloudstack_condition" "scale_up_condition" {
  counter_id          = data.cloudstack_counter.existing_cpu_counter.id
  relational_operator = "GT"
  threshold           = 80.0
  account_name        = "admin"
  domain_id           = "1"
}

resource "cloudstack_condition" "scale_down_condition" {
  counter_id          = data.cloudstack_counter.existing_cpu_counter.id
  relational_operator = "LT"
  threshold           = 20.0
  account_name        = "admin"
  domain_id           = "1"
}

resource "cloudstack_autoscale_policy" "scale_up_policy" {
  name         = "scale-up"
  action       = "scaleup"
  duration     = 300
  quiet_time   = 300
  condition_ids = [cloudstack_condition.scale_up_condition.id]
}

resource "cloudstack_autoscale_policy" "scale_down_policy" {
  name         = "scale-down"
  action       = "scaledown"
  duration     = 300
  quiet_time   = 300
  condition_ids = [cloudstack_condition.scale_down_condition.id]
}

resource "cloudstack_autoscale_vm_profile" "vm_profile" {
  service_offering         = "Small Instance"
  template                = cloudstack_template.ubuntu_template.name
  zone                    = "ref-trl-9240-k-Mol8-pearl-dsilva"
  destroy_vm_grace_period = "30s"
  
  counter_param_list = {
    "snmpcommunity" = "public"
    "snmpport"      = "161"
  }
  
  user_data = base64encode(<<-EOF
    #!/bin/bash
    apt-get update -y

    apt-get install -y apache2
    a2enmod cgi

    sed -i -e '/Options Indexes FollowSymLinks/s/$/ ExecCGI/' \
           -e 's/DirectoryIndex index.html/DirectoryIndex index.py/' /etc/apache2/apache2.conf

    cat << EOFCGI > /etc/apache2/conf-available/python-cgi.conf
    <Directory "/var/www/html">
        AddHandler cgi-script .py
        Options +ExecCGI
    </Directory>
    EOFCGI

    a2enconf python-cgi

    cat << 'EOFPY' > /var/www/html/index.py
    #!/usr/bin/env python3
    import time
    import socket
    time.sleep(5)
    print("Content-type: text/html\n\n")
    print('<p style="text-align: center;">Hello World!!!</p>')
    print('<p style="text-align: center;"><strong>Instance:</strong> {}</p>'.format(socket.gethostname()))
    EOFPY

    chmod 705 /var/www/html/index.py

    systemctl enable apache2
    systemctl restart apache2
    EOF
  )
  
  user_data_details = {
    "environment" = "autoscale"
    "application" = "web-server"
  }
  
  account_name     = "Admin"
  domain_id        = "1"
  
  display          = true
  
  other_deploy_params = {
    "rootdisksize" = "20"
  }
}

resource "cloudstack_autoscale_vm_group" "vm_group" {
  name             = "simple-autoscale-group"
  lbrule_id       = cloudstack_loadbalancer_rule.autoscale_lb.id
  min_members     = 1
  max_members     = 5
  vm_profile_id   = cloudstack_autoscale_vm_profile.vm_profile.id
  state           = "enable"
  cleanup      = "true"
  
  scaleup_policy_ids = [
    cloudstack_autoscale_policy.scale_up_policy.id
  ]
  
  scaledown_policy_ids = [
    cloudstack_autoscale_policy.scale_down_policy.id
  ]
}

output "network_id" {
  description = "ID of the created isolated network"
  value       = cloudstack_network.autoscale_network.id
}

output "network_cidr" {
  description = "CIDR of the isolated network"
  value       = cloudstack_network.autoscale_network.cidr
}

output "public_ip_address" {
  description = "Public IP address for the load balancer"
  value       = cloudstack_ipaddress.lb_public_ip.ip_address
}

output "load_balancer_url" {
  description = "URL to access the load balanced application"
  value       = "http://${cloudstack_ipaddress.lb_public_ip.ip_address}"
}

output "autoscale_group_id" {
  description = "ID of the autoscale VM group"
  value       = cloudstack_autoscale_vm_group.vm_group.id
}

output "template_id" {
  description = "ID of the registered Ubuntu template"
  value       = cloudstack_template.ubuntu_template.id
}

output "initial_vm_id" {
  description = "ID of the initial VM instance"
  value       = cloudstack_instance.initial_vm.id
}

output "initial_vm_ip" {
  description = "Private IP address of the initial VM"
  value       = cloudstack_instance.initial_vm.ip_address
}

output "load_balancer_members" {
  description = "Current members of the load balancer"
  value       = cloudstack_loadbalancer_rule.autoscale_lb.member_ids
}

On running the config, it successfully creates the resources and autoscale vm group:


Apply complete! Resources: 12 added, 0 changed, 0 destroyed.

Outputs:

autoscale_group_id = "1d571b8e-621f-4e5b-b854-944b182a816c"
initial_vm_id = "03097204-d52c-4e2a-97b5-10d2f82b92f2"
initial_vm_ip = "10.0.10.31"
load_balancer_url = "http://10.0.xx.xx"
network_cidr = "10.0.10.0/24"
network_id = "5162c6ea-6e36-44e5-81e5-cd99c1c4f62b"
public_ip_address = "10.0.xx.xx"
template_id = "650ababb-ee02-4d8c-9a1c-9cdb3fd4c4e1"


image

Depends on: apache/cloudstack-go#119 , to test locally using this fix, checkout to the branch fix-counter-response-object on the cloudstack-go repo and add the following to the go.mod file in the tf repo:

replace github.com/apache/cloudstack-go/v2 => <path to cloudstack repo locally>

@Pearl1594 Pearl1594 linked an issue Aug 29, 2025 that may be closed by this pull request
@Pearl1594
Copy link
Contributor Author

test failures due to: apache/cloudstack-go#119

@Pearl1594 Pearl1594 changed the title [WIP] Add support for autoscale VM group Add support for autoscale VM group Sep 2, 2025
@Pearl1594 Pearl1594 changed the title Add support for autoscale VM group Add support for autoscale VM groups Sep 2, 2025
@Pearl1594 Pearl1594 marked this pull request as ready for review September 3, 2025 15:54
@DaanHoogland
Copy link
Contributor

let’s rerun tests once #119 is merged, lgtm otherwise.

@kiranchavala kiranchavala reopened this Sep 9, 2025
@kiranchavala
Copy link
Collaborator

kiranchavala commented Sep 15, 2025

@Pearl1594 is it possible to add tests and documentation for the resources and data source.

On testing found that

on terraform destroy the plugin is crashing

terraform destroy
cloudstack_autoscale_vm_profile.vm_profile: Refreshing state... [id=5188474d-c3b5-4696-8998-a25c005cff55]
cloudstack_network.autoscale_network: Refreshing state... [id=067b9203-9678-415a-bc6c-013742d13270]
data.cloudstack_counter.existing_cpu_counter: Reading...
data.cloudstack_counter.existing_cpu_counter: Read complete after 1s [id=4b27ead4-8c8b-11f0-b0ae-1e0092000273]
cloudstack_condition.scale_up_condition: Refreshing state... [id=f0bc1ec0-61db-4e59-bd8e-3980a83e0785]
cloudstack_condition.scale_down_condition: Refreshing state... [id=024c4cc8-6b1b-47ff-aa65-2a9e72e05900]
cloudstack_ipaddress.lb_public_ip: Refreshing state... [id=46e2a4cc-f30f-4850-a1df-0d928b214dcf]
cloudstack_instance.initial_vm: Refreshing state... [id=700a2afc-fd2a-415d-89c0-9477ff12c086]
cloudstack_autoscale_policy.scale_up_policy: Refreshing state... [id=bda40f7f-9df6-4478-881a-5f84e9be8f09]
cloudstack_autoscale_policy.scale_down_policy: Refreshing state... [id=20869e49-5294-4777-94f6-20fc5dc20e5b]
cloudstack_firewall.http_firewall: Refreshing state... [id=46e2a4cc-f30f-4850-a1df-0d928b214dcf]
cloudstack_loadbalancer_rule.autoscale_lb: Refreshing state... [id=858e3b4d-521f-4f5f-a627-e5ac14afcf24]
cloudstack_autoscale_vm_group.vm_group: Refreshing state... [id=fb778d99-0772-4db7-bb05-e8e847f99be7]
╷
│ Error: Request cancelled
│ 
│ The plugin6.(*GRPCProvider).ReadResource request was cancelled.
╵

Stack trace from the terraform-provider-cloudstack plugin:

panic: interface conversion: interface {} is *cloudstack.AutoScalePolicy, not string

goroutine 216 [running]:
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.HashString({0x1038b6e20?, 0x1400060e270?})
        /Users/kiranchavala/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/set.go:21 +0x58
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Set).hash(0x14000120300?, {0x1038b6e20?, 0x1400060e270?})
        /Users/kiranchavala/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/set.go:221 +0x34
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Set).add(0x14000120540, {0x1038b6e20, 0x1400060e270}, 0x0)
        /Users/kiranchavala/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/set.go:201 +0x6c
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Set).Add(...)
        /Users/kiranchavala/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/set.go:79
github.com/terraform-providers/terraform-provider-cloudstack/cloudstack.resourceCloudStackAutoScaleVMGroupRead(0x140006a5000, {0x103a44f40?, 0x14000528008})
        /Users/kiranchavala/Desktop/kiranterraformtesting/cloudstack-terraform-provider/cloudstack/resource_cloudstack_autoscale_vm_group.go:205 +0x5a0
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0x103bb2b68?, {0x103bb2b68?, 0x140003ba2a0?}, 0xd?, {0x103a44f40?, 0x14000528008?})
        /Users/kiranchavala/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:783 +0x130
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).RefreshWithoutUpgrade(0x140002bb340, {0x103bb2b68, 0x140003ba2a0}, 0x14000414a90, {0x103a44f40, 0x14000528008})
        /Users/kiranchavala/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:1089 +0x404
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadResource(0x1400000d608, {0x103bb2b68?, 0x140003ba180?}, 0x1400023ba40)
        /Users/kiranchavala/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:667 +0x3e4
github.com/hashicorp/terraform-plugin-mux/tf5to6server.v5tov6Server.ReadResource({{0x103bbace0?, 0x1400000d608?}}, {0x103bb2b68?, 0x140003ba180?}, 0x1400023b6c0?)
        /Users/kiranchavala/go/pkg/mod/github.com/hashicorp/[email protected]/tf5to6server/tf5to6server.go:215 +0x228
github.com/hashicorp/terraform-plugin-mux/tf6muxserver.(*muxServer).ReadResource(0x14000251810, {0x103bb2b68?, 0x1400069fe30?}, 0x1400023b6c0)
        /Users/kiranchavala/go/pkg/mod/github.com/hashicorp/[email protected]/tf6muxserver/mux_server_ReadResource.go:35 +0x184
github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server.(*server).ReadResource(0x1400024d5e0, {0x103bb2b68?, 0x1400069f6b0?}, 0x140000911a0)
        /Users/kiranchavala/go/pkg/mod/github.com/hashicorp/[email protected]/tfprotov6/tf6server/server.go:776 +0x3bc
github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6._Provider_ReadResource_Handler({0x103ada760, 0x1400024d5e0}, {0x103bb2b68, 0x1400069f6b0}, 0x140006a4d80, 0x0)
        /Users/kiranchavala/go/pkg/mod/github.com/hashicorp/[email protected]/tfprotov6/internal/tfplugin6/tfplugin6_grpc.pb.go:482 +0x1c0
google.golang.org/grpc.(*Server).processUnaryRPC(0x1400018d000, {0x103bb2b68, 0x1400069f5c0}, {0x103bb9200, 0x14000500000}, 0x140004726c0, 0x14000373710, 0x1044dc7c8, 0x0)
        /Users/kiranchavala/go/pkg/mod/google.golang.org/[email protected]/server.go:1386 +0xb58
google.golang.org/grpc.(*Server).handleStream(0x1400018d000, {0x103bb9200, 0x14000500000}, 0x140004726c0)
        /Users/kiranchavala/go/pkg/mod/google.golang.org/[email protected]/server.go:1797 +0xb10
google.golang.org/grpc.(*Server).serveStreams.func2.1()
        /Users/kiranchavala/go/pkg/mod/google.golang.org/[email protected]/server.go:1027 +0x84
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 36
        /Users/kiranchavala/go/pkg/mod/google.golang.org/[email protected]/server.go:1038 +0x13c

Error: The terraform-provider-cloudstack plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.

@kiranchavala
Copy link
Collaborator

kiranchavala commented Sep 15, 2025

@Pearl1594
Copy link
Contributor Author

Thanks @kiranchavala. I am working on adding the support for those.

@Pearl1594
Copy link
Contributor Author

@kiranchavala I've addressed your comments/concerns

Copy link
Collaborator

@kiranchavala kiranchavala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Tested manually with the following

Apply, destroy worked


provider "cloudstack" {
  api_url    = var.cloudstack_api_url
  api_key    = var.cloudstack_api_key
  secret_key = var.cloudstack_secret_key

}



data "cloudstack_counter" "existing_cpu_counter" {
  id = "4b27ead4-8c8b-11f0-b0ae-1e0092000273"
}


resource "cloudstack_ipaddress" "lb_public_ip" {
  network_id = "e14203af-6474-4a13-8384-5f63a894cf26"
  zone       = "05d9863d-bd94-41c2-bba8-251aab44637a"
}

resource "cloudstack_firewall" "http_firewall" {
  ip_address_id = cloudstack_ipaddress.lb_public_ip.id

  rule {
    cidr_list = ["0.0.0.0/0"]
    protocol  = "tcp"
    ports     = ["80"]
  }
}

resource "cloudstack_loadbalancer_rule" "autoscale_lb" {
  name          = "autoscale-lb-rule"
  description   = "Load balancer rule for autoscale group"
  ip_address_id = cloudstack_ipaddress.lb_public_ip.id
  network_id    = "e14203af-6474-4a13-8384-5f63a894cf26"
  algorithm     = "roundrobin"
  private_port  = 80
  public_port   = 80
  member_ids    = []
}




resource "cloudstack_condition" "scale_up_condition" {
  counter_id          = data.cloudstack_counter.existing_cpu_counter.id
  relational_operator = "GT"
  threshold           = 80.0
  account_name        = "admin"
  domain_id           = "1"
}

resource "cloudstack_condition" "scale_down_condition" {
  counter_id          = data.cloudstack_counter.existing_cpu_counter.id
  relational_operator = "LT"
  threshold           = 20.0
  account_name        = "admin"
  domain_id           = "1"
}

resource "cloudstack_autoscale_policy" "scale_up_policy" {
  name         = "scale-up"
  action       = "scaleup"
  duration     = 300
  quiet_time   = 300
  condition_ids = [cloudstack_condition.scale_up_condition.id]
}

resource "cloudstack_autoscale_policy" "scale_down_policy" {
  name         = "scale-down"
  action       = "scaledown"
  duration     = 300
  quiet_time   = 300
  condition_ids = [cloudstack_condition.scale_down_condition.id]
}

resource "cloudstack_autoscale_vm_profile" "vm_profile" {
  service_offering         = "CKS"
  template                = "41b6337d-6abd-45ab-b799-a28b6f627cdb"
  zone                    = "05d9863d-bd94-41c2-bba8-251aab44637a"
  destroy_vm_grace_period = "30s"
  
  counter_param_list = {
    "snmpcommunity" = "public"
    "snmpport"      = "161"
  }
  
  user_data = base64encode(<<-EOF
    #!/bin/bash
    apt-get update -y

    apt-get install -y apache2
    a2enmod cgi

    sed -i -e '/Options Indexes FollowSymLinks/s/$/ ExecCGI/' \
           -e 's/DirectoryIndex index.html/DirectoryIndex index.py/' /etc/apache2/apache2.conf

    cat << EOFCGI > /etc/apache2/conf-available/python-cgi.conf
    <Directory "/var/www/html">
        AddHandler cgi-script .py
        Options +ExecCGI
    </Directory>
    EOFCGI

    a2enconf python-cgi

    cat << 'EOFPY' > /var/www/html/index.py
    #!/usr/bin/env python3
    import time
    import socket
    time.sleep(5)
    print("Content-type: text/html\n\n")
    print('<p style="text-align: center;">Hello World!!!</p>')
    print('<p style="text-align: center;"><strong>Instance:</strong> {}</p>'.format(socket.gethostname()))
    EOFPY

    chmod 705 /var/www/html/index.py

    systemctl enable apache2
    systemctl restart apache2
    EOF
  )
  
  user_data_details = {
    "environment" = "autoscale"
    "application" = "web-server"
  }
  
  account_name     = "Admin"
  domain_id        = "1"
  
  display          = true
  
  other_deploy_params = {
    "rootdisksize" = "20"
  }
  
}

resource "cloudstack_autoscale_vm_group" "vm_group" {
  name             = "simple-autoscale-group"
  lbrule_id       = cloudstack_loadbalancer_rule.autoscale_lb.id
  min_members     = 1
  max_members     = 5
  vm_profile_id   = cloudstack_autoscale_vm_profile.vm_profile.id
  
  scaleup_policy_ids = [
    cloudstack_autoscale_policy.scale_up_policy.id
  ]
  
  scaledown_policy_ids = [
    cloudstack_autoscale_policy.scale_down_policy.id
  ]
  cleanup = true
}

output "network_id" {
  description = "ID of the created isolated network"
  value       = "e14203af-6474-4a13-8384-5f63a894cf26"
}

output "network_cidr" {
  description = "CIDR of the isolated network"
  value       = "10.1.1.0/24"
}

output "public_ip_address" {
  description = "Public IP address for the load balancer"
  value       = cloudstack_ipaddress.lb_public_ip.ip_address
}

output "load_balancer_url" {
  description = "URL to access the load balanced application"
  value       = "http://${cloudstack_ipaddress.lb_public_ip.ip_address}"
}

output "autoscale_group_id" {
  description = "ID of the autoscale VM group"
  value       = cloudstack_autoscale_vm_group.vm_group.id
}

output "template_id" {
  description = "ID of the registered Ubuntu template"
  value       = "41b6337d-6abd-45ab-b799-a28b6f627cdb"
}




output "load_balancer_members" {
  description = "Current members of the load balancer"
  value       = cloudstack_loadbalancer_rule.autoscale_lb.member_ids
}


terraform apply
data.cloudstack_counter.existing_cpu_counter: Reading...
data.cloudstack_counter.existing_cpu_counter: Read complete after 0s [id=4b27ead4-8c8b-11f0-b0ae-1e0092000273]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the
following symbols:
  + create

Terraform will perform the following actions:

  # cloudstack_autoscale_policy.scale_down_policy will be created
  + resource "cloudstack_autoscale_policy" "scale_down_policy" {
      + action        = "SCALEDOWN"
      + condition_ids = (known after apply)
      + duration      = 300
      + id            = (known after apply)
      + name          = "scale-down"
      + quiet_time    = 300
    }

  # cloudstack_autoscale_policy.scale_up_policy will be created
  + resource "cloudstack_autoscale_policy" "scale_up_policy" {
      + action        = "SCALEUP"
      + condition_ids = (known after apply)
      + duration      = 300
      + id            = (known after apply)
      + name          = "scale-up"
      + quiet_time    = 300
    }

  # cloudstack_autoscale_vm_group.vm_group will be created
  + resource "cloudstack_autoscale_vm_group" "vm_group" {
      + cleanup              = true
      + id                   = (known after apply)
      + lbrule_id            = (known after apply)
      + max_members          = 5
      + min_members          = 1
      + name                 = "simple-autoscale-group"
      + scaledown_policy_ids = (known after apply)
      + scaleup_policy_ids   = (known after apply)
      + state                = "enable"
      + vm_profile_id        = (known after apply)
    }

  # cloudstack_autoscale_vm_profile.vm_profile will be created
  + resource "cloudstack_autoscale_vm_profile" "vm_profile" {
      + account_name            = "Admin"
      + counter_param_list      = {
          + "snmpcommunity" = "public"
          + "snmpport"      = "161"
        }
      + destroy_vm_grace_period = "30s"
      + display                 = true
      + domain_id               = "1"
      + id                      = (known after apply)
      + metadata                = (known after apply)
      + other_deploy_params     = {
          + "rootdisksize" = "20"
        }
      + service_offering        = "CKS"
      + template                = "41b6337d-6abd-45ab-b799-a28b6f627cdb"
      + user_data               = "IyEvYmluL2Jhc2gKYXB0LWdldCB1cGRhdGUgLXkKCmFwdC1nZXQgaW5zdGFsbCAteSBhcGFjaGUyCmEyZW5tb2QgY2dpCgpzZWQgLWkgLWUgJy9PcHRpb25zIEluZGV4ZXMgRm9sbG93U3ltTGlua3Mvcy8kLyBFeGVjQ0dJLycgXAogICAgICAgLWUgJ3MvRGlyZWN0b3J5SW5kZXggaW5kZXguaHRtbC9EaXJlY3RvcnlJbmRleCBpbmRleC5weS8nIC9ldGMvYXBhY2hlMi9hcGFjaGUyLmNvbmYKCmNhdCA8PCBFT0ZDR0kgPiAvZXRjL2FwYWNoZTIvY29uZi1hdmFpbGFibGUvcHl0aG9uLWNnaS5jb25mCjxEaXJlY3RvcnkgIi92YXIvd3d3L2h0bWwiPgogICAgQWRkSGFuZGxlciBjZ2ktc2NyaXB0IC5weQogICAgT3B0aW9ucyArRXhlY0NHSQo8L0RpcmVjdG9yeT4KRU9GQ0dJCgphMmVuY29uZiBweXRob24tY2dpCgpjYXQgPDwgJ0VPRlBZJyA+IC92YXIvd3d3L2h0bWwvaW5kZXgucHkKIyEvdXNyL2Jpbi9lbnYgcHl0aG9uMwppbXBvcnQgdGltZQppbXBvcnQgc29ja2V0CnRpbWUuc2xlZXAoNSkKcHJpbnQoIkNvbnRlbnQtdHlwZTogdGV4dC9odG1sXG5cbiIpCnByaW50KCc8cCBzdHlsZT0idGV4dC1hbGlnbjogY2VudGVyOyI+SGVsbG8gV29ybGQhISE8L3A+JykKcHJpbnQoJzxwIHN0eWxlPSJ0ZXh0LWFsaWduOiBjZW50ZXI7Ij48c3Ryb25nPkluc3RhbmNlOjwvc3Ryb25nPiB7fTwvcD4nLmZvcm1hdChzb2NrZXQuZ2V0aG9zdG5hbWUoKSkpCkVPRlBZCgpjaG1vZCA3MDUgL3Zhci93d3cvaHRtbC9pbmRleC5weQoKc3lzdGVtY3RsIGVuYWJsZSBhcGFjaGUyCnN5c3RlbWN0bCByZXN0YXJ0IGFwYWNoZTIK"
      + user_data_details       = {
          + "application" = "web-server"
          + "environment" = "autoscale"
        }
      + zone                    = "05d9863d-bd94-41c2-bba8-251aab44637a"
    }

  # cloudstack_condition.scale_down_condition will be created
  + resource "cloudstack_condition" "scale_down_condition" {
      + account_name        = "admin"
      + counter_id          = "4b27ead4-8c8b-11f0-b0ae-1e0092000273"
      + domain_id           = "1"
      + id                  = (known after apply)
      + relational_operator = "LT"
      + threshold           = 20
    }

  # cloudstack_condition.scale_up_condition will be created
  + resource "cloudstack_condition" "scale_up_condition" {
      + account_name        = "admin"
      + counter_id          = "4b27ead4-8c8b-11f0-b0ae-1e0092000273"
      + domain_id           = "1"
      + id                  = (known after apply)
      + relational_operator = "GT"
      + threshold           = 80
    }

  # cloudstack_firewall.http_firewall will be created
  + resource "cloudstack_firewall" "http_firewall" {
      + id            = (known after apply)
      + ip_address_id = (known after apply)
      + managed       = false
      + parallelism   = 2
      + project       = (known after apply)

      + rule {
          + cidr_list = [
              + "0.0.0.0/0",
            ]
          + icmp_code = (known after apply)
          + icmp_type = (known after apply)
          + ports     = [
              + "80",
            ]
          + protocol  = "tcp"
          + uuids     = (known after apply)
        }
    }

  # cloudstack_ipaddress.lb_public_ip will be created
  + resource "cloudstack_ipaddress" "lb_public_ip" {
      + id            = (known after apply)
      + ip_address    = (known after apply)
      + is_portable   = false
      + is_source_nat = (known after apply)
      + network_id    = "e14203af-6474-4a13-8384-5f63a894cf26"
      + project       = (known after apply)
      + tags          = (known after apply)
      + zone          = "05d9863d-bd94-41c2-bba8-251aab44637a"
    }

  # cloudstack_loadbalancer_rule.autoscale_lb will be created
  + resource "cloudstack_loadbalancer_rule" "autoscale_lb" {
      + algorithm     = "roundrobin"
      + description   = "Load balancer rule for autoscale group"
      + id            = (known after apply)
      + ip_address_id = (known after apply)
      + name          = "autoscale-lb-rule"
      + network_id    = "e14203af-6474-4a13-8384-5f63a894cf26"
      + private_port  = 80
      + project       = (known after apply)
      + protocol      = (known after apply)
      + public_port   = 80
    }

Plan: 9 to add, 0 to change, 0 to destroy.

Changes to Outputs:
  + autoscale_group_id    = (known after apply)
  + load_balancer_url     = (known after apply)
  + network_cidr          = "10.1.1.0/24"
  + network_id            = "e14203af-6474-4a13-8384-5f63a894cf26"
  + public_ip_address     = (known after apply)
  + template_id           = "41b6337d-6abd-45ab-b799-a28b6f627cdb"

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

cloudstack_ipaddress.lb_public_ip: Creating...
cloudstack_condition.scale_up_condition: Creating...
cloudstack_autoscale_vm_profile.vm_profile: Creating...
cloudstack_condition.scale_down_condition: Creating...
cloudstack_condition.scale_up_condition: Creation complete after 1s [id=a5a03cde-58bd-4ec6-a08c-9a545b78e004]
cloudstack_condition.scale_down_condition: Creation complete after 1s [id=70d682f7-e96a-4c9d-90c5-9d5a5e6a9514]
cloudstack_autoscale_policy.scale_down_policy: Creating...
cloudstack_autoscale_policy.scale_up_policy: Creating...
cloudstack_ipaddress.lb_public_ip: Creation complete after 1s [id=10ffaaf7-066c-43f3-a1d5-6c00bcca0f1f]
cloudstack_loadbalancer_rule.autoscale_lb: Creating...
cloudstack_firewall.http_firewall: Creating...
cloudstack_autoscale_policy.scale_up_policy: Creation complete after 0s [id=57baea62-2a75-4d79-837b-c32490aabe35]
cloudstack_autoscale_policy.scale_down_policy: Creation complete after 0s [id=575264b1-e6e7-43fa-90f4-f3ebae2e54c8]
cloudstack_autoscale_vm_profile.vm_profile: Creation complete after 4s [id=e3b8c745-5c8e-478b-85ee-01666e09ef88]
cloudstack_firewall.http_firewall: Creation complete after 8s [id=10ffaaf7-066c-43f3-a1d5-6c00bcca0f1f]
cloudstack_loadbalancer_rule.autoscale_lb: Still creating... [00m10s elapsed]
cloudstack_loadbalancer_rule.autoscale_lb: Creation complete after 12s [id=099b29f1-357a-4d1a-8f03-1f0910cd0c5b]
cloudstack_autoscale_vm_group.vm_group: Creating...
cloudstack_autoscale_vm_group.vm_group: Creation complete after 8s [id=dba7ced2-01ff-4615-82ba-7a3f9c362fbb]

Apply complete! Resources: 9 added, 0 changed, 0 destroyed.

Outputs:

autoscale_group_id = "dba7ced2-01ff-4615-82ba-7a3f9c362fbb"
load_balancer_url = "http://10.0.52.109"
network_cidr = "10.1.1.0/24"
network_id = "e14203af-6474-4a13-8384-5f63a894cf26"
public_ip_address = "10.0.52.109"
template_id = "41b6337d-6abd-45ab-b799-a28b6f627cdb"
╭─ ~/Desktop/cloudstack-India-demo/cloudstack-terraform copy                   ✔ ╱ 25s ╱ Azure subscription 1  ╱ 10:24:02 PM 
╰─ terraform destroy
cloudstack_ipaddress.lb_public_ip: Refreshing state... [id=10ffaaf7-066c-43f3-a1d5-6c00bcca0f1f]
data.cloudstack_counter.existing_cpu_counter: Reading...
cloudstack_autoscale_vm_profile.vm_profile: Refreshing state... [id=e3b8c745-5c8e-478b-85ee-01666e09ef88]
data.cloudstack_counter.existing_cpu_counter: Read complete after 0s [id=4b27ead4-8c8b-11f0-b0ae-1e0092000273]
cloudstack_condition.scale_up_condition: Refreshing state... [id=a5a03cde-58bd-4ec6-a08c-9a545b78e004]
cloudstack_condition.scale_down_condition: Refreshing state... [id=70d682f7-e96a-4c9d-90c5-9d5a5e6a9514]
cloudstack_loadbalancer_rule.autoscale_lb: Refreshing state... [id=099b29f1-357a-4d1a-8f03-1f0910cd0c5b]
cloudstack_firewall.http_firewall: Refreshing state... [id=10ffaaf7-066c-43f3-a1d5-6c00bcca0f1f]
cloudstack_autoscale_policy.scale_down_policy: Refreshing state... [id=575264b1-e6e7-43fa-90f4-f3ebae2e54c8]
cloudstack_autoscale_policy.scale_up_policy: Refreshing state... [id=57baea62-2a75-4d79-837b-c32490aabe35]
cloudstack_autoscale_vm_group.vm_group: Refreshing state... [id=dba7ced2-01ff-4615-82ba-7a3f9c362fbb]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the
following symbols:
  - destroy

Terraform will perform the following actions:

  # cloudstack_autoscale_policy.scale_down_policy will be destroyed
  - resource "cloudstack_autoscale_policy" "scale_down_policy" {
      - action        = "SCALEDOWN" -> null
      - condition_ids = [
          - "70d682f7-e96a-4c9d-90c5-9d5a5e6a9514",
        ] -> null
      - duration      = 300 -> null
      - id            = "575264b1-e6e7-43fa-90f4-f3ebae2e54c8" -> null
      - name          = "scale-down" -> null
      - quiet_time    = 300 -> null
    }

  # cloudstack_autoscale_policy.scale_up_policy will be destroyed
  - resource "cloudstack_autoscale_policy" "scale_up_policy" {
      - action        = "SCALEUP" -> null
      - condition_ids = [
          - "a5a03cde-58bd-4ec6-a08c-9a545b78e004",
        ] -> null
      - duration      = 300 -> null
      - id            = "57baea62-2a75-4d79-837b-c32490aabe35" -> null
      - name          = "scale-up" -> null
      - quiet_time    = 300 -> null
    }

  # cloudstack_autoscale_vm_group.vm_group will be destroyed
  - resource "cloudstack_autoscale_vm_group" "vm_group" {
      - cleanup              = true -> null
      - display              = true -> null
      - id                   = "dba7ced2-01ff-4615-82ba-7a3f9c362fbb" -> null
      - interval             = 30 -> null
      - lbrule_id            = "099b29f1-357a-4d1a-8f03-1f0910cd0c5b" -> null
      - max_members          = 5 -> null
      - min_members          = 1 -> null
      - name                 = "simple-autoscale-group" -> null
      - scaledown_policy_ids = [
          - "575264b1-e6e7-43fa-90f4-f3ebae2e54c8",
        ] -> null
      - scaleup_policy_ids   = [
          - "57baea62-2a75-4d79-837b-c32490aabe35",
        ] -> null
      - state                = "enable" -> null
      - vm_profile_id        = "e3b8c745-5c8e-478b-85ee-01666e09ef88" -> null
    }

  # cloudstack_autoscale_vm_profile.vm_profile will be destroyed
  - resource "cloudstack_autoscale_vm_profile" "vm_profile" {
      - account_name            = "admin" -> null
      - counter_param_list      = {
          - "snmpcommunity" = "public"
          - "snmpport"      = "161"
        } -> null
      - destroy_vm_grace_period = "30s" -> null
      - display                 = false -> null
      - domain_id               = "16f19ba6-8c8b-11f0-b0ae-1e0092000273" -> null
      - id                      = "e3b8c745-5c8e-478b-85ee-01666e09ef88" -> null
      - metadata                = {} -> null
      - other_deploy_params     = {
          - "rootdisksize" = "20"
        } -> null
      - service_offering        = "CKS" -> null
      - template                = "41b6337d-6abd-45ab-b799-a28b6f627cdb" -> null
      - user_data               = "IyEvYmluL2Jhc2gKYXB0LWdldCB1cGRhdGUgLXkKCmFwdC1nZXQgaW5zdGFsbCAteSBhcGFjaGUyCmEyZW5tb2QgY2dpCgpzZWQgLWkgLWUgJy9PcHRpb25zIEluZGV4ZXMgRm9sbG93U3ltTGlua3Mvcy8kLyBFeGVjQ0dJLycgXAogICAgICAgLWUgJ3MvRGlyZWN0b3J5SW5kZXggaW5kZXguaHRtbC9EaXJlY3RvcnlJbmRleCBpbmRleC5weS8nIC9ldGMvYXBhY2hlMi9hcGFjaGUyLmNvbmYKCmNhdCA8PCBFT0ZDR0kgPiAvZXRjL2FwYWNoZTIvY29uZi1hdmFpbGFibGUvcHl0aG9uLWNnaS5jb25mCjxEaXJlY3RvcnkgIi92YXIvd3d3L2h0bWwiPgogICAgQWRkSGFuZGxlciBjZ2ktc2NyaXB0IC5weQogICAgT3B0aW9ucyArRXhlY0NHSQo8L0RpcmVjdG9yeT4KRU9GQ0dJCgphMmVuY29uZiBweXRob24tY2dpCgpjYXQgPDwgJ0VPRlBZJyA+IC92YXIvd3d3L2h0bWwvaW5kZXgucHkKIyEvdXNyL2Jpbi9lbnYgcHl0aG9uMwppbXBvcnQgdGltZQppbXBvcnQgc29ja2V0CnRpbWUuc2xlZXAoNSkKcHJpbnQoIkNvbnRlbnQtdHlwZTogdGV4dC9odG1sXG5cbiIpCnByaW50KCc8cCBzdHlsZT0idGV4dC1hbGlnbjogY2VudGVyOyI+SGVsbG8gV29ybGQhISE8L3A+JykKcHJpbnQoJzxwIHN0eWxlPSJ0ZXh0LWFsaWduOiBjZW50ZXI7Ij48c3Ryb25nPkluc3RhbmNlOjwvc3Ryb25nPiB7fTwvcD4nLmZvcm1hdChzb2NrZXQuZ2V0aG9zdG5hbWUoKSkpCkVPRlBZCgpjaG1vZCA3MDUgL3Zhci93d3cvaHRtbC9pbmRleC5weQoKc3lzdGVtY3RsIGVuYWJsZSBhcGFjaGUyCnN5c3RlbWN0bCByZXN0YXJ0IGFwYWNoZTIK" -> null
      - user_data_details       = {} -> null
      - zone                    = "05d9863d-bd94-41c2-bba8-251aab44637a" -> null
    }

  # cloudstack_condition.scale_down_condition will be destroyed
  - resource "cloudstack_condition" "scale_down_condition" {
      - account_name        = "admin" -> null
      - counter_id          = "4b27ead4-8c8b-11f0-b0ae-1e0092000273" -> null
      - domain_id           = "16f19ba6-8c8b-11f0-b0ae-1e0092000273" -> null
      - id                  = "70d682f7-e96a-4c9d-90c5-9d5a5e6a9514" -> null
      - relational_operator = "LT" -> null
      - threshold           = 20 -> null
    }

  # cloudstack_condition.scale_up_condition will be destroyed
  - resource "cloudstack_condition" "scale_up_condition" {
      - account_name        = "admin" -> null
      - counter_id          = "4b27ead4-8c8b-11f0-b0ae-1e0092000273" -> null
      - domain_id           = "16f19ba6-8c8b-11f0-b0ae-1e0092000273" -> null
      - id                  = "a5a03cde-58bd-4ec6-a08c-9a545b78e004" -> null
      - relational_operator = "GT" -> null
      - threshold           = 80 -> null
    }

  # cloudstack_firewall.http_firewall will be destroyed
  - resource "cloudstack_firewall" "http_firewall" {
      - id            = "10ffaaf7-066c-43f3-a1d5-6c00bcca0f1f" -> null
      - ip_address_id = "10ffaaf7-066c-43f3-a1d5-6c00bcca0f1f" -> null
      - managed       = false -> null
      - parallelism   = 2 -> null

      - rule {
          - cidr_list = [
              - "0.0.0.0/0",
            ] -> null
          - icmp_code = 0 -> null
          - icmp_type = 0 -> null
          - ports     = [
              - "80",
            ] -> null
          - protocol  = "tcp" -> null
          - uuids     = {
              - "80" = "016d7d1e-eaa9-47f4-bd13-2c39106143bf"
            } -> null
        }
    }

  # cloudstack_ipaddress.lb_public_ip will be destroyed
  - resource "cloudstack_ipaddress" "lb_public_ip" {
      - id            = "10ffaaf7-066c-43f3-a1d5-6c00bcca0f1f" -> null
      - ip_address    = "10.0.52.109" -> null
      - is_portable   = false -> null
      - is_source_nat = false -> null
      - network_id    = "e14203af-6474-4a13-8384-5f63a894cf26" -> null
      - tags          = {} -> null
      - zone          = "05d9863d-bd94-41c2-bba8-251aab44637a" -> null
        # (1 unchanged attribute hidden)
    }

  # cloudstack_loadbalancer_rule.autoscale_lb will be destroyed
  - resource "cloudstack_loadbalancer_rule" "autoscale_lb" {
      - algorithm     = "roundrobin" -> null
      - description   = "Load balancer rule for autoscale group" -> null
      - id            = "099b29f1-357a-4d1a-8f03-1f0910cd0c5b" -> null
      - ip_address_id = "10ffaaf7-066c-43f3-a1d5-6c00bcca0f1f" -> null
      - member_ids    = [
          - "2cbcf453-4904-4d83-9457-9a76ac9038d1",
        ] -> null
      - name          = "autoscale-lb-rule" -> null
      - network_id    = "e14203af-6474-4a13-8384-5f63a894cf26" -> null
      - private_port  = 80 -> null
      - public_port   = 80 -> null
        # (2 unchanged attributes hidden)
    }

Plan: 0 to add, 0 to change, 9 to destroy.

Changes to Outputs:
  - autoscale_group_id    = "dba7ced2-01ff-4615-82ba-7a3f9c362fbb" -> null
  - load_balancer_members = [] -> null
  - load_balancer_url     = "http://10.0.52.109" -> null
  - network_cidr          = "10.1.1.0/24" -> null
  - network_id            = "e14203af-6474-4a13-8384-5f63a894cf26" -> null
  - public_ip_address     = "10.0.52.109" -> null
  - template_id           = "41b6337d-6abd-45ab-b799-a28b6f627cdb" -> null

Do you really want to destroy all resources?
  Terraform will destroy all your managed infrastructure, as shown above.
  There is no undo. Only 'yes' will be accepted to confirm.

  Enter a value: yes

cloudstack_autoscale_vm_group.vm_group: Destroying... [id=dba7ced2-01ff-4615-82ba-7a3f9c362fbb]
cloudstack_firewall.http_firewall: Destroying... [id=10ffaaf7-066c-43f3-a1d5-6c00bcca0f1f]
cloudstack_firewall.http_firewall: Destruction complete after 8s
cloudstack_autoscale_vm_group.vm_group: Still destroying... [id=dba7ced2-01ff-4615-82ba-7a3f9c362fbb, 00m10s elapsed]
cloudstack_autoscale_vm_group.vm_group: Still destroying... [id=dba7ced2-01ff-4615-82ba-7a3f9c362fbb, 00m20s elapsed]
cloudstack_autoscale_vm_group.vm_group: Still destroying... [id=dba7ced2-01ff-4615-82ba-7a3f9c362fbb, 00m30s elapsed]
cloudstack_autoscale_vm_group.vm_group: Destruction complete after 37s
cloudstack_loadbalancer_rule.autoscale_lb: Destroying... [id=099b29f1-357a-4d1a-8f03-1f0910cd0c5b]
cloudstack_autoscale_policy.scale_down_policy: Destroying... [id=575264b1-e6e7-43fa-90f4-f3ebae2e54c8]
cloudstack_autoscale_policy.scale_up_policy: Destroying... [id=57baea62-2a75-4d79-837b-c32490aabe35]
cloudstack_autoscale_vm_profile.vm_profile: Destroying... [id=e3b8c745-5c8e-478b-85ee-01666e09ef88]
cloudstack_autoscale_policy.scale_up_policy: Destruction complete after 1s
cloudstack_condition.scale_up_condition: Destroying... [id=a5a03cde-58bd-4ec6-a08c-9a545b78e004]
cloudstack_autoscale_policy.scale_down_policy: Destruction complete after 1s
cloudstack_condition.scale_down_condition: Destroying... [id=70d682f7-e96a-4c9d-90c5-9d5a5e6a9514]
cloudstack_autoscale_vm_profile.vm_profile: Destruction complete after 1s
cloudstack_condition.scale_up_condition: Destruction complete after 0s
cloudstack_condition.scale_down_condition: Destruction complete after 1s
cloudstack_loadbalancer_rule.autoscale_lb: Destruction complete after 8s
cloudstack_ipaddress.lb_public_ip: Destroying... [id=10ffaaf7-066c-43f3-a1d5-6c00bcca0f1f]
cloudstack_ipaddress.lb_public_ip: Destruction complete after 0s

Destroy complete! Resources: 9 destroyed.

@kiranchavala
Copy link
Collaborator

@Pearl1594 can we add some tests if possible

Also, will there be an issue if the upcoming terraform release includes this without a go release

apache/cloudstack-go#119

or will it work fine after a go release is performed

@DaanHoogland
Copy link
Contributor

@Pearl1594 can you look at the failing tests?

@Pearl1594
Copy link
Contributor Author

@Pearl1594 can we add some tests if possible

Also, will there be an issue if the upcoming terraform release includes this without a go release

apache/cloudstack-go#119

or will it work fine after a go release is performed

@kiranchavala this fix will need to go-sdk change. Otherwise, it would fail.

@kiranchavala
Copy link
Collaborator

@Pearl1594 can you look at the failing tests?

@DaanHoogland I think the failing tests are there because it needs go pr

apache/cloudstack-go#119

@Pearl1594
Copy link
Contributor Author

@Pearl1594 can you look at the failing tests?

@DaanHoogland the test failures are because of the go-sdk change that's missing.

@DaanHoogland
Copy link
Contributor

also there is a conflict (now)

@DaanHoogland
Copy link
Contributor

@Pearl1594 can you look at the failing tests?

@DaanHoogland the test failures are because of the go-sdk change that's missing.

can you create a release for that change? cc @vishesh92 @kiranchavala @shwstppr

@kiranchavala kiranchavala added this to the v0.6.0 milestone Sep 19, 2025
@kiranchavala
Copy link
Collaborator

@Pearl1594 as discussed, hitting the following exception after

  1. Apply the config

  2. Add state="Disabled" to the "cloudstack_autoscale_vm_group"

  3. Apply the config again

  4. Error observed


terraform apply
data.cloudstack_counter.existing_cpu_counter: Reading...
cloudstack_ipaddress.lb_public_ip: Refreshing state... [id=d092551a-dfa2-40e6-97bc-afba2c68b5b1]
cloudstack_autoscale_vm_profile.vm_profile: Refreshing state... [id=bbb61517-6fe8-492d-a003-e778fc56ca6d]
data.cloudstack_counter.existing_cpu_counter: Read complete after 1s [id=4b27ead4-8c8b-11f0-b0ae-1e0092000273]
cloudstack_condition.scale_up_condition: Refreshing state... [id=78f2a0eb-90a7-458b-a241-556b359f0943]
cloudstack_condition.scale_down_condition: Refreshing state... [id=4f99814f-ff56-491b-a91c-78e2ebb929fe]
cloudstack_loadbalancer_rule.autoscale_lb: Refreshing state... [id=f635f445-937b-4033-9ca9-d4a6f3e0d667]
cloudstack_firewall.http_firewall: Refreshing state... [id=d092551a-dfa2-40e6-97bc-afba2c68b5b1]
cloudstack_autoscale_policy.scale_down_policy: Refreshing state... [id=10eb5462-0829-4eda-b488-e3c5ee6f71d9]
cloudstack_autoscale_policy.scale_up_policy: Refreshing state... [id=7552547f-ded5-4b99-b7cc-42fd93b7df39]
cloudstack_autoscale_vm_group.vm_group: Refreshing state... [id=bce38ab6-62d1-4c19-b001-8f1cdc273544]

Note: Objects have changed outside of Terraform

Terraform detected the following changes made outside of Terraform since the last "terraform apply" which may have affected this plan:

  # cloudstack_loadbalancer_rule.autoscale_lb has changed
  ~ resource "cloudstack_loadbalancer_rule" "autoscale_lb" {
        id            = "f635f445-937b-4033-9ca9-d4a6f3e0d667"
      + member_ids    = [
          + "9030f9c3-86cc-4bdd-b1b5-15d4fe671422",
        ]
        name          = "autoscale-lb-rule"
        # (8 unchanged attributes hidden)
    }


Unless you have made equivalent changes to your configuration, or ignored the relevant attributes using ignore_changes, the following plan may include actions to undo or respond to these changes.

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place
-/+ destroy and then create replacement

Terraform will perform the following actions:

  # cloudstack_autoscale_policy.scale_down_policy will be updated in-place
  ~ resource "cloudstack_autoscale_policy" "scale_down_policy" {
      ~ condition_ids = [
          - "4f99814f-ff56-491b-a91c-78e2ebb929fe",
        ] -> (known after apply)
        id            = "10eb5462-0829-4eda-b488-e3c5ee6f71d9"
        name          = "scale-down"
        # (3 unchanged attributes hidden)
    }

  # cloudstack_autoscale_policy.scale_up_policy will be updated in-place
  ~ resource "cloudstack_autoscale_policy" "scale_up_policy" {
      ~ condition_ids = [
          - "78f2a0eb-90a7-458b-a241-556b359f0943",
        ] -> (known after apply)
        id            = "7552547f-ded5-4b99-b7cc-42fd93b7df39"
        name          = "scale-up"
        # (3 unchanged attributes hidden)
    }

  # cloudstack_autoscale_vm_group.vm_group must be replaced
-/+ resource "cloudstack_autoscale_vm_group" "vm_group" {
      - display              = true -> null
      ~ id                   = "bce38ab6-62d1-4c19-b001-8f1cdc273544" -> (known after apply)
      - interval             = 30 -> null
        name                 = "simple-autoscale-group"
      ~ state                = "enable" -> "disable"
      ~ vm_profile_id        = "bbb61517-6fe8-492d-a003-e778fc56ca6d" -> (known after apply) # forces replacement
        # (6 unchanged attributes hidden)
    }

  # cloudstack_autoscale_vm_profile.vm_profile must be replaced
-/+ resource "cloudstack_autoscale_vm_profile" "vm_profile" {
      ~ account_name            = "admin" -> "Admin" # forces replacement
      ~ display                 = false -> true
      ~ domain_id               = "16f19ba6-8c8b-11f0-b0ae-1e0092000273" -> "1" # forces replacement
      ~ id                      = "bbb61517-6fe8-492d-a003-e778fc56ca6d" -> (known after apply)
      ~ metadata                = {} -> (known after apply)
      ~ user_data_details       = {
          + "application" = "web-server"
          + "environment" = "autoscale"
        }
        # (7 unchanged attributes hidden)
    }

  # cloudstack_condition.scale_down_condition must be replaced
-/+ resource "cloudstack_condition" "scale_down_condition" {
      ~ domain_id           = "16f19ba6-8c8b-11f0-b0ae-1e0092000273" -> "1" # forces replacement
      ~ id                  = "4f99814f-ff56-491b-a91c-78e2ebb929fe" -> (known after apply)
        # (4 unchanged attributes hidden)
    }

  # cloudstack_condition.scale_up_condition must be replaced
-/+ resource "cloudstack_condition" "scale_up_condition" {
      ~ domain_id           = "16f19ba6-8c8b-11f0-b0ae-1e0092000273" -> "1" # forces replacement
      ~ id                  = "78f2a0eb-90a7-458b-a241-556b359f0943" -> (known after apply)
        # (4 unchanged attributes hidden)
    }

  # cloudstack_loadbalancer_rule.autoscale_lb will be updated in-place
  ~ resource "cloudstack_loadbalancer_rule" "autoscale_lb" {
        id            = "f635f445-937b-4033-9ca9-d4a6f3e0d667"
      ~ member_ids    = [
          - "9030f9c3-86cc-4bdd-b1b5-15d4fe671422",
        ]
        name          = "autoscale-lb-rule"
        # (8 unchanged attributes hidden)
    }

Plan: 4 to add, 3 to change, 4 to destroy.

Changes to Outputs:
  ~ autoscale_group_id    = "bce38ab6-62d1-4c19-b001-8f1cdc273544" -> (known after apply)
  + load_balancer_members = []

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

cloudstack_autoscale_vm_group.vm_group: Destroying... [id=bce38ab6-62d1-4c19-b001-8f1cdc273544]
cloudstack_autoscale_vm_group.vm_group: Still destroying... [id=bce38ab6-62d1-4c19-b001-8f1cdc273544, 00m10s elapsed]
cloudstack_autoscale_vm_group.vm_group: Still destroying... [id=bce38ab6-62d1-4c19-b001-8f1cdc273544, 00m20s elapsed]
cloudstack_autoscale_vm_group.vm_group: Still destroying... [id=bce38ab6-62d1-4c19-b001-8f1cdc273544, 00m30s elapsed]
cloudstack_autoscale_vm_group.vm_group: Still destroying... [id=bce38ab6-62d1-4c19-b001-8f1cdc273544, 00m40s elapsed]
cloudstack_autoscale_vm_group.vm_group: Still destroying... [id=bce38ab6-62d1-4c19-b001-8f1cdc273544, 00m50s elapsed]
cloudstack_autoscale_vm_group.vm_group: Destruction complete after 53s
cloudstack_condition.scale_down_condition: Destroying... [id=4f99814f-ff56-491b-a91c-78e2ebb929fe]
cloudstack_condition.scale_up_condition: Destroying... [id=78f2a0eb-90a7-458b-a241-556b359f0943]
cloudstack_autoscale_vm_profile.vm_profile: Destroying... [id=bbb61517-6fe8-492d-a003-e778fc56ca6d]
cloudstack_loadbalancer_rule.autoscale_lb: Modifying... [id=f635f445-937b-4033-9ca9-d4a6f3e0d667]
cloudstack_autoscale_vm_profile.vm_profile: Destruction complete after 1s
cloudstack_autoscale_vm_profile.vm_profile: Creating...
cloudstack_autoscale_vm_profile.vm_profile: Creation complete after 2s [id=80217609-ef5e-4d33-9882-659d21fe906d]
cloudstack_loadbalancer_rule.autoscale_lb: Still modifying... [id=f635f445-937b-4033-9ca9-d4a6f3e0d667, 00m10s elapsed]
cloudstack_loadbalancer_rule.autoscale_lb: Modifications complete after 13s [id=f635f445-937b-4033-9ca9-d4a6f3e0d667]
╷
│ Error: Error deleting condition: Undefined error: {"errorcode":536,"errortext":"Cannot delete Condition when it is in use by one or more AutoScale Policies."}
│ 
│ 
╵
╷
│ Error: Error deleting condition: Undefined error: {"errorcode":536,"errortext":"Cannot delete Condition when it is in use by one or more AutoScale Policies."}

… lb rule associated to an asg or autoscale vm profile
@Pearl1594
Copy link
Contributor Author

Thanks for testing @kiranchavala . Can you please retest that scenario again.

@kiranchavala
Copy link
Collaborator

@Pearl1594 still hitting the same error

@Pearl1594
Copy link
Contributor Author

@kiranchavala Im not able to reproduce the issue with the latest changes.

@kiranchavala
Copy link
Collaborator

@Pearl1594

Hitting the timeout issue

Terraform is updating the resources when only "cloudstack_autoscale_vm_group" state is changed from enable to disable

cloudstack_autoscale_vm_profile.vm_profile
cloudstack_loadbalancer_rule.autoscale_lb

terraform apply
data.cloudstack_counter.existing_cpu_counter: Reading...
cloudstack_ipaddress.lb_public_ip: Refreshing state... [id=42462dce-96ad-47d0-909d-8e56a465f3e1]
cloudstack_autoscale_vm_profile.vm_profile: Refreshing state... [id=00196cec-b4ac-47de-8066-a8a70fb7b9ca]
data.cloudstack_counter.existing_cpu_counter: Read complete after 0s [id=4b27ead4-8c8b-11f0-b0ae-1e0092000273]
cloudstack_condition.scale_up_condition: Refreshing state... [id=f06c5d82-121b-499d-bb47-30771b2e2a18]
cloudstack_condition.scale_down_condition: Refreshing state... [id=355f52df-5667-41b9-9307-ecad0ea4d21e]
cloudstack_loadbalancer_rule.autoscale_lb: Refreshing state... [id=59fc77ed-b5c4-4dab-8b6e-7239981a4ede]
cloudstack_firewall.http_firewall: Refreshing state... [id=42462dce-96ad-47d0-909d-8e56a465f3e1]
cloudstack_autoscale_policy.scale_down_policy: Refreshing state... [id=f380822c-984c-4dfc-ae9a-40364e8d410c]
cloudstack_autoscale_policy.scale_up_policy: Refreshing state... [id=90e4bb1b-189d-412b-9678-5737c2180b66]
cloudstack_autoscale_vm_group.vm_group: Refreshing state... [id=c4d718c9-22de-4014-aa73-1133858a1dad]

Note: Objects have changed outside of Terraform

Terraform detected the following changes made outside of Terraform since the last "terraform apply" which may have affected this plan:

  # cloudstack_loadbalancer_rule.autoscale_lb has changed
  ~ resource "cloudstack_loadbalancer_rule" "autoscale_lb" {
        id            = "59fc77ed-b5c4-4dab-8b6e-7239981a4ede"
      + member_ids    = [
          + "02ea6652-88e6-4599-bd39-2c9769a8b9e3",
        ]
        name          = "autoscale-lb-rule"
        # (8 unchanged attributes hidden)
    }


Unless you have made equivalent changes to your configuration, or ignored the relevant attributes using ignore_changes, the following plan may include actions to undo or respond to these changes.

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # cloudstack_autoscale_vm_group.vm_group will be updated in-place
  ~ resource "cloudstack_autoscale_vm_group" "vm_group" {
      - display              = true -> null
        id                   = "c4d718c9-22de-4014-aa73-1133858a1dad"
      - interval             = 30 -> null
        name                 = "simple-autoscale-group2"
      ~ state                = "enable" -> "disable"
        # (7 unchanged attributes hidden)
    }

  # cloudstack_autoscale_vm_profile.vm_profile will be updated in-place
  ~ resource "cloudstack_autoscale_vm_profile" "vm_profile" {
      ~ display                 = false -> true
        id                      = "00196cec-b4ac-47de-8066-a8a70fb7b9ca"
        # (11 unchanged attributes hidden)
    }

  # cloudstack_loadbalancer_rule.autoscale_lb will be updated in-place
  ~ resource "cloudstack_loadbalancer_rule" "autoscale_lb" {
        id            = "59fc77ed-b5c4-4dab-8b6e-7239981a4ede"
      ~ member_ids    = [
          - "02ea6652-88e6-4599-bd39-2c9769a8b9e3",
        ]
        name          = "autoscale-lb-rule"
        # (8 unchanged attributes hidden)
    }

Plan: 0 to add, 3 to change, 0 to destroy.

Changes to Outputs:
  + load_balancer_members = []

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

cloudstack_loadbalancer_rule.autoscale_lb: Modifying... [id=59fc77ed-b5c4-4dab-8b6e-7239981a4ede]
cloudstack_autoscale_vm_profile.vm_profile: Modifying... [id=00196cec-b4ac-47de-8066-a8a70fb7b9ca]
cloudstack_loadbalancer_rule.autoscale_lb: Modifications complete after 2s [id=59fc77ed-b5c4-4dab-8b6e-7239981a4ede]
cloudstack_autoscale_vm_profile.vm_profile: Still modifying... [id=00196cec-b4ac-47de-8066-a8a70fb7b9ca, 00m10s elapsed]
cloudstack_autoscale_vm_profile.vm_profile: Still modifying... [id=00196cec-b4ac-47de-8066-a8a70fb7b9ca, 00m20s elapsed]
cloudstack_autoscale_vm_profile.vm_profile: Still modifying... [id=00196cec-b4ac-47de-8066-a8a70fb7b9ca, 00m30s elapsed]
cloudstack_autoscale_vm_profile.vm_profile: Still modifying... [id=00196cec-b4ac-47de-8066-a8a70fb7b9ca, 00m40s elapsed]
cloudstack_autoscale_vm_profile.vm_profile: Still modifying... [id=00196cec-b4ac-47de-8066-a8a70fb7b9ca, 00m50s elapsed]
cloudstack_autoscale_vm_profile.vm_profile: Still modifying... [id=00196cec-b4ac-47de-8066-a8a70fb7b9ca, 01m00s elapsed]
╷
│ Error: Autoscale VM groups must be disabled before updating profile: Autoscale VM groups must be disabled before updating profile: Timeout waiting for VM groups to reach state 'disabled' after 60 seconds
│ 
│   with cloudstack_autoscale_vm_profile.vm_profile,
│   on main.tf line 87, in resource "cloudstack_autoscale_vm_profile" "vm_profile":
│   87: resource "cloudstack_autoscale_vm_profile" "vm_profile" {

@kiranchavala kiranchavala merged commit 86dc428 into main Sep 25, 2025
67 of 69 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improvement issue for AutoScale VM Groups with Terraform.
3 participants