Skip to content

Commit 3817c89

Browse files
committed
PLT-1947: Fixed import support for sshkey, application, clusterprofile, alert, virtual cluster and application
1 parent ade5524 commit 3817c89

File tree

6 files changed

+46
-26
lines changed

6 files changed

+46
-26
lines changed

spectrocloud/resource_alert_import.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,26 @@ package spectrocloud
33
import (
44
"context"
55
"fmt"
6-
"strings"
76

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

1110
func resourceAlertImport(ctx context.Context, d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) {
12-
c := getV1ClientWithResourceContext(m, "tenant")
13-
idParts := strings.Split(d.Id(), ":")
14-
if len(idParts) != 2 {
15-
return nil, fmt.Errorf("invalid import ID format, expected 'alertUid:component', got: %s", d.Id())
16-
}
17-
alertUid := idParts[0]
18-
component := idParts[1]
11+
12+
idParts := d.Id()
13+
context := "project"
14+
c := getV1ClientWithResourceContext(m, context)
1915
pjt, err := c.GetProject(ProviderInitProjectUid)
2016
if err != nil {
2117
return nil, err
2218
}
2319
if err := d.Set("project", pjt.Metadata.Name); err != nil {
2420
return nil, err
2521
}
26-
if err := d.Set("component", component); err != nil {
22+
if err := d.Set("component", "ClusterHealth"); err != nil {
2723
return nil, err
2824
}
29-
d.SetId(alertUid)
25+
d.SetId(idParts)
3026
// Read all alert data to populate the state
3127
diags := resourceAlertRead(ctx, d, m)
3228
if diags.HasError() {

spectrocloud/resource_cluster_group.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,11 @@ func resourceClusterGroup() *schema.Resource {
9999
Default: "",
100100
},
101101
"k8s_distribution": {
102-
Type: schema.TypeString,
103-
Optional: true,
104-
Default: "k3s",
105-
ForceNew: true,
106-
ValidateFunc: validation.StringInSlice([]string{"k3s", "cncf_k8s"}, false),
107-
Description: "The Kubernetes distribution, allowed values are `k3s` and `cncf_k8s`.",
102+
Type: schema.TypeString,
103+
Optional: true,
104+
Default: "k3s",
105+
ForceNew: true,
106+
Description: "The Kubernetes distribution, allowed values are `k3s` and `cncf_k8s`.",
108107
},
109108
},
110109
},

spectrocloud/resource_cluster_profile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ func resourceClusterProfileUpdate(ctx context.Context, d *schema.ResourceData, m
224224
}
225225
}
226226

227-
if d.HasChanges("name") || d.HasChanges("tags") || d.HasChanges("pack") {
227+
if d.HasChanges("name") || d.HasChanges("tags") || d.HasChanges("pack") || d.HasChanges("description") {
228228
log.Printf("Updating packs")
229229
cp, err := c.GetClusterProfile(d.Id())
230230
if err != nil {

spectrocloud/resource_cluster_virtual.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ func resourceClusterVirtual() *schema.Resource {
6363
Description: "The description of the cluster. Default value is empty string.",
6464
},
6565
"host_cluster_uid": {
66-
Type: schema.TypeString,
67-
Optional: true,
68-
ExactlyOneOf: []string{"host_cluster_uid", "cluster_group_uid"},
66+
Type: schema.TypeString,
67+
Optional: true,
68+
// ExactlyOneOf: []string{"host_cluster_uid", "cluster_group_uid"},
6969
ValidateFunc: validation.StringNotInSlice([]string{""}, false),
7070
},
7171
"cluster_group_uid": {

spectrocloud/resource_cluster_virtual_import.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,33 @@ func resourceClusterVirtualImport(ctx context.Context, d *schema.ResourceData, m
3333
return nil, err
3434
}
3535

36+
if err := d.Set("cluster_group_uid", cluster.Spec.ClusterConfig.HostClusterConfig.ClusterGroup.UID); err != nil {
37+
return nil, err
38+
}
39+
40+
// setting up default settings for import
41+
if err := d.Set("host_cluster_uid", cluster.Spec.ClusterConfig.HostClusterConfig.HostCluster.UID); err != nil {
42+
return nil, err
43+
}
44+
if err := d.Set("apply_setting", "DownloadAndInstall"); err != nil {
45+
return nil, err
46+
}
47+
if err := d.Set("force_delete", false); err != nil {
48+
return nil, err
49+
}
50+
if err := d.Set("force_delete_delay", 20); err != nil {
51+
return nil, err
52+
}
53+
if err := d.Set("skip_completion", false); err != nil {
54+
return nil, err
55+
}
56+
if err := d.Set("os_patch_on_boot", false); err != nil {
57+
return nil, err
58+
}
59+
if err := d.Set("pause_cluster", false); err != nil {
60+
return nil, err
61+
}
62+
3663
// Read all cluster data to populate the state
3764
diags := resourceClusterVirtualRead(ctx, d, m)
3865
if diags.HasError() {

spectrocloud/resource_ssh_key_import.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,10 @@ func GetCommonSSHKey(d *schema.ResourceData, m interface{}) (*client.V1Client, e
8989
return nil, err
9090
}
9191

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

9997
// Set the ID to the SSH key ID
10098
d.SetId(sshKeyID)

0 commit comments

Comments
 (0)