Skip to content

Commit 1276614

Browse files
Power SPPP Refactor
1 parent 040936f commit 1276614

File tree

3 files changed

+36
-45
lines changed

3 files changed

+36
-45
lines changed

ibm/service/power/resource_ibm_pi_spp_placement_group.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import (
1010

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

13-
st "github.com/IBM-Cloud/power-go-client/clients/instance"
14-
"github.com/IBM-Cloud/power-go-client/helpers"
13+
"github.com/IBM-Cloud/power-go-client/clients/instance"
1514
models "github.com/IBM-Cloud/power-go-client/power/models"
1615
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
1716
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
@@ -32,40 +31,41 @@ func ResourceIBMPISPPPlacementGroup() *schema.Resource {
3231
},
3332

3433
Schema: map[string]*schema.Schema{
34+
// Arguments
35+
Arg_CloudInstanceID: {
36+
Description: "PI cloud instance ID",
37+
ForceNew: true,
38+
Required: true,
39+
Type: schema.TypeString,
40+
},
3541

3642
Arg_SPPPlacementGroupName: {
37-
Type: schema.TypeString,
38-
Required: true,
39-
ForceNew: true,
4043
Description: "Name of the SPP placement group",
44+
ForceNew: true,
45+
Required: true,
46+
Type: schema.TypeString,
4147
},
4248

4349
Arg_SPPPlacementGroupPolicy: {
44-
Type: schema.TypeString,
45-
Required: true,
50+
Description: "Policy of the SPP placement group",
4651
ForceNew: true,
52+
Required: true,
53+
Type: schema.TypeString,
4754
ValidateFunc: validate.ValidateAllowedStringValues([]string{"affinity", "anti-affinity"}),
48-
Description: "Policy of the SPP placement group",
4955
},
5056

51-
helpers.PICloudInstanceId: {
57+
// Attributes
58+
Attr_SPPPlacementGroupID: {
59+
Computed: true,
60+
Description: "SPP placement group ID",
5261
Type: schema.TypeString,
53-
Required: true,
54-
ForceNew: true,
55-
Description: "PI cloud instance ID",
5662
},
5763

5864
Attr_SPPPlacementGroupMembers: {
59-
Type: schema.TypeSet,
6065
Computed: true,
61-
Elem: &schema.Schema{Type: schema.TypeString},
6266
Description: "Member SPP IDs that are the SPP placement group members",
63-
},
64-
65-
Attr_SPPPlacementGroupID: {
66-
Type: schema.TypeString,
67-
Computed: true,
68-
Description: "SPP placement group ID",
67+
Elem: &schema.Schema{Type: schema.TypeString},
68+
Type: schema.TypeSet,
6969
},
7070
},
7171
}
@@ -77,10 +77,10 @@ func resourceIBMPISPPPlacementGroupCreate(ctx context.Context, d *schema.Resourc
7777
return diag.FromErr(err)
7878
}
7979

80-
cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string)
80+
cloudInstanceID := d.Get(Arg_CloudInstanceID).(string)
8181
name := d.Get(Arg_SPPPlacementGroupName).(string)
8282
policy := d.Get(Arg_SPPPlacementGroupPolicy).(string)
83-
client := st.NewIBMPISPPPlacementGroupClient(ctx, sess, cloudInstanceID)
83+
client := instance.NewIBMPISPPPlacementGroupClient(ctx, sess, cloudInstanceID)
8484
body := &models.SPPPlacementGroupCreate{
8585
Name: &name,
8686
Policy: &policy,
@@ -107,18 +107,18 @@ func resourceIBMPISPPPlacementGroupRead(ctx context.Context, d *schema.ResourceD
107107
}
108108

109109
cloudInstanceID := parts[0]
110-
client := st.NewIBMPISPPPlacementGroupClient(ctx, sess, cloudInstanceID)
110+
client := instance.NewIBMPISPPPlacementGroupClient(ctx, sess, cloudInstanceID)
111111

112112
response, err := client.Get(parts[1])
113113
if err != nil || response == nil {
114114
return diag.Errorf("error reading the spp placement group: %v", err)
115115
}
116116

117117
d.Set(Arg_CloudInstanceID, cloudInstanceID)
118-
d.Set(Arg_SPPPlacementGroupName, response.Name)
119118
d.Set(Attr_SPPPlacementGroupID, response.ID)
120-
d.Set(Arg_SPPPlacementGroupPolicy, response.Policy)
121119
d.Set(Attr_SPPPlacementGroupMembers, response.MemberSharedProcessorPools)
120+
d.Set(Arg_SPPPlacementGroupName, response.Name)
121+
d.Set(Arg_SPPPlacementGroupPolicy, response.Policy)
122122

123123
return nil
124124

@@ -134,7 +134,7 @@ func resourceIBMPISPPPlacementGroupDelete(ctx context.Context, d *schema.Resourc
134134
return diag.FromErr(err)
135135
}
136136
cloudInstanceID := parts[0]
137-
client := st.NewIBMPISPPPlacementGroupClient(ctx, sess, cloudInstanceID)
137+
client := instance.NewIBMPISPPPlacementGroupClient(ctx, sess, cloudInstanceID)
138138
err = client.Delete(parts[1])
139139

140140
if err != nil {

ibm/service/power/resource_ibm_pi_spp_placement_group_test.go

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestAccIBMPISPPPlacementGroupBasic(t *testing.T) {
3131
CheckDestroy: testAccCheckIBMPISPPPlacementGroupDestroy,
3232
Steps: []resource.TestStep{
3333
{
34-
Config: testAccCheckIBMPICreateSAPInstanceWithSPP(name, policy, "tinytest-1x4"),
34+
Config: testAccCheckIBMPICreateSAPInstanceWithSPP(name, policy),
3535
ExpectError: regexp.MustCompile("\"pi_shared_processor_pool\": conflicts with pi_sap_profile_id"),
3636
},
3737
{
@@ -404,8 +404,7 @@ func testAccCheckIBMPISPPPlacementGroupConfig(name string, policy string) string
404404
pi_cloud_instance_id = "%[1]s"
405405
pi_spp_placement_group_name = "%[2]spg"
406406
pi_spp_placement_group_policy = "%[3]s"
407-
}
408-
`, acc.Pi_cloud_instance_id, name, policy)
407+
}`, acc.Pi_cloud_instance_id, name, policy)
409408
}
410409

411410
func testAccCheckIBMPISPPPlacementGroupAddMemberConfig(name string, policy string) string {
@@ -422,8 +421,7 @@ func testAccCheckIBMPISPPPlacementGroupAddMemberConfig(name string, policy strin
422421
pi_cloud_instance_id = "%[1]s"
423422
pi_spp_placement_group_name = "%[2]spg"
424423
pi_spp_placement_group_policy = "%[3]s"
425-
}
426-
`, acc.Pi_cloud_instance_id, name, policy)
424+
}`, acc.Pi_cloud_instance_id, name, policy)
427425
}
428426

429427
func testAccCheckIBMPISPPPlacementGroupUpdateMemberConfig(name string, policy string) string {
@@ -444,8 +442,7 @@ func testAccCheckIBMPISPPPlacementGroupUpdateMemberConfig(name string, policy st
444442
pi_cloud_instance_id = "%[1]s"
445443
pi_spp_placement_group_name = "%[2]s2pg"
446444
pi_spp_placement_group_policy = "%[3]s"
447-
}
448-
`, acc.Pi_cloud_instance_id, name, policy)
445+
}`, acc.Pi_cloud_instance_id, name, policy)
449446
}
450447

