Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Resource] Add deployment target Argument #5446

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ toolchain go1.22.3

require (
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240216115622-a311507b4b5b
github.com/IBM-Cloud/power-go-client v1.6.0
github.com/IBM-Cloud/power-go-client v1.7.0
github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca
github.com/IBM/appconfiguration-go-admin-sdk v0.3.0
github.com/IBM/appid-management-go-sdk v0.0.0-20210908164609-dd0e0eaf732f
Expand Down
317 changes: 315 additions & 2 deletions go.sum

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions ibm/service/power/ibm_pi_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const (
Arg_CloudInstanceID = "pi_cloud_instance_id"
Arg_Datacenter = "pi_datacenter"
Arg_DatacenterZone = "pi_datacenter_zone"
Arg_DeploymentTarget = "pi_deployment_target"
Arg_Description = "pi_description"
Arg_DhcpCidr = "pi_cidr"
Arg_DhcpCloudConnectionID = "pi_cloud_connection_id"
Expand Down Expand Up @@ -355,6 +356,9 @@ const (
State_Removed = "removed"
State_Retry = "retry"

// Allowed Values
Host = "host"
HostGroup = "hostGroup"
// Health
Health_OK = "OK"

Expand Down
40 changes: 37 additions & 3 deletions ibm/service/power/resource_ibm_pi_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"
"time"

"github.com/IBM/go-sdk-core/v5/core"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -147,6 +148,27 @@ func ResourceIBMPIInstance() *schema.Resource {
Default: true,
Description: "Indicates if all volumes attached to the server must reside in the same storage pool",
},
Arg_DeploymentTarget: {
Description: "The deployment of a dedicated host.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Attr_ID: {
Description: "The uuid of the host group or host.",
Required: true,
Type: schema.TypeString,
},
Attr_Type: {
Description: "The deployment target type. Supported values are `host` and `hostGroup`.",
Required: true,
Type: schema.TypeString,
ValidateFunc: validate.ValidateAllowedStringValues([]string{Host, HostGroup}),
},
},
},
Optional: true,
MaxItems: 1,
Type: schema.TypeSet,
},
PIInstanceNetwork: {
Type: schema.TypeList,
DiffSuppressFunc: flex.ApplyOnce,
Expand Down Expand Up @@ -1389,7 +1411,9 @@ func createSAPInstance(d *schema.ResourceData, sapClient *st.IBMPISAPInstanceCli
if pg, ok := d.GetOk(helpers.PIPlacementGroupID); ok {
body.PlacementGroup = pg.(string)
}

if deploymentTarget, ok := d.GetOk(Arg_DeploymentTarget); ok {
body.DeploymentTarget = expandDeploymentTarget(deploymentTarget.(*schema.Set).List())
}
pvmList, err := sapClient.Create(body)
if err != nil {
return nil, fmt.Errorf("failed to provision: %v", err)
Expand Down Expand Up @@ -1581,7 +1605,9 @@ func createPVMInstance(d *schema.ResourceData, client *st.IBMPIInstanceClient, i
}
body.SoftwareLicenses = sl
}

if deploymentTarget, ok := d.GetOk(Arg_DeploymentTarget); ok {
body.DeploymentTarget = expandDeploymentTarget(deploymentTarget.(*schema.Set).List())
}
pvmList, err := client.Create(body)

if err != nil {
Expand All @@ -1593,7 +1619,15 @@ func createPVMInstance(d *schema.ResourceData, client *st.IBMPIInstanceClient, i

return pvmList, nil
}

func expandDeploymentTarget(dt []interface{}) *models.DeploymentTarget {
dtexpanded := &models.DeploymentTarget{}
for _, v := range dt {
dtarget := v.(map[string]interface{})
dtexpanded.ID = core.StringPtr(dtarget[Attr_ID].(string))
dtexpanded.Type = core.StringPtr(dtarget[Attr_Type].(string))
}
return dtexpanded
}
func splitID(id string) (id1, id2 string, err error) {
parts, err := flex.IdParts(id)
if err != nil {
Expand Down
40 changes: 39 additions & 1 deletion ibm/service/power/resource_ibm_pi_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,27 @@ func testAccCheckIBMPIInstanceReplicantConfig(name string) string {
`, acc.Pi_cloud_instance_id, name, acc.Pi_image, acc.Pi_network_name, acc.Pi_volume_name)
}

func testAccCheckIBMPIInstanceDeplomentTargetConfig(name string) string {
return fmt.Sprintf(`
resource "ibm_pi_instance" "power_instance" {
pi_cloud_instance_id = "%[1]s"
pi_memory = "2"
pi_processors = "1"
pi_instance_name = "%[2]s"
pi_proc_type = "shared"
pi_image_id = "%[3]s"
pi_sys_type = "s922"
pi_network {
network_id = "%[4]s"
}
pi_deployment_target {
id = "308"
type = "host"
}
}
`, acc.Pi_cloud_instance_id, name, acc.Pi_image, acc.Pi_network_name)
}

func testAccCheckIBMPIInstanceDestroy(s *terraform.State) error {
sess, err := acc.TestAccProvider.Meta().(conns.ClientSession).IBMPISession()
if err != nil {
Expand Down Expand Up @@ -305,7 +326,24 @@ func TestAccIBMPIInstanceBasic(t *testing.T) {
},
})
}

func TestAccIBMPIInstanceDeploymentTarget(t *testing.T) {
instanceRes := "ibm_pi_instance.power_instance"
name := fmt.Sprintf("tf-pi-instance-%d", acctest.RandIntRange(10, 100))
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
CheckDestroy: testAccCheckIBMPIInstanceDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMPIInstanceDeplomentTargetConfig(name),
Check: resource.ComposeTestCheckFunc(
testAccCheckIBMPIInstanceExists(instanceRes),
resource.TestCheckResourceAttr(instanceRes, "pi_instance_name", name),
),
},
},
})
}
func TestAccIBMPIInstanceDeploymentType(t *testing.T) {
instanceRes := "ibm_pi_instance.power_instance"
name := fmt.Sprintf("tf-pi-instance-%d", acctest.RandIntRange(10, 100))
Expand Down
2 changes: 1 addition & 1 deletion ibm/service/power/resource_ibm_pi_shared_processor_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ func resourceIBMPISharedProcessorPoolUpdate(ctx context.Context, d *schema.Resou
}
if d.HasChange(Arg_SharedProcessorPoolReservedCores) {
reservedCores := int64(d.Get(Arg_SharedProcessorPoolReservedCores).(int))
body.ReservedCores = reservedCores
body.ReservedCores = &reservedCores
}

_, err = client.Update(sppID, body)
Expand Down
6 changes: 6 additions & 0 deletions website/docs/r/pi_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ Review the argument references that you can specify for your resource.
- `pi_anti_affinity_instances` - (Optional, String) List of pvmInstances to base storage anti-affinity policy against; required if requesting `anti-affinity` and `pi_anti_affinity_volumes` is not provided.
- `pi_anti_affinity_volumes`- (Optional, String) List of volumes to base storage anti-affinity policy against; required if requesting `anti-affinity` and `pi_anti_affinity_instances` is not provided.
- `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account.
- `pi_deployment_target` - (Optional, List) The deployment of a dedicated host. Max items: 1.

Nested scheme for `pi_deployment_target` :
* `id` - (Required, String) The uuid of the host group or host.
* `type` - (Required, String) The deployment target type. Supported values are `host` and `hostGroup`.

- `pi_deployment_type` - (Optional, String) Custom deployment type; Allowable value: `EPIC` or `VMNoStorage`.
- `pi_health_status` - (Optional, String) Specifies if Terraform should poll for the health status to be `OK` or `WARNING`. The default value is `OK`.

Expand Down
Loading