Skip to content

Conversation

@ianc769
Copy link
Contributor

@ianc769 ianc769 commented Sep 15, 2025

Followup from #67

Comment Thread in #217

Adding Data Source

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

data "cloudstack_zone" "zone" {
  filter {
    name = "name"
    value = "ref-trl-9433-k-Mol8-kiran-chavala"
  }
}

data "cloudstack_pod" "pod" {
  filter {
    name = "name"
    value = "Pod1"
  }
}

# Create a cluster first
resource "cloudstack_cluster" "test_cluster" {
  cluster_name = "terraform-test-cluster"
  cluster_type = "CloudManaged"
  hypervisor = "KVM"
  pod_id = data.cloudstack_pod.pod.id
  zone_id = data.cloudstack_zone.zone.id
}

# Then query it with the data source
data "cloudstack_cluster" "test" {
  filter {
    name = "name"
    value = "terraform-test-cluster"
  }
  depends_on = [cloudstack_cluster.test_cluster]
}



output "cloudstack_cluster_details" {
  description = "cluster_id"
  value       = data.cloudstack_cluster.test.id
}

terraform apply
data.cloudstack_zone.zone: Reading...
data.cloudstack_pod.pod: Reading...
data.cloudstack_pod.pod: Read complete after 0s [id=6079c0a3-e6d5-4eaf-ab47-551f657e5379]
data.cloudstack_zone.zone: Read complete after 0s [id=05d9863d-bd94-41c2-bba8-251aab44637a]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create
 <= read (data resources)

Terraform will perform the following actions:

  # data.cloudstack_cluster.test will be read during apply
  # (depends on a resource or a module with changes pending)
 <= data "cloudstack_cluster" "test" {
      + allocation_state        = (known after apply)
      + arch                    = (known after apply)
      + capacity                = (known after apply)
      + cluster_name            = (known after apply)
      + cluster_type            = (known after apply)
      + cpu_overcommit_ratio    = (known after apply)
      + guest_vswitch_name      = (known after apply)
      + guest_vswitch_type      = (known after apply)
      + hypervisor              = (known after apply)
      + id                      = (known after apply)
      + managed_state           = (known after apply)
      + memory_overcommit_ratio = (known after apply)
      + name                    = (known after apply)
      + ovm3_cluster            = (known after apply)
      + ovm3_pool               = (known after apply)
      + ovm3_vip                = (known after apply)
      + ovm3vip                 = (known after apply)
      + password                = (sensitive value)
      + pod_id                  = (known after apply)
      + pod_name                = (known after apply)
      + public_vswitch_name     = (known after apply)
      + public_vswitch_type     = (known after apply)
      + url                     = (known after apply)
      + username                = (known after apply)
      + vsm_ip_address          = (known after apply)
      + vsm_password            = (sensitive value)
      + vsm_username            = (known after apply)
      + zone_id                 = (known after apply)
      + zone_name               = (known after apply)

      + filter {
          + name  = "name"
          + value = "terraform-test-cluster"
        }
    }

  # cloudstack_cluster.test_cluster will be created
  + resource "cloudstack_cluster" "test_cluster" {
      + allocation_state = (known after apply)
      + cluster_name     = "terraform-test-cluster"
      + cluster_type     = "CloudManaged"
      + hypervisor       = "KVM"
      + id               = (known after apply)
      + pod_id           = "6079c0a3-e6d5-4eaf-ab47-551f657e5379"
      + zone_id          = "05d9863d-bd94-41c2-bba8-251aab44637a"
    }

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

Changes to Outputs:
  + cloudstack_cluster_details = (known after apply)

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_cluster.test_cluster: Creating...
cloudstack_cluster.test_cluster: Creation complete after 0s [id=d576bb30-42e3-46a6-8d9f-2aad062a6245]
data.cloudstack_cluster.test: Reading...
data.cloudstack_cluster.test: Read complete after 1s [id=d576bb30-42e3-46a6-8d9f-2aad062a6245]

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

Outputs:

cloudstack_cluster_details = "d576bb30-42e3-46a6-8d9f-2aad062a6245"

Copy link
Contributor

@DaanHoogland DaanHoogland left a comment

Choose a reason for hiding this comment

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

clgtm

@DaanHoogland DaanHoogland merged commit 5191290 into apache:main Sep 16, 2025
24 checks passed
@ianc769 ianc769 deleted the feature/cluster-data-source branch September 22, 2025 16:52
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.

3 participants