451448
func testAccCheckIBMPISPPPlacementGroupRemoveMemberConfig(name string, policy string) string {
@@ -466,8 +463,7 @@ func testAccCheckIBMPISPPPlacementGroupRemoveMemberConfig(name string, policy st
466463
pi_cloud_instance_id = "%[1]s"
467464
pi_spp_placement_group_name = "%[2]s2pg"
468465
pi_spp_placement_group_policy = "%[3]s"
469-
}
470-
`, acc.Pi_cloud_instance_id, name, policy)
466+
}`, acc.Pi_cloud_instance_id, name, policy)
471467
}
472468

473469
func testAccCheckIBMPICreateSPPInPlacementGroup(name string, policy string) string {
@@ -496,8 +492,7 @@ func testAccCheckIBMPICreateSPPInPlacementGroup(name string, policy string) stri
496492
pi_cloud_instance_id = "%[1]s"
497493
pi_spp_placement_group_name = "%[2]s2pg"
498494
pi_spp_placement_group_policy = "%[3]s"
499-
}
500-
`, acc.Pi_cloud_instance_id, name, policy)
495+
}`, acc.Pi_cloud_instance_id, name, policy)
501496
}
502497

503498
func testAccCheckIBMPIDeleteSPPPlacementGroup(name string, policy string) string {
@@ -523,8 +518,7 @@ func testAccCheckIBMPIDeleteSPPPlacementGroup(name string, policy string) string
523518
pi_cloud_instance_id = "%[1]s"
524519
pi_spp_placement_group_name = "%[2]s2pg"
525520
pi_spp_placement_group_policy = "%[3]s"
526-
}
527-
`, acc.Pi_cloud_instance_id, name, policy)
521+
}`, acc.Pi_cloud_instance_id, name, policy)
528522
}
529523

530524
func testAccCheckIBMPICreateInstanceWithSPP(name string, policy string) string {
@@ -586,11 +580,10 @@ func testAccCheckIBMPICreateInstanceWithSPP(name string, policy string) string {
586580
network_id = data.ibm_pi_network.power_networks.id
587581
}
588582
pi_shared_processor_pool = ibm_pi_shared_processor_pool.spp_pool.pi_shared_processor_pool_name
589-
}
590-
`, acc.Pi_cloud_instance_id, name, policy, acc.Pi_image, acc.Pi_network_name)
583+
}`, acc.Pi_cloud_instance_id, name, policy, acc.Pi_image, acc.Pi_network_name)
591584
}
592585

593-
func testAccCheckIBMPICreateSAPInstanceWithSPP(name string, policy string, sapProfile string) string {
586+
func testAccCheckIBMPICreateSAPInstanceWithSPP(name string, policy string) string {
594587
return fmt.Sprintf(`
595588
resource "ibm_pi_shared_processor_pool" "spp_pool" {
596589
pi_cloud_instance_id = "%[1]s"
@@ -661,6 +654,5 @@ func testAccCheckIBMPICreateSAPInstanceWithSPP(name string, policy string, sapPr
661654
}
662655
pi_health_status = "OK"
663656
pi_shared_processor_pool = ibm_pi_shared_processor_pool.spp_pool_2.pi_shared_processor_pool_name
664-
}
665-
`, acc.Pi_cloud_instance_id, name, policy, acc.Pi_image, acc.Pi_network_name, acc.Pi_sap_image, sapProfile)
657+
}`, acc.Pi_cloud_instance_id, name, policy, acc.Pi_image, acc.Pi_network_name, acc.Pi_sap_image, acc.PiSAPProfileID)
666658
}

website/docs/r/pi_spp_placement_group.html.markdown

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
---
2-
32
subcategory: "Power Systems"
43
layout: "ibm"
54
page_title: "IBM: pi_spp_placement_group"

0 commit comments

Comments
 (0)