Skip to content

Commit

Permalink
Terraform Support for EPIC offering Create flow (IBM-Cloud#3949)
Browse files Browse the repository at this point in the history
* Terraform Support for EPIC offering Create flow

* New Test Case for EPIC
  • Loading branch information
bhagyagkwd authored and SunithaGudisagarIBM1 committed Sep 14, 2022
1 parent b33774a commit 470307d
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
1 change: 1 addition & 0 deletions ibm/service/power/ibm_pi_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const (
activeTimeOut = 2 * time.Minute
// power service instance capabilities
CUSTOM_VIRTUAL_CORES = "custom-virtualcores"
PIInstanceDeploymentType = "pi_deployment_type"
PIInstanceNetwork = "pi_network"
PIInstanceStoragePool = "pi_storage_pool"
PISAPInstanceProfileID = "pi_sap_profile_id"
Expand Down
9 changes: 9 additions & 0 deletions ibm/service/power/resource_ibm_pi_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ func ResourceIBMPIInstance() *schema.Resource {
ConflictsWith: []string{PISAPInstanceProfileID},
Description: "Memory size",
},
PIInstanceDeploymentType: {
Type: schema.TypeString,
Optional: true,
Description: "Custom Deployment Type Information",
},
PISAPInstanceProfileID: {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -1222,6 +1227,10 @@ func createPVMInstance(d *schema.ResourceData, client *st.IBMPIInstanceClient, i
body.StoragePool = sp.(string)
}

if dt, ok := d.GetOk(PIInstanceDeploymentType); ok {
body.DeploymentType = dt.(string)
}

if ap, ok := d.GetOk(PIAffinityPolicy); ok {
policy := ap.(string)
affinity := &models.StorageAffinity{
Expand Down
53 changes: 53 additions & 0 deletions ibm/service/power/resource_ibm_pi_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,40 @@ func testAccCheckIBMPIInstanceConfig(name, instanceHealthStatus string) string {
`, acc.Pi_cloud_instance_id, name, acc.Pi_image, acc.Pi_network_name, instanceHealthStatus)
}

func testAccCheckIBMPIInstanceDeploymentTypeConfig(name, instanceHealthStatus string) string {
return fmt.Sprintf(`
resource "ibm_pi_key" "key" {
pi_cloud_instance_id = "%[1]s"
pi_key_name = "%[2]s"
pi_ssh_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVERRN7/9484SOBJ3HSKxxNG5JN8owAjy5f9yYwcUg+JaUVuytn5Pv3aeYROHGGg+5G346xaq3DAwX6Y5ykr2fvjObgncQBnuU5KHWCECO/4h8uWuwh/kfniXPVjFToc+gnkqA+3RKpAecZhFXwfalQ9mMuYGFxn+fwn8cYEApsJbsEmb0iJwPiZ5hjFC8wREuiTlhPHDgkBLOiycd20op2nXzDbHfCHInquEe/gYxEitALONxm0swBOwJZwlTDOB7C6y2dzlrtxr1L59m7pCkWI4EtTRLvleehBoj3u7jB4usR"
}
data "ibm_pi_image" "power_image" {
pi_image_name = "%[3]s"
pi_cloud_instance_id = "%[1]s"
}
data "ibm_pi_network" "power_networks" {
pi_cloud_instance_id = "%[1]s"
pi_network_name = "%[4]s"
}
resource "ibm_pi_instance" "power_instance" {
pi_memory = "2"
pi_processors = "1"
pi_instance_name = "%[2]s"
pi_proc_type = "dedicated"
pi_image_id = data.ibm_pi_image.power_image.id
pi_key_pair_name = ibm_pi_key.key.key_id
pi_sys_type = "e980"
pi_cloud_instance_id = "%[1]s"
pi_storage_type = "tier1"
pi_health_status = "%[5]s"
pi_network {
network_id = data.ibm_pi_network.power_networks.id
}
pi_deployment_type = "EPIC"
}
`, acc.Pi_cloud_instance_id, name, acc.Pi_image, acc.Pi_network_name, instanceHealthStatus)
}

func testAccIBMPIInstanceNetworkConfig(name, privateNetIP string) string {
return fmt.Sprintf(`
resource "ibm_pi_key" "key" {
Expand Down Expand Up @@ -191,6 +225,25 @@ func TestAccIBMPIInstanceBasic(t *testing.T) {
})
}

func TestAccIBMPIInstanceDeploymentType(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: testAccCheckIBMPIInstanceDeploymentTypeConfig(name, helpers.PIInstanceHealthWarning),
Check: resource.ComposeTestCheckFunc(
testAccCheckIBMPIInstanceExists(instanceRes),
resource.TestCheckResourceAttr(instanceRes, "pi_instance_name", name),
),
},
},
})
}

func TestAccIBMPIInstanceNetwork(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 website/docs/r/pi_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ 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_type` - (Optional, String) Custom deployment type information (For Internal Use Only).
- `pi_health_status` - (Optional, String) Specifies if Terraform should poll for the health status to be `OK` or `WARNING`. The default value is `OK`.
- `pi_image_id` - (Required, String) The ID of the image that you want to use for your Power Systems Virtual Server instance. The image determines the operating system that is installed in your instance. To list available images, run the `ibmcloud pi images` command.
- `pi_instance_name` - (Required, String) The name of the Power Systems Virtual Server instance.
Expand Down Expand Up @@ -99,7 +100,6 @@ Review the argument references that you can specify for your resource.
- `pi_user_data` - (Optional, String) The base64 encoded form of the user data `cloud-init` to pass to the instance during creation.
- `pi_virtual_cores_assigned` - (Optional, Integer) Specify the number of virtual cores to be assigned.
- `pi_volume_ids` - (Optional, List of String) The list of volume IDs that you want to attach to the instance during creation.

## Attribute reference
In addition to all argument reference list, you can access the following attribute reference after your resource is created.

Expand Down

0 comments on commit 470307d

Please sign in to comment.