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

Add code to allow SAP create with a placement group #3633

Merged
merged 1 commit into from
Mar 14, 2022
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
6 changes: 6 additions & 0 deletions ibm/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
11 changes: 8 additions & 3 deletions ibm/service/power/resource_ibm_pi_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the diff suprress func applied ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hkantare when using a stock image the result image id from the pvm instance depends on the storage controller used to deploy the image. Here user provided configuration is not always same as the instance image id. Terraform would always show a diff to be applied which was also failing the test cases at some places depending on the storage controller selected automatically by the service provider.

},
helpers.PIInstanceProcessors: {
Type: schema.TypeFloat,
Expand Down Expand Up @@ -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)
Expand Down
97 changes: 66 additions & 31 deletions ibm/service/power/resource_ibm_pi_placement_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"errors"
"fmt"
"strings"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
Expand Down Expand Up @@ -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"),
),
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -357,20 +367,20 @@ 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" {
pi_cloud_instance_id = "%[1]s"
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 {
Expand All @@ -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
}
Expand All @@ -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 {
Expand All @@ -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
}
Expand All @@ -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 {
Expand All @@ -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 = ""
}
Expand All @@ -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"
Expand All @@ -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
}
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
}
}

Expand All @@ -563,18 +586,30 @@ 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" {
pi_cloud_instance_id = "%[1]s"
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)
}
4 changes: 2 additions & 2 deletions website/docs/r/pi_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down