Skip to content

Commit c9676d6

Browse files
authored
Revert "[Resource] [Datasource] Replace SSH Key API with new API (IBM-Cloud#6327)" (IBM-Cloud#6355)
This reverts commit 5540d8c.
1 parent 3cdb7eb commit c9676d6

File tree

8 files changed

+33
-300
lines changed

8 files changed

+33
-300
lines changed

ibm/service/power/data_source_ibm_pi_key.go

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -38,37 +38,12 @@ func DataSourceIBMPIKey() *schema.Resource {
3838
Description: "Date of SSH Key creation.",
3939
Type: schema.TypeString,
4040
},
41-
Attr_Description: {
42-
Computed: true,
43-
Description: "Description of the ssh key.",
44-
Type: schema.TypeString,
45-
},
46-
Attr_KeyName: {
47-
Computed: true,
48-
Description: "Name of SSH key.",
49-
Type: schema.TypeString,
50-
},
51-
Attr_PrimaryWorkspace: {
52-
Computed: true,
53-
Description: "Indicates if the current workspace owns the ssh key or not.",
54-
Type: schema.TypeBool,
55-
},
5641
Attr_SSHKey: {
5742
Computed: true,
5843
Description: "SSH RSA key.",
5944
Sensitive: true,
6045
Type: schema.TypeString,
6146
},
62-
Attr_SSHKeyID: {
63-
Computed: true,
64-
Description: "Unique ID of SSH key.",
65-
Type: schema.TypeString,
66-
},
67-
Attr_Visibility: {
68-
Computed: true,
69-
Description: "Visibility of the ssh key.",
70-
Type: schema.TypeString,
71-
},
7247
},
7348
}
7449
}
@@ -81,20 +56,15 @@ func dataSourceIBMPIKeyRead(ctx context.Context, d *schema.ResourceData, meta in
8156

8257
cloudInstanceID := d.Get(Arg_CloudInstanceID).(string)
8358

84-
sshkeyC := instance.NewIBMPISSHKeyClient(ctx, sess, cloudInstanceID)
59+
sshkeyC := instance.NewIBMPIKeyClient(ctx, sess, cloudInstanceID)
8560
sshkeydata, err := sshkeyC.Get(d.Get(helpers.PIKeyName).(string))
8661
if err != nil {
8762
return diag.FromErr(err)
8863
}
8964

9065
d.SetId(*sshkeydata.Name)
9166
d.Set(Attr_CreationDate, sshkeydata.CreationDate.String())
92-
d.Set(Attr_Description, sshkeydata.Description)
93-
d.Set(Attr_KeyName, sshkeydata.Name)
94-
d.Set(Attr_PrimaryWorkspace, sshkeydata.PrimaryWorkspace)
9567
d.Set(Attr_SSHKey, sshkeydata.SSHKey)
96-
d.Set(Attr_SSHKeyID, sshkeydata.ID)
97-
d.Set(Attr_Visibility, sshkeydata.Visibility)
9868

9969
return nil
10070
}

