Skip to content

Conversation

@ianc769
Copy link
Contributor

@ianc769 ianc769 commented Sep 9, 2025

Adding cloudstack_pod as a terraform managed resource option -> https://cloudstack.apache.org/api/apidocs-4.20/apis/createPod.html

Adding cloudstack_cluster as a terraform managed resource option -> https://cloudstack.apache.org/api/apidocs-4.20/apis/addCluster.html

Using this code for example:

resource "cloudstack_zone" "zone" {
  name                 = "Terraform Zone"
  dns1                 = "8.8.8.8"
  internal_dns1        = "8.8.8.8"
  network_type         = "Basic"
  securitygroupenabled = false
  domain               = var.dns_domain
}
resource "cloudstack_pod" "foopod" {
  name     = "terraform-pod"
  zone_id  = cloudstack_zone.zone.id
  gateway  = "192.168.56.1"
  netmask  = "255.255.255.0"
  start_ip = "192.168.56.2"
  end_ip   = "192.168.56.254"
}
resource "cloudstack_cluster" "foo" {
  name         = "terraform-cluster"
  cluster_type = "CloudManaged"
  hypervisor   = "KVM"
  pod_id       = cloudstack_pod.foopod.id
  zone_id      = cloudstack_zone.zone.id
  arch         = "x86_64"
}
  # cloudstack_cluster.foo will be created
  + resource "cloudstack_cluster" "foo" {
      + allocation_state        = (known after apply)
      + arch                    = "x86_64"
      + cluster_type            = "CloudManaged"
      + cpu_overcommit_ratio    = (known after apply)
      + hypervisor              = "KVM"
      + id                      = (known after apply)
      + managed_state           = (known after apply)
      + memory_overcommit_ratio = (known after apply)
      + name                    = "terraform-cluster"
      + ovm3vip                 = (known after apply)
      + pod_id                  = (known after apply)
      + pod_name                = (known after apply)
      + zone_id                 = (known after apply)
      + zone_name               = (known after apply)
    }

  # cloudstack_pod.foopod will be created
  + resource "cloudstack_pod" "foopod" {
      + allocation_state = (known after apply)
      + end_ip           = "192.168.56.254"
      + gateway          = "192.168.56.1"
      + id               = (known after apply)
      + name             = "terraform-pod"
      + netmask          = "255.255.255.0"
      + start_ip         = "192.168.56.2"
      + vlan_id          = (known after apply)
      + zone_id          = (known after apply)
      + zone_name        = (known after apply)
    }

  # cloudstack_zone.zone will be created
  + resource "cloudstack_zone" "zone" {
      + allocationstate      = (known after apply)
      + dns1                 = "8.8.8.8"
      + domain               = "dev.example.com"
      + id                   = (known after apply)
      + internal_dns1        = "8.8.8.8"
      + name                 = "Terraform Zone"
      + network_type         = "Basic"
      + securitygroupenabled = false
    }
  Enter a value: yes

cloudstack_zone.zone: Creating...
cloudstack_zone.zone: Creation complete after 1s [id=ea20f61a-b65e-429b-9209-1c041c7416a4]
cloudstack_pod.foopod: Creating...
cloudstack_pod.foopod: Creation complete after 2s [id=4819a4bf-fcf6-49cc-80b2-d7ad50f8e702]
cloudstack_cluster.foo: Creating...
cloudstack_cluster.foo: Creation complete after 0s [id=6a82196f-d1d0-4b71-ab14-f8fabedb4b23]

Apply complete! Resources: 3 added, 1 changed, 0 destroyed.
{3B5DA58B-7F21-4945-BD40-7AFFE1CC2C16} {9638119C-5B19-41CE-BA25-FD32BB20648D}

This commit adds support for managing CloudStack Pods and Clusters through
Terraform. It implements the following new resources and data sources:

Resources:
- cloudstack_pod: Allows creation and management of CloudStack Pods
- cloudstack_cluster: Allows creation and management of CloudStack Clusters

Data Sources:
- cloudstack_cluster: Provides lookup capabilities for existing Clusters

Implementation details:
- Added resource_cloudstack_pod.go with CRUD operations for Pods
- Added resource_cloudstack_cluster.go with CRUD operations for Clusters
- Added data_source_cloudstack_cluster.go for Cluster data source
- Created corresponding test files for all resources and data sources
- Added documentation for all new resources and data sources
- Updated provider.go to register the new resources and data sources
- Added import functionality to both resources
@kiranchavala
Copy link
Collaborator

