diff --git a/ibm/acctest/acctest.go b/ibm/acctest/acctest.go index c8262bb3f3..17ff2d09e0 100644 --- a/ibm/acctest/acctest.go +++ b/ibm/acctest/acctest.go @@ -97,6 +97,7 @@ var IksClusterResourceGroupID string // For Power Colo var Pi_image string +var Pi_sap_image string var Pi_image_bucket_name string var Pi_image_bucket_file_name string var Pi_image_bucket_access_key string @@ -518,6 +519,11 @@ func init() { Pi_image = "c93dc4c6-e85a-4da2-9ea6-f24576256122" fmt.Println("[INFO] Set the environment variable PI_IMAGE for testing ibm_pi_image resource else it is set to default value '7200-03-03'") } + Pi_sap_image = os.Getenv("PI_SAP_IMAGE") + if Pi_sap_image == "" { + Pi_sap_image = "2e29d6d2-e5ed-4ff8-8fad-64e4be90e023" + fmt.Println("[INFO] Set the environment variable PI_SAP_IMAGE for testing ibm_pi_image resource else it is set to default value 'Linux-RHEL-SAP-8-2'") + } Pi_image_bucket_name = os.Getenv("PI_IMAGE_BUCKET_NAME") if Pi_image_bucket_name == "" { Pi_image_bucket_name = "images-public-bucket" diff --git a/ibm/service/power/resource_ibm_pi_instance.go b/ibm/service/power/resource_ibm_pi_instance.go index 473ccce909..bf87ca1eaf 100644 --- a/ibm/service/power/resource_ibm_pi_instance.go +++ b/ibm/service/power/resource_ibm_pi_instance.go @@ -220,9 +220,10 @@ func ResourceIBMPIInstance() *schema.Resource { Description: "PIN Policy of the Instance", }, helpers.PIInstanceImageId: { - Type: schema.TypeString, - Required: true, - Description: "PI instance image id", + Type: schema.TypeString, + Required: true, + Description: "PI instance image id", + DiffSuppressFunc: flex.ApplyOnce, }, helpers.PIInstanceProcessors: { Type: schema.TypeFloat, @@ -1095,6 +1096,10 @@ func createSAPInstance(d *schema.ResourceData, sapClient *st.IBMPISAPInstanceCli body.StorageAffinity = affinity } + if pg, ok := d.GetOk(helpers.PIPlacementGroupID); ok { + body.PlacementGroup = pg.(string) + } + pvmList, err := sapClient.Create(body) if err != nil { return nil, fmt.Errorf("failed to provision: %v", err) diff --git a/ibm/service/power/resource_ibm_pi_placement_group_test.go b/ibm/service/power/resource_ibm_pi_placement_group_test.go index ae16d69165..aa2f953bce 100644 --- a/ibm/service/power/resource_ibm_pi_placement_group_test.go +++ b/ibm/service/power/resource_ibm_pi_placement_group_test.go @@ -7,6 +7,7 @@ import ( "context" "errors" "fmt" + "strings" "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" @@ -64,17 +65,20 @@ func TestAccIBMPIPlacementGroupBasic(t *testing.T) { ), }, { - Config: testAccCheckIBMPICreateInstanceInPlacementGroup(name, policy), + Config: testAccCheckIBMPICreateInstanceInPlacementGroup(name, policy, "tinytest-1x4"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet( "ibm_pi_instance.power_instance", "pi_placement_group_id"), resource.TestCheckResourceAttrSet( "ibm_pi_instance.power_instance_in_pg", "pi_placement_group_id"), + resource.TestCheckResourceAttrSet( + "ibm_pi_instance.sap_power_instance", "pi_placement_group_id"), testAccCheckIBMPIPlacementGroupMemberExistsFromInstanceCreate("ibm_pi_placement_group.power_placement_group", "ibm_pi_instance.power_instance", "ibm_pi_instance.power_instance_in_pg"), + testAccCheckIBMPIPlacementGroupMemberExists("ibm_pi_placement_group.power_placement_group", "ibm_pi_instance.sap_power_instance"), ), }, { - Config: testAccCheckIBMPIDeletePlacementGroup(name, policy), + Config: testAccCheckIBMPIDeletePlacementGroup(name, policy, "tinytest-1x4"), Check: resource.ComposeTestCheckFunc( testAccCheckIBMPIPlacementGroupDelete("ibm_pi_placement_group.power_placement_group", "ibm_pi_instance.power_instance", "ibm_pi_instance.power_instance_in_pg"), ), @@ -171,14 +175,20 @@ func testAccCheckIBMPIPlacementGroupMemberExists(n string, instance string) reso if !ok { return fmt.Errorf("Not found: %s", instance) } - instanccParts, err := flex.IdParts(instancers.Primary.ID) + instanceParts, err := flex.IdParts(instancers.Primary.ID) if err != nil { return err } - if instanccParts[1] != pg.Members[0] { - return fmt.Errorf("Expected server ID %s in the PG members field but found %s", instanccParts[1], pg.Members[0]) + var isInstanceFound bool = false + for _, x := range pg.Members { + if x == instanceParts[1] { + isInstanceFound = true + break + } + } + if !isInstanceFound { + return fmt.Errorf("Expected server ID %s in the PG members field but found %s", instanceParts[1], strings.Join(pg.Members[:], ",")) } - return nil } } @@ -357,12 +367,12 @@ func testAccCheckIBMPIPlacementGroupConfig(name string, policy string) string { pi_memory = "2" pi_key_pair_name = ibm_pi_key.key.key_id pi_image_id = "%[4]s" - pi_sys_type = "s922" + pi_sys_type = "e980" pi_instance_name = "%[2]s" pi_cloud_instance_id = "%[1]s" pi_storage_type = "tier3" pi_network { - network_id = "cli-test-private" + network_id = "%[5]s" } } resource "ibm_pi_placement_group" "power_placement_group" { @@ -370,7 +380,7 @@ func testAccCheckIBMPIPlacementGroupConfig(name string, policy string) string { pi_placement_group_name = "%[2]s" pi_placement_group_policy = "%[3]s" } - `, acc.Pi_cloud_instance_id, name, policy, acc.Pi_image) + `, acc.Pi_cloud_instance_id, name, policy, acc.Pi_image, acc.Pi_network_name) } func testAccCheckIBMPIPlacementGroupAddMemberConfig(name string, policy string) string { @@ -387,12 +397,12 @@ func testAccCheckIBMPIPlacementGroupAddMemberConfig(name string, policy string) pi_memory = "2" pi_key_pair_name = ibm_pi_key.key.key_id pi_image_id = "%[4]s" - pi_sys_type = "s922" + pi_sys_type = "e980" pi_instance_name = "%[2]s" pi_cloud_instance_id = "%[1]s" pi_storage_type = "tier3" pi_network { - network_id = "cli-test-private" + network_id = "%[5]s" } pi_placement_group_id = ibm_pi_placement_group.power_placement_group.placement_group_id } @@ -402,7 +412,7 @@ func testAccCheckIBMPIPlacementGroupAddMemberConfig(name string, policy string) pi_placement_group_name = "%[2]s" pi_placement_group_policy = "%[3]s" } - `, acc.Pi_cloud_instance_id, name, policy, acc.Pi_image) + `, acc.Pi_cloud_instance_id, name, policy, acc.Pi_image, acc.Pi_network_name) } func testAccCheckIBMPIPlacementGroupUpdateMemberConfig(name string, policy string) string { @@ -419,12 +429,12 @@ func testAccCheckIBMPIPlacementGroupUpdateMemberConfig(name string, policy strin pi_memory = "2" pi_key_pair_name = ibm_pi_key.key.key_id pi_image_id = "%[4]s" - pi_sys_type = "s922" + pi_sys_type = "e980" pi_instance_name = "%[2]s" pi_cloud_instance_id = "%[1]s" pi_storage_type = "tier3" pi_network { - network_id = "cli-test-private" + network_id = "%[5]s" } pi_placement_group_id = ibm_pi_placement_group.power_placement_group_another.placement_group_id } @@ -440,7 +450,7 @@ func testAccCheckIBMPIPlacementGroupUpdateMemberConfig(name string, policy strin pi_placement_group_name = "%[2]s-2" pi_placement_group_policy = "%[3]s" } - `, acc.Pi_cloud_instance_id, name, policy, acc.Pi_image) + `, acc.Pi_cloud_instance_id, name, policy, acc.Pi_image, acc.Pi_network_name) } func testAccCheckIBMPIPlacementGroupRemoveMemberConfig(name string, policy string) string { @@ -450,19 +460,19 @@ func testAccCheckIBMPIPlacementGroupRemoveMemberConfig(name string, policy strin pi_key_name = "%[2]s" pi_ssh_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDKUt7bk9yLBZFC187bQJFuLaBZONKFYjeIGCZj5mN0OvaJdJqPN2Mbx9Ui42Y5vrLE7SipG5c94BS/fYf7e2LvsQ+xaU1VQnMvP6XS8emoyKR6q/YzD60MkvkSopwTAgpyf6CpfCsKE5Yclbrsc1HIP16bjSgOapfgaVuEDXifn27i1fP1QRYhosY7YkfSKjyJQihxnFH1sONdl4JspJDC5rp8wZ4E7jSXyaZh6QIMbMBEvKoE8+/8CUgT3EWWndIOIMuPQtills3X3jDojTt722OBW1qETPahYDDEmN00R1Q1Q8V8pfVi1XG+ESLzY93gC8hV+/lWIoIvSEazwkfi7/5kludrZG1RhCGbOffGo3DkrmtqaBbKbjrTh/ZbY0GzHPXqccfW/KIhk6xlmoR0wF9LYPtFuzTkqnHF/tHi8EXPHI5XVv9m01kMLkoUqtWVXP2O7ZM7EwrJ+1TyJqLTrzbKMUbn52GqNuTSFJCAgEVc3XrvIRFjTL1/b428mS9JV5kCfRVLmDAUtPjuaQg1wmI/W97gZCF8IoF4JXWTEQP8IIb2opLxvEoBggsZpiFOtjsr9A914i/Tyd4T4KlvfkavJXqkzQoj29oZZPt10gt2ywwXPvV6usM1iofATB+YtX6vl8wUDaqvEyC8d4OTnSVkPZnFxTG3lhY4cDwa/w== tedfordt@us.ibm.com" } - + resource "ibm_pi_instance" "power_instance" { pi_processors = "0.25" pi_proc_type = "shared" pi_memory = "2" pi_key_pair_name = ibm_pi_key.key.key_id pi_image_id = "%[4]s" - pi_sys_type = "s922" + pi_sys_type = "e980" pi_instance_name = "%[2]s" pi_cloud_instance_id = "%[1]s" pi_storage_type = "tier3" pi_network { - network_id = "cli-test-private" + network_id = "%[5]s" } pi_placement_group_id = "" } @@ -478,10 +488,10 @@ func testAccCheckIBMPIPlacementGroupRemoveMemberConfig(name string, policy strin pi_placement_group_name = "%[2]s-2" pi_placement_group_policy = "%[3]s" } - `, acc.Pi_cloud_instance_id, name, policy, acc.Pi_image) + `, acc.Pi_cloud_instance_id, name, policy, acc.Pi_image, acc.Pi_network_name) } -func testAccCheckIBMPICreateInstanceInPlacementGroup(name string, policy string) string { +func testAccCheckIBMPICreateInstanceInPlacementGroup(name string, policy string, sapProfile string) string { return fmt.Sprintf(` resource "ibm_pi_key" "key" { pi_cloud_instance_id = "%[1]s" @@ -495,12 +505,12 @@ func testAccCheckIBMPICreateInstanceInPlacementGroup(name string, policy string) pi_memory = "2" pi_key_pair_name = ibm_pi_key.key.key_id pi_image_id = "%[4]s" - pi_sys_type = "s922" + pi_sys_type = "e980" pi_instance_name = "%[2]s" pi_cloud_instance_id = "%[1]s" pi_storage_type = "tier3" pi_network { - network_id = "cli-test-private" + network_id = "%[7]s" } pi_placement_group_id = ibm_pi_placement_group.power_placement_group.placement_group_id } @@ -511,15 +521,28 @@ func testAccCheckIBMPICreateInstanceInPlacementGroup(name string, policy string) pi_memory = "2" pi_key_pair_name = ibm_pi_key.key.key_id pi_image_id = "%[4]s" - pi_sys_type = "s922" + pi_sys_type = "e980" pi_instance_name = "%[2]s-2" pi_cloud_instance_id = "%[1]s" pi_network { - network_id = "cli-test-private" + network_id = "%[7]s" } pi_placement_group_id = ibm_pi_placement_group.power_placement_group.placement_group_id } + resource "ibm_pi_instance" "sap_power_instance" { + pi_cloud_instance_id = "%[1]s" + pi_instance_name = "sap-%[2]s" + pi_sap_profile_id = "%[5]s" + pi_image_id = "%[6]s" + pi_storage_type = "tier1" + pi_network { + network_id = "%[7]s" + } + pi_placement_group_id = ibm_pi_placement_group.power_placement_group.placement_group_id + depends_on = [ ibm_pi_instance.power_instance_in_pg ] + } + resource "ibm_pi_placement_group" "power_placement_group" { pi_cloud_instance_id = "%[1]s" pi_placement_group_name = "%[2]s" @@ -531,10 +554,10 @@ func testAccCheckIBMPICreateInstanceInPlacementGroup(name string, policy string) pi_placement_group_name = "%[2]s-2" pi_placement_group_policy = "%[3]s" } - `, acc.Pi_cloud_instance_id, name, policy, acc.Pi_image) + `, acc.Pi_cloud_instance_id, name, policy, acc.Pi_image, sapProfile, acc.Pi_sap_image, acc.Pi_network_name) } -func testAccCheckIBMPIDeletePlacementGroup(name string, policy string) string { +func testAccCheckIBMPIDeletePlacementGroup(name string, policy string, sapProfile string) string { return fmt.Sprintf(` resource "ibm_pi_key" "key" { pi_cloud_instance_id = "%[1]s" @@ -548,12 +571,12 @@ func testAccCheckIBMPIDeletePlacementGroup(name string, policy string) string { pi_memory = "2" pi_key_pair_name = ibm_pi_key.key.key_id pi_image_id = "%[4]s" - pi_sys_type = "s922" + pi_sys_type = "e980" pi_instance_name = "%[2]s" pi_cloud_instance_id = "%[1]s" pi_storage_type = "tier3" pi_network { - network_id = "cli-test-private" + network_id = "%[7]s" } } @@ -563,12 +586,24 @@ func testAccCheckIBMPIDeletePlacementGroup(name string, policy string) string { pi_memory = "2" pi_key_pair_name = ibm_pi_key.key.key_id pi_image_id = "%[4]s" - pi_sys_type = "s922" + pi_sys_type = "e980" pi_instance_name = "%[2]s-2" pi_cloud_instance_id = "%[1]s" pi_network { - network_id = "cli-test-private" + network_id = "%[7]s" + } + } + + resource "ibm_pi_instance" "sap_power_instance" { + pi_cloud_instance_id = "%[1]s" + pi_instance_name = "sap-%[2]s" + pi_sap_profile_id = "%[5]s" + pi_image_id = "%[6]s" + pi_storage_type = "tier1" + pi_network { + network_id = "%[7]s" } + depends_on = [ ibm_pi_instance.power_instance_in_pg ] } resource "ibm_pi_placement_group" "power_placement_group_another" { @@ -576,5 +611,5 @@ func testAccCheckIBMPIDeletePlacementGroup(name string, policy string) string { pi_placement_group_name = "%[2]s-2" pi_placement_group_policy = "%[3]s" } - `, acc.Pi_cloud_instance_id, name, policy, acc.Pi_image) + `, acc.Pi_cloud_instance_id, name, policy, acc.Pi_image, sapProfile, acc.Pi_sap_image, acc.Pi_network_name) } diff --git a/website/docs/r/pi_instance.html.markdown b/website/docs/r/pi_instance.html.markdown index 8f8ec7f752..d936de5946 100644 --- a/website/docs/r/pi_instance.html.markdown +++ b/website/docs/r/pi_instance.html.markdown @@ -78,13 +78,13 @@ Review the argument references that you can specify for your resource. - `network_id` - (String) The network ID to assign to the instance. - `ip_address` - (String) The ip address to be used of this network. - `pi_pin_policy` - (Optional, String) Select the pinning policy for your Power Systems Virtual Server instance. Supported values are `soft`, `hard`, and `none`. **Note** You can choose to soft pin (`soft`) or hard pin (`hard`) a virtual server to the physical host where it runs. When you soft pin an instance for high availability, the instance automatically migrates back to the original host once the host is back to its operating state. If the instance has a licensing restriction with the host, the hard pin option restricts the movement of the instance during remote restart, automated remote restart, DRO, and live partition migration. The default pinning policy is `none`. -- `pi_placement_group_id`- (Optional, String) The ID of the placement group that the instance is in if any or empty quotes `""` to also indicate it is not in a placement group. +- `pi_placement_group_id` - (Optional, String) The ID of the placement group that the instance is in or empty quotes `""` to indicate it is not in a placement group. The meta-argument `count` and a `pi_replicants` cannot be used when specifying a placement group ID. Instances provisioning in the same placement group must be provisioned one at a time; however, to provision multiple instances on the same host or different hosts then use `pi_replicants` and `pi_replication_policy` instead of `pi_placement_group_id`. - `pi_processors` - (Optional, Float) The number of vCPUs to assign to the VM as visible within the guest Operating System. - Required when not creating SAP instances. Conflicts with `pi_sap_profile_id`. - `pi_proc_type` - (Optional, String) The type of processor mode in which the VM will run with `shared`, `capped` or `dedicated`. - Required when not creating SAP instances. Conflicts with `pi_sap_profile_id`. - `pi_replicants` - (Optional, Integer) The number of instances that you want to provision with the same configuration. If this parameter is not set, `1` is used by default. -- `pi_replication_policy` - (Optional, String) The replication policy that you want to use. If this parameter is not set, `none` is used by default. +- `pi_replication_policy` - (Optional, String) The replication policy that you want to use, either `affinity`, `anti-affinity` or `none`. If this parameter is not set, `none` is used by default. - `pi_replication_scheme` - (Optional, String) The replication scheme that you want to set, either `prefix` or `suffix`. - `pi_sap_profile_id` - (Optional, String) SAP Profile ID for the amount of cores and memory. - Required only when creating SAP instances.