ibm/service/power/data_source_ibm_pi_keys.go

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -38,36 +38,16 @@ func DataSourceIBMPIKeys() *schema.Resource {
3838
Description: "Date of SSH key creation.",
3939
Type: schema.TypeString,
4040
},
41-
Attr_Description: {
42-
Computed: true,
43-
Description: "Description of the ssh key.",
44-
Type: schema.TypeString,
45-
},
4641
Attr_Name: {
4742
Computed: true,
4843
Description: "User defined name for the SSH key.",
4944
Type: schema.TypeString,
5045
},
51-
Attr_PrimaryWorkspace: {
52-
Computed: true,
53-
Description: "Indicates if the current workspace owns the ssh key or not.",
54-
Type: schema.TypeBool,
55-
},
5646
Attr_SSHKey: {
5747
Computed: true,
5848
Description: "SSH RSA key.",
5949
Type: schema.TypeString,
6050
},
61-
Attr_SSHKeyID: {
62-
Computed: true,
63-
Description: "Unique ID of SSH key.",
64-
Type: schema.TypeString,
65-
},
66-
Attr_Visibility: {
67-
Computed: true,
68-
Description: "Visibility of the ssh key.",
69-
Type: schema.TypeString,
70-
},
7151
},
7252
},
7353
Type: schema.TypeList,
@@ -84,7 +64,7 @@ func dataSourceIBMPIKeysRead(ctx context.Context, d *schema.ResourceData, meta i
8464

8565
cloudInstanceID := d.Get(Arg_CloudInstanceID).(string)
8666

87-
client := instance.NewIBMPISSHKeyClient(ctx, sess, cloudInstanceID)
67+
client := instance.NewIBMPIKeyClient(ctx, sess, cloudInstanceID)
8868
sshKeys, err := client.GetAll()
8969
if err != nil {
9070
log.Printf("[ERROR] get all keys failed %v", err)
@@ -94,13 +74,9 @@ func dataSourceIBMPIKeysRead(ctx context.Context, d *schema.ResourceData, meta i
9474
result := make([]map[string]interface{}, 0, len(sshKeys.SSHKeys))
9575
for _, sshKey := range sshKeys.SSHKeys {
9676
key := map[string]interface{}{
97-
Attr_CreationDate: sshKey.CreationDate.String(),
98-
Attr_Description: sshKey.Description,
99-
Attr_Name: sshKey.Name,
100-
Attr_PrimaryWorkspace: sshKey.PrimaryWorkspace,
101-
Attr_SSHKey: sshKey.SSHKey,
102-
Attr_SSHKeyID: sshKey.ID,
103-
Attr_Visibility: sshKey.Visibility,
77+
Attr_CreationDate: sshKey.CreationDate.String(),
78+
Attr_Name: sshKey.Name,
79+
Attr_SSHKey: sshKey.SSHKey,
10480
}
10581
result = append(result, key)
10682
}

ibm/service/power/ibm_pi_constants.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ const (
158158
Arg_VirtualCoresAssigned = "pi_virtual_cores_assigned"
159159
Arg_VirtualOpticalDevice = "pi_virtual_optical_device"
160160
Arg_VirtualSerialNumber = "pi_virtual_serial_number"
161-
Arg_Visibility = "pi_visibility"
162161
Arg_VolumeCloneName = "pi_volume_clone_name"
163162
Arg_VolumeCloneTaskID = "pi_volume_clone_task_id"
164163
Arg_VolumeGroupAction = "pi_volume_group_action"
@@ -390,7 +389,6 @@ const (
390389
Attr_PowerEdgeRouter = "power_edge_router"
391390
Attr_Primary = "primary"
392391
Attr_PrimaryRole = "primary_role"
393-
Attr_PrimaryWorkspace = "primary_workspace"
394392
Attr_Processors = "processors"
395393
Attr_ProcType = "proctype"
396394
Attr_Product = "product"
@@ -448,7 +446,6 @@ const (
448446
Attr_SPPPlacementGroupPolicy = "policy"
449447
Attr_SPPPlacementGroups = "spp_placement_groups"
450448
Attr_SSHKey = "ssh_key"
451-
Attr_SSHKeyID = "ssh_key_id"
452449
Attr_Start = "start"
453450
Attr_StartTime = "start_time"
454451
Attr_State = "state"
@@ -500,7 +497,6 @@ const (
500497
Attr_VirtualCoresAssigned = "virtual_cores_assigned"
501498
Attr_VirtualSerialNumber = "virtual_serial_number"
502499
Attr_VirtualSerialNumbers = "virtual_serial_numbers"
503-
Attr_Visibility = "visibility"
504500
Attr_VLanID = "vlan_id"
505501
Attr_VolumeGroupID = "volume_group_id"
506502
Attr_VolumeGroupName = "volume_group_name"
@@ -532,7 +528,6 @@ const (
532528
StockVTL = "stock-vtl"
533529

534530
// Allowed Values
535-
Account = "account"
536531
Affinity = "affinity"
537532
All = "all"
538533
Allow = "allow"
@@ -596,7 +591,6 @@ const (
596591
Vlan = "vlan"
597592
vSCSI = "vSCSI"
598593
Warning = "WARNING"
599-
Workspace = "workspace"
600594

601595
// Actions
602596
Action_HardReboot = "hard-reboot"

ibm/service/power/resource_ibm_pi_key.go

Lines changed: 11 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,21 @@ import (
1313
"github.com/IBM-Cloud/power-go-client/power/models"
1414
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
1515
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
16-
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
1716
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1817
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1918
)
2019

2120
func ResourceIBMPIKey() *schema.Resource {
2221
return &schema.Resource{
23-
CustomizeDiff: customdiff.Sequence(
24-
func(_ context.Context, diff *schema.ResourceDiff, v interface{}) error {
25-
return customizeNameAndSSHKeyPIKeyDiff(diff)
26-
},
27-
),
2822
CreateContext: resourceIBMPIKeyCreate,
2923
ReadContext: resourceIBMPIKeyRead,
3024
UpdateContext: resourceIBMPIKeyUpdate,
3125
DeleteContext: resourceIBMPIKeyDelete,
3226
Importer: &schema.ResourceImporter{},
3327

3428
Timeouts: &schema.ResourceTimeout{
35-
Create: schema.DefaultTimeout(10 * time.Minute),
36-
Update: schema.DefaultTimeout(10 * time.Minute),
37-
Delete: schema.DefaultTimeout(10 * time.Minute),
29+
Create: schema.DefaultTimeout(60 * time.Minute),
30+
Delete: schema.DefaultTimeout(60 * time.Minute),
3831
},
3932

4033
Schema: map[string]*schema.Schema{
@@ -46,11 +39,6 @@ func ResourceIBMPIKey() *schema.Resource {
4639
Type: schema.TypeString,
4740
ValidateFunc: validation.NoZeroValues,
4841
},
49-
Arg_Description: {
50-
Description: "Description of the ssh key.",
51-
Optional: true,
52-
Type: schema.TypeString,
53-
},
5442
Arg_KeyName: {
5543
Description: "User defined name for the SSH key.",
5644
Required: true,
@@ -63,13 +51,7 @@ func ResourceIBMPIKey() *schema.Resource {
6351
Type: schema.TypeString,
6452
ValidateFunc: validation.NoZeroValues,
6553
},
66-
Arg_Visibility: {
67-
Default: Workspace,
68-
Description: "Visibility of the ssh key. Valid values are: [\"account\", \"workspace\"].",
69-
Optional: true,
70-
Type: schema.TypeString,
71-
ValidateFunc: validation.StringInSlice([]string{Account, Workspace}, false),
72-
},
54+
7355
// Attributes
7456
Attr_CreationDate: {
7557
Computed: true,
@@ -78,26 +60,14 @@ func ResourceIBMPIKey() *schema.Resource {
7860
},
7961
Attr_Name: {
8062
Computed: true,
81-
Deprecated: "This field is deprecated and will be removed in a future release. Use pi_key_name instead.",
8263
Description: "User defined name for the SSH key.",
8364
Type: schema.TypeString,
8465
},
8566
Attr_Key: {
8667
Computed: true,
87-
Deprecated: "This field is deprecated and will be removed in a future release. Use pi_ssh_key instead.",
8868
Description: "SSH RSA key.",
8969
Type: schema.TypeString,
9070
},
91-
Attr_PrimaryWorkspace: {
92-
Computed: true,
93-
Description: "Indicates if the current workspace owns the ssh key or not.",
94-
Type: schema.TypeBool,
95-
},
96-
Attr_SSHKeyID: {
97-
Computed: true,
98-
Description: "Unique ID of SSH key.",
99-
Type: schema.TypeString,
100-
},
10171
},
10272
}
10373
}
@@ -113,29 +83,21 @@ func resourceIBMPIKeyCreate(ctx context.Context, d *schema.ResourceData, meta in
11383
cloudInstanceID := d.Get(Arg_CloudInstanceID).(string)
11484
name := d.Get(Arg_KeyName).(string)
11585
sshkey := d.Get(Arg_SSHKey).(string)
116-
visibility := d.Get(Arg_Visibility).(string)
11786

11887
// create key
119-
client := instance.NewIBMPISSHKeyClient(ctx, sess, cloudInstanceID)
120-
body := &models.CreateWorkspaceSSHKey{
121-
Name: &name,
122-
SSHKey: &sshkey,
123-
Visibility: &visibility,
88+
client := instance.NewIBMPIKeyClient(ctx, sess, cloudInstanceID)
89+
body := &models.SSHKey{
90+
Name: &name,
91+
SSHKey: &sshkey,
12492
}
125-
126-
if v, ok := d.GetOk(Arg_Description); ok {
127-
description := v.(string)
128-
body.Description = description
129-
}
130-
13193
sshResponse, err := client.Create(body)
13294
if err != nil {
13395
log.Printf("[DEBUG] err %s", err)
13496
return diag.FromErr(err)
13597
}
13698

13799
log.Printf("Printing the sshkey %+v", *sshResponse)
138-
d.SetId(fmt.Sprintf("%s/%s", cloudInstanceID, *sshResponse.ID))
100+
d.SetId(fmt.Sprintf("%s/%s", cloudInstanceID, name))
139101
return resourceIBMPIKeyRead(ctx, d, meta)
140102
}
141103

@@ -153,70 +115,21 @@ func resourceIBMPIKeyRead(ctx context.Context, d *schema.ResourceData, meta inte
153115
}
154116

155117
// get key
156-
sshkeyC := instance.NewIBMPISSHKeyClient(ctx, sess, cloudInstanceID)
118+
sshkeyC := instance.NewIBMPIKeyClient(ctx, sess, cloudInstanceID)
157119
sshkeydata, err := sshkeyC.Get(key)
158120
if err != nil {
159121
return diag.FromErr(err)
160122
}
161123

162-
// Arguments
163-
d.Set(Arg_CloudInstanceID, cloudInstanceID)
164-
d.Set(Arg_Description, sshkeydata.Description)
165-
d.Set(Arg_KeyName, sshkeydata.Name)
166-
d.Set(Arg_SSHKey, sshkeydata.SSHKey)
167-
d.Set(Arg_Visibility, sshkeydata.Visibility)
168-
169-
// Attributes
124+
// set attributes
170125
d.Set(Attr_CreationDate, sshkeydata.CreationDate.String())
171126
d.Set(Attr_Key, sshkeydata.SSHKey)
172127
d.Set(Attr_Name, sshkeydata.Name)
173-
d.Set(Attr_PrimaryWorkspace, sshkeydata.PrimaryWorkspace)
174-
d.Set(Attr_SSHKeyID, sshkeydata.ID)
175128

176129
return nil
177130
}
178131

179132
func resourceIBMPIKeyUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
180-
// session
181-
sess, err := meta.(conns.ClientSession).IBMPISession()
182-
if err != nil {
183-
return diag.FromErr(err)
184-
}
185-
186-
// arguments
187-
cloudInstanceID, key, err := splitID(d.Id())
188-
if err != nil {
189-
return diag.FromErr(err)
190-
}
191-
192-
client := instance.NewIBMPISSHKeyClient(ctx, sess, cloudInstanceID)
193-
updateBody := &models.UpdateWorkspaceSSHKey{}
194-
195-
if d.HasChange(Arg_Description) {
196-
newDescription := d.Get(Arg_Description).(string)
197-
updateBody.Description = &newDescription
198-
}
199-
200-
if d.HasChange(Arg_KeyName) {
201-
newKeyName := d.Get(Arg_KeyName).(string)
202-
updateBody.Name = &newKeyName
203-
}
204-
205-
if d.HasChange(Arg_SSHKey) {
206-
newSSHKey := d.Get(Arg_SSHKey).(string)
207-
updateBody.SSHKey = &newSSHKey
208-
}
209-
210-
if d.HasChange(Arg_Visibility) {
211-
newVisibility := d.Get(Arg_Visibility).(string)
212-
updateBody.Visibility = &newVisibility
213-
}
214-
215-
_, err = client.Update(key, updateBody)
216-
if err != nil {
217-
return diag.FromErr(err)
218-
}
219-
220133
return resourceIBMPIKeyRead(ctx, d, meta)
221134
}
222135

@@ -234,21 +147,11 @@ func resourceIBMPIKeyDelete(ctx context.Context, d *schema.ResourceData, meta in
234147
}
235148

236149
// delete key
237-
sshkeyC := instance.NewIBMPISSHKeyClient(ctx, sess, cloudInstanceID)
150+
sshkeyC := instance.NewIBMPIKeyClient(ctx, sess, cloudInstanceID)
238151
err = sshkeyC.Delete(key)
239152
if err != nil {
240153
return diag.FromErr(err)
241154
}
242155
d.SetId("")
243156
return nil
244157
}
245-
246-
func customizeNameAndSSHKeyPIKeyDiff(diff *schema.ResourceDiff) error {
247-
if diff.Id() != "" && diff.HasChange(Arg_KeyName) {
248-
diff.SetNewComputed(Attr_Name)
249-
}
250-
if diff.Id() != "" && diff.HasChange(Arg_SSHKey) {
251-
diff.SetNewComputed(Attr_Key)
252-
}
253-
return nil
254-
}

0 commit comments

Comments
 (0)