Skip to content

Commit

Permalink
Power SPPP Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Kita committed Nov 20, 2024
1 parent 040936f commit 1276614
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 45 deletions.
52 changes: 26 additions & 26 deletions ibm/service/power/resource_ibm_pi_spp_placement_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
},
},
}
Expand All @@ -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,
Expand All @@ -107,18 +107,18 @@ 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 {
return diag.Errorf("error reading the spp placement group: %v", err)
}

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

Expand All @@ -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 {
Expand Down
28 changes: 10 additions & 18 deletions ibm/service/power/resource_ibm_pi_spp_placement_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
},
{
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
1 change: 0 additions & 1 deletion website/docs/r/pi_spp_placement_group.html.markdown
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---

subcategory: "Power Systems"
layout: "ibm"
page_title: "IBM: pi_spp_placement_group"
Expand Down

0 comments on commit 1276614

Please sign in to comment.