From 12766140d05e2ba46dce49b6b524c937f52cfdd4 Mon Sep 17 00:00:00 2001 From: Alexander Kita Date: Wed, 20 Nov 2024 11:40:45 -0600 Subject: [PATCH] Power SPPP Refactor --- .../resource_ibm_pi_spp_placement_group.go | 52 +++++++++---------- ...esource_ibm_pi_spp_placement_group_test.go | 28 ++++------ .../r/pi_spp_placement_group.html.markdown | 1 - 3 files changed, 36 insertions(+), 45 deletions(-) diff --git a/ibm/service/power/resource_ibm_pi_spp_placement_group.go b/ibm/service/power/resource_ibm_pi_spp_placement_group.go index 534439feea..22978a7582 100644 --- a/ibm/service/power/resource_ibm_pi_spp_placement_group.go +++ b/ibm/service/power/resource_ibm_pi_spp_placement_group.go @@ -10,8 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - st "github.com/IBM-Cloud/power-go-client/clients/instance" - "github.com/IBM-Cloud/power-go-client/helpers" + "github.com/IBM-Cloud/power-go-client/clients/instance" models "github.com/IBM-Cloud/power-go-client/power/models" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" @@ -32,40 +31,41 @@ func ResourceIBMPISPPPlacementGroup() *schema.Resource { }, Schema: map[string]*schema.Schema{ + // Arguments + Arg_CloudInstanceID: { + Description: "PI cloud instance ID", + ForceNew: true, + Required: true, + Type: schema.TypeString, + }, Arg_SPPPlacementGroupName: { - Type: schema.TypeString, - Required: true, - ForceNew: true, Description: "Name of the SPP placement group", + ForceNew: true, + Required: true, + Type: schema.TypeString, }, Arg_SPPPlacementGroupPolicy: { - Type: schema.TypeString, - Required: true, + Description: "Policy of the SPP placement group", ForceNew: true, + Required: true, + Type: schema.TypeString, ValidateFunc: validate.ValidateAllowedStringValues([]string{"affinity", "anti-affinity"}), - Description: "Policy of the SPP placement group", }, - helpers.PICloudInstanceId: { + // Attributes + Attr_SPPPlacementGroupID: { + Computed: true, + Description: "SPP placement group ID", Type: schema.TypeString, - Required: true, - ForceNew: true, - Description: "PI cloud instance ID", }, Attr_SPPPlacementGroupMembers: { - Type: schema.TypeSet, Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, Description: "Member SPP IDs that are the SPP placement group members", - }, - - Attr_SPPPlacementGroupID: { - Type: schema.TypeString, - Computed: true, - Description: "SPP placement group ID", + Elem: &schema.Schema{Type: schema.TypeString}, + Type: schema.TypeSet, }, }, } @@ -77,10 +77,10 @@ func resourceIBMPISPPPlacementGroupCreate(ctx context.Context, d *schema.Resourc return diag.FromErr(err) } - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) name := d.Get(Arg_SPPPlacementGroupName).(string) policy := d.Get(Arg_SPPPlacementGroupPolicy).(string) - client := st.NewIBMPISPPPlacementGroupClient(ctx, sess, cloudInstanceID) + client := instance.NewIBMPISPPPlacementGroupClient(ctx, sess, cloudInstanceID) body := &models.SPPPlacementGroupCreate{ Name: &name, Policy: &policy, @@ -107,7 +107,7 @@ func resourceIBMPISPPPlacementGroupRead(ctx context.Context, d *schema.ResourceD } cloudInstanceID := parts[0] - client := st.NewIBMPISPPPlacementGroupClient(ctx, sess, cloudInstanceID) + client := instance.NewIBMPISPPPlacementGroupClient(ctx, sess, cloudInstanceID) response, err := client.Get(parts[1]) if err != nil || response == nil { @@ -115,10 +115,10 @@ func resourceIBMPISPPPlacementGroupRead(ctx context.Context, d *schema.ResourceD } d.Set(Arg_CloudInstanceID, cloudInstanceID) - d.Set(Arg_SPPPlacementGroupName, response.Name) d.Set(Attr_SPPPlacementGroupID, response.ID) - d.Set(Arg_SPPPlacementGroupPolicy, response.Policy) d.Set(Attr_SPPPlacementGroupMembers, response.MemberSharedProcessorPools) + d.Set(Arg_SPPPlacementGroupName, response.Name) + d.Set(Arg_SPPPlacementGroupPolicy, response.Policy) return nil @@ -134,7 +134,7 @@ func resourceIBMPISPPPlacementGroupDelete(ctx context.Context, d *schema.Resourc return diag.FromErr(err) } cloudInstanceID := parts[0] - client := st.NewIBMPISPPPlacementGroupClient(ctx, sess, cloudInstanceID) + client := instance.NewIBMPISPPPlacementGroupClient(ctx, sess, cloudInstanceID) err = client.Delete(parts[1]) if err != nil { diff --git a/ibm/service/power/resource_ibm_pi_spp_placement_group_test.go b/ibm/service/power/resource_ibm_pi_spp_placement_group_test.go index 0df6351a1a..2fa85c3fcf 100644 --- a/ibm/service/power/resource_ibm_pi_spp_placement_group_test.go +++ b/ibm/service/power/resource_ibm_pi_spp_placement_group_test.go @@ -31,7 +31,7 @@ func TestAccIBMPISPPPlacementGroupBasic(t *testing.T) { CheckDestroy: testAccCheckIBMPISPPPlacementGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckIBMPICreateSAPInstanceWithSPP(name, policy, "tinytest-1x4"), + Config: testAccCheckIBMPICreateSAPInstanceWithSPP(name, policy), ExpectError: regexp.MustCompile("\"pi_shared_processor_pool\": conflicts with pi_sap_profile_id"), }, { @@ -404,8 +404,7 @@ func testAccCheckIBMPISPPPlacementGroupConfig(name string, policy string) string pi_cloud_instance_id = "%[1]s" pi_spp_placement_group_name = "%[2]spg" pi_spp_placement_group_policy = "%[3]s" - } - `, acc.Pi_cloud_instance_id, name, policy) + }`, acc.Pi_cloud_instance_id, name, policy) } func testAccCheckIBMPISPPPlacementGroupAddMemberConfig(name string, policy string) string { @@ -422,8 +421,7 @@ func testAccCheckIBMPISPPPlacementGroupAddMemberConfig(name string, policy strin pi_cloud_instance_id = "%[1]s" pi_spp_placement_group_name = "%[2]spg" pi_spp_placement_group_policy = "%[3]s" - } - `, acc.Pi_cloud_instance_id, name, policy) + }`, acc.Pi_cloud_instance_id, name, policy) } func testAccCheckIBMPISPPPlacementGroupUpdateMemberConfig(name string, policy string) string { @@ -444,8 +442,7 @@ func testAccCheckIBMPISPPPlacementGroupUpdateMemberConfig(name string, policy st pi_cloud_instance_id = "%[1]s" pi_spp_placement_group_name = "%[2]s2pg" pi_spp_placement_group_policy = "%[3]s" - } - `, acc.Pi_cloud_instance_id, name, policy) + }`, acc.Pi_cloud_instance_id, name, policy) } func testAccCheckIBMPISPPPlacementGroupRemoveMemberConfig(name string, policy string) string { @@ -466,8 +463,7 @@ func testAccCheckIBMPISPPPlacementGroupRemoveMemberConfig(name string, policy st pi_cloud_instance_id = "%[1]s" pi_spp_placement_group_name = "%[2]s2pg" pi_spp_placement_group_policy = "%[3]s" - } - `, acc.Pi_cloud_instance_id, name, policy) + }`, acc.Pi_cloud_instance_id, name, policy) } func testAccCheckIBMPICreateSPPInPlacementGroup(name string, policy string) string { @@ -496,8 +492,7 @@ func testAccCheckIBMPICreateSPPInPlacementGroup(name string, policy string) stri pi_cloud_instance_id = "%[1]s" pi_spp_placement_group_name = "%[2]s2pg" pi_spp_placement_group_policy = "%[3]s" - } - `, acc.Pi_cloud_instance_id, name, policy) + }`, acc.Pi_cloud_instance_id, name, policy) } func testAccCheckIBMPIDeleteSPPPlacementGroup(name string, policy string) string { @@ -523,8 +518,7 @@ func testAccCheckIBMPIDeleteSPPPlacementGroup(name string, policy string) string pi_cloud_instance_id = "%[1]s" pi_spp_placement_group_name = "%[2]s2pg" pi_spp_placement_group_policy = "%[3]s" - } - `, acc.Pi_cloud_instance_id, name, policy) + }`, acc.Pi_cloud_instance_id, name, policy) } func testAccCheckIBMPICreateInstanceWithSPP(name string, policy string) string { @@ -586,11 +580,10 @@ func testAccCheckIBMPICreateInstanceWithSPP(name string, policy string) string { network_id = data.ibm_pi_network.power_networks.id } pi_shared_processor_pool = ibm_pi_shared_processor_pool.spp_pool.pi_shared_processor_pool_name - } - `, acc.Pi_cloud_instance_id, name, policy, acc.Pi_image, acc.Pi_network_name) + }`, acc.Pi_cloud_instance_id, name, policy, acc.Pi_image, acc.Pi_network_name) } -func testAccCheckIBMPICreateSAPInstanceWithSPP(name string, policy string, sapProfile string) string { +func testAccCheckIBMPICreateSAPInstanceWithSPP(name string, policy string) string { return fmt.Sprintf(` resource "ibm_pi_shared_processor_pool" "spp_pool" { pi_cloud_instance_id = "%[1]s" @@ -661,6 +654,5 @@ func testAccCheckIBMPICreateSAPInstanceWithSPP(name string, policy string, sapPr } pi_health_status = "OK" pi_shared_processor_pool = ibm_pi_shared_processor_pool.spp_pool_2.pi_shared_processor_pool_name - } - `, acc.Pi_cloud_instance_id, name, policy, acc.Pi_image, acc.Pi_network_name, acc.Pi_sap_image, sapProfile) + }`, acc.Pi_cloud_instance_id, name, policy, acc.Pi_image, acc.Pi_network_name, acc.Pi_sap_image, acc.PiSAPProfileID) } diff --git a/website/docs/r/pi_spp_placement_group.html.markdown b/website/docs/r/pi_spp_placement_group.html.markdown index 9e18247b25..def2c27185 100644 --- a/website/docs/r/pi_spp_placement_group.html.markdown +++ b/website/docs/r/pi_spp_placement_group.html.markdown @@ -1,5 +1,4 @@ --- - subcategory: "Power Systems" layout: "ibm" page_title: "IBM: pi_spp_placement_group"