Thanks @ianc769 could you please resolve the conflicts

@kiranchavala kiranchavala added this to the v0.6.0 milestone Sep 10, 2025
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"
  }
}


resource "cloudstack_pod" "foopod" {
  name = "terraform-pod"
  zone_id = data.cloudstack_zone.zone.id
  gateway = "192.168.56.1"
  netmask = "255.255.255.0"
  start_ip = "192.168.56.2"
  end_ip = "192.168.56.254"
}
resource "cloudstack_cluster" "foo" {
  name = "terraform-cluster"
  cluster_type = "CloudManaged"
  hypervisor = "KVM"
  pod_id = cloudstack_pod.foopod.id
  zone_id = data.cloudstack_zone.zone.id
  arch = "x86_64"
}

terraform apply
data.cloudstack_zone.zone: Reading...
data.cloudstack_zone.zone: Read complete after 1s [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

Terraform will perform the following actions:

  # cloudstack_cluster.foo will be created
  + resource "cloudstack_cluster" "foo" {
      + allocation_state        = (known after apply)
      + arch                    = "x86_64"
      + cluster_type            = "CloudManaged"
      + cpu_overcommit_ratio    = (known after apply)
      + hypervisor              = "KVM"
      + id                      = (known after apply)
      + managed_state           = (known after apply)
      + memory_overcommit_ratio = (known after apply)
      + name                    = "terraform-cluster"
      + ovm3vip                 = (known after apply)
      + pod_id                  = (known after apply)
      + pod_name                = (known after apply)
      + zone_id                 = "05d9863d-bd94-41c2-bba8-251aab44637a"
      + zone_name               = (known after apply)
    }

  # cloudstack_pod.foopod will be created
  + resource "cloudstack_pod" "foopod" {
      + allocation_state = (known after apply)
      + end_ip           = "192.168.56.254"
      + gateway          = "192.168.56.1"
      + id               = (known after apply)
      + name             = "terraform-pod"
      + netmask          = "255.255.255.0"
      + start_ip         = "192.168.56.2"
      + vlan_id          = (known after apply)
      + zone_id          = "05d9863d-bd94-41c2-bba8-251aab44637a"
      + zone_name        = (known after apply)
    }

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

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_pod.foopod: Creating...
cloudstack_pod.foopod: Creation complete after 3s [id=fc2a152e-a97e-4d67-964d-368b256afd70]
cloudstack_cluster.foo: Creating...
cloudstack_cluster.foo: Creation complete after 0s [id=d76ba5d3-7316-4d6f-ad00-cd436122332d]

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

Screenshot 2025-09-12 at 2 00 51 PM Screenshot 2025-09-12 at 2 00 46 PM

@kiranchavala
Copy link
Collaborator

@ianc769 could you please only include the following files in the PR

data_source_cloudstack_cluster.go
data_source_cloudstack_cluster_test.go
cluster.html.markdown

As the other resources pod and cluster have been already included in this

#67

sidshas03 added a commit to sidshas03/cloudstack-terraform-provider that referenced this pull request Sep 15, 2025
- Merged PR apache#217 implementation with main branch
- Used PR branch implementation for cluster and pod resources as it has better error handling and validation
- Resolved conflicts in provider.go, resource files, test files, and documentation
- All tests compile successfully
sidshas03 added a commit to sidshas03/cloudstack-terraform-provider that referenced this pull request Sep 15, 2025
- Add cloudstack_pod resource with full CRUD operations
- Add cloudstack_cluster resource with full CRUD operations
- Add data sources for both resources
- Include comprehensive validation and error handling
- Add complete test coverage
- Add documentation for both resources
- Resolve all merge conflicts from original PR apache#217
@ianc769
Copy link
Contributor Author

ianc769 commented Sep 15, 2025

@ianc769 could you please only include the following files in the PR

data_source_cloudstack_cluster.go data_source_cloudstack_cluster_test.go cluster.html.markdown

As the other resources pod and cluster have been already included in this

#67

Going to Open a new PR from a clean branch for this instead. 👍

@ianc769 ianc769 closed this Sep 15, 2025
@ianc769 ianc769 deleted the feature/pods-and-clusters 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.

2 participants