Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions cloudstack/resource_cloudstack_kubernetes_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,25 @@ func resourceCloudStackKubernetesCluster() *schema.Resource {
Optional: true,
Default: 8,
},

"docker_registry_url": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},

"docker_registry_username": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},

"docker_registry_password": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Sensitive: true,
Comment on lines +148 to +152

Copilot AI Sep 2, 2025

Copy link

Choose a reason for hiding this comment

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

The docker_registry_password field should include DiffSuppressOnRefresh: true to prevent sensitive values from being stored in state and logged during refresh operations.

Suggested change
"docker_registry_password": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Sensitive: true,
Sensitive: true,
DiffSuppressOnRefresh: true,

Copilot uses AI. Check for mistakes.
},
},
}
}
Expand Down Expand Up @@ -180,6 +199,15 @@ func resourceCloudStackKubernetesClusterCreate(d *schema.ResourceData, meta inte
if noderootdisksize, ok := d.GetOk("noderootdisksize"); ok {
p.SetNoderootdisksize(int64(noderootdisksize.(int)))
}
if dockerurl, ok := d.GetOk("docker_registry_url"); ok {
p.SetDockerregistryurl(dockerurl.(string))
}
if dockerusername, ok := d.GetOk("docker_registry_username"); ok {
p.SetDockerregistryusername(dockerusername.(string))
}
if dockerpassword, ok := d.GetOk("docker_registry_password"); ok {
p.SetDockerregistrypassword(dockerpassword.(string))
}

// If there is a project supplied, we retrieve and set the project id
if err := setProjectid(p, cs, d); err != nil {
Expand All @@ -189,6 +217,13 @@ func resourceCloudStackKubernetesClusterCreate(d *schema.ResourceData, meta inte
log.Printf("[DEBUG] Creating Kubernetes Cluster %s", name)
r, err := cs.Kubernetes.CreateKubernetesCluster(p)
if err != nil {
cluster, _, errg := cs.Kubernetes.GetKubernetesClusterByName(
name,
cloudstack.WithProject(d.Get("project").(string)),
)
if errg == nil {
d.SetId(cluster.Id)
}
Comment on lines +220 to +226

Copilot AI Sep 2, 2025

Copy link

Choose a reason for hiding this comment

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

Setting the resource ID on creation failure is incorrect. This creates inconsistent state where Terraform believes the resource was created successfully but the actual creation failed. The original error should be returned without setting the ID, allowing Terraform to properly handle the failed creation.

Suggested change
cluster, _, errg := cs.Kubernetes.GetKubernetesClusterByName(
name,
cloudstack.WithProject(d.Get("project").(string)),
)
if errg == nil {
d.SetId(cluster.Id)
}

Copilot uses AI. Check for mistakes.
return err
}

Expand Down