Skip to content
Merged
Show file tree
Hide file tree
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
16 changes: 6 additions & 10 deletions spectrocloud/resource_alert_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,26 @@ package spectrocloud
import (
"context"
"fmt"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func resourceAlertImport(ctx context.Context, d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) {
c := getV1ClientWithResourceContext(m, "tenant")
idParts := strings.Split(d.Id(), ":")
if len(idParts) != 2 {
return nil, fmt.Errorf("invalid import ID format, expected 'alertUid:component', got: %s", d.Id())
}
alertUid := idParts[0]
component := idParts[1]

idParts := d.Id()
context := "project"
c := getV1ClientWithResourceContext(m, context)
pjt, err := c.GetProject(ProviderInitProjectUid)
if err != nil {
return nil, err
}
if err := d.Set("project", pjt.Metadata.Name); err != nil {
return nil, err
}
if err := d.Set("component", component); err != nil {
if err := d.Set("component", "ClusterHealth"); err != nil {
return nil, err
}
d.SetId(alertUid)
d.SetId(idParts)
// Read all alert data to populate the state
diags := resourceAlertRead(ctx, d, m)
if diags.HasError() {
Expand Down
11 changes: 5 additions & 6 deletions spectrocloud/resource_cluster_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,11 @@ func resourceClusterGroup() *schema.Resource {
Default: "",
},
"k8s_distribution": {
Type: schema.TypeString,
Optional: true,
Default: "k3s",
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{"k3s", "cncf_k8s"}, false),
Description: "The Kubernetes distribution, allowed values are `k3s` and `cncf_k8s`.",
Type: schema.TypeString,
Optional: true,
Default: "k3s",
ForceNew: true,
Description: "The Kubernetes distribution, allowed values are `k3s` and `cncf_k8s`.",
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion spectrocloud/resource_cluster_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func resourceClusterProfileUpdate(ctx context.Context, d *schema.ResourceData, m
}
}

if d.HasChanges("name") || d.HasChanges("tags") || d.HasChanges("pack") {
if d.HasChanges("name") || d.HasChanges("tags") || d.HasChanges("pack") || d.HasChanges("description") {
log.Printf("Updating packs")
cp, err := c.GetClusterProfile(d.Id())
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions spectrocloud/resource_cluster_virtual.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ func resourceClusterVirtual() *schema.Resource {
Description: "The description of the cluster. Default value is empty string.",
},
"host_cluster_uid": {
Type: schema.TypeString,
Optional: true,
ExactlyOneOf: []string{"host_cluster_uid", "cluster_group_uid"},
Type: schema.TypeString,
Optional: true,
// ExactlyOneOf: []string{"host_cluster_uid", "cluster_group_uid"},
ValidateFunc: validation.StringNotInSlice([]string{""}, false),
},
"cluster_group_uid": {
Expand Down
27 changes: 27 additions & 0 deletions spectrocloud/resource_cluster_virtual_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,33 @@ func resourceClusterVirtualImport(ctx context.Context, d *schema.ResourceData, m
return nil, err
}

if err := d.Set("cluster_group_uid", cluster.Spec.ClusterConfig.HostClusterConfig.ClusterGroup.UID); err != nil {
return nil, err
}

// setting up default settings for import
if err := d.Set("host_cluster_uid", cluster.Spec.ClusterConfig.HostClusterConfig.HostCluster.UID); err != nil {
return nil, err
}
if err := d.Set("apply_setting", "DownloadAndInstall"); err != nil {
return nil, err
}
if err := d.Set("force_delete", false); err != nil {
return nil, err
}
if err := d.Set("force_delete_delay", 20); err != nil {
return nil, err
}
if err := d.Set("skip_completion", false); err != nil {
return nil, err
}
if err := d.Set("os_patch_on_boot", false); err != nil {
return nil, err
}
if err := d.Set("pause_cluster", false); err != nil {
return nil, err
}

// Read all cluster data to populate the state
diags := resourceClusterVirtualRead(ctx, d, m)
if diags.HasError() {
Expand Down
10 changes: 4 additions & 6 deletions spectrocloud/resource_ssh_key_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,10 @@ func GetCommonSSHKey(d *schema.ResourceData, m interface{}) (*client.V1Client, e
return nil, err
}

// Set the SSH key value (this is required)
if sshKey.Spec != nil && sshKey.Spec.PublicKey != "" {
if err := d.Set("ssh_key", sshKey.Spec.PublicKey); err != nil {
return nil, err
}
}
// Note: We don't set the 'ssh_key' field during import because it's marked as sensitive.
// This follows the same pattern as other sensitive fields (like credentials in cloud accounts).
// The user will need to provide the ssh_key value in their Terraform configuration after import.
// This is a security best practice to prevent sensitive data from being stored in state during import.

// Set the ID to the SSH key ID
d.SetId(sshKeyID)
Expand Down