Skip to content

Commit

Permalink
Refactor placement group
Browse files Browse the repository at this point in the history
  • Loading branch information
Diptipowervs committed Mar 18, 2024
1 parent 5d96eb2 commit 01d9df9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 36 deletions.
37 changes: 18 additions & 19 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 @@ -34,38 +33,38 @@ func ResourceIBMPISPPPlacementGroup() *schema.Resource {
Schema: map[string]*schema.Schema{

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: {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Arg_CloudInstanceID: {
Description: "PI cloud instance ID",
ForceNew: true,
Required: true,
Type: schema.TypeString,
},

Attr_SPPPlacementGroupMembers: {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: "Member SPP IDs that are the SPP placement group members",
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeSet,
},

Attr_SPPPlacementGroupID: {
Type: schema.TypeString,
Computed: true,
Description: "SPP placement group ID",
Type: schema.TypeString,
},
},
}
Expand All @@ -77,10 +76,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,7 +106,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 {
Expand All @@ -134,7 +133,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
24 changes: 8 additions & 16 deletions ibm/service/power/resource_ibm_pi_spp_placement_group_test.go
Original file line number Diff line number Diff line change
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,8 +580,7 @@ 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 {
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, sapProfile)
}
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 01d9df9

Please sign in to comment.