Skip to content

Commit

Permalink
Add GRS (#5665)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Kita authored Oct 11, 2024
1 parent 9928c93 commit bba26b8
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ibm/service/power/ibm_pi_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const (
Arg_AffinityVolume = "pi_affinity_volume"
Arg_AntiAffinityInstances = "pi_anti_affinity_instances"
Arg_AntiAffinityVolumes = "pi_anti_affinity_volumes"
Arg_BootVolumeReplicationEnabled = "pi_boot_volume_replication_enabled"
Arg_Cidr = "pi_cidr"
Arg_CloudConnectionID = "pi_cloud_connection_id"
Arg_CloudConnectionName = "pi_cloud_connection_name"
Expand Down Expand Up @@ -63,9 +64,9 @@ const (
Arg_Remove = "pi_remove"
Arg_Replicants = "pi_replicants"
Arg_ReplicationEnabled = "pi_replication_enabled"
Arg_ReplicationSites = "pi_replication_sites"
Arg_ReplicationPolicy = "pi_replication_policy"
Arg_ReplicationScheme = "pi_replication_scheme"
Arg_ReplicationSites = "pi_replication_sites"
Arg_ResourceGroupID = "pi_resource_group_id"
Arg_SAP = "sap"
Arg_SAPDeploymentType = "pi_sap_deployment_type"
Expand Down
43 changes: 43 additions & 0 deletions ibm/service/power/resource_ibm_pi_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ func ResourceIBMPIInstance() *schema.Resource {
Optional: true,
Type: schema.TypeList,
},
Arg_BootVolumeReplicationEnabled: {
Description: "Indicates if the boot volume should be replication enabled or not.",
ForceNew: true,
Optional: true,
Type: schema.TypeBool,
},
Arg_CloudInstanceID: {
Description: "This is the Power Instance id that is assigned to the account",
ForceNew: true,
Expand Down Expand Up @@ -244,6 +250,14 @@ func ResourceIBMPIInstance() *schema.Resource {
Type: schema.TypeString,
ValidateFunc: validate.ValidateAllowedStringValues([]string{Prefix, Suffix}),
},
Arg_ReplicationSites: {
Description: "Indicates the replication sites of the boot volume.",
Elem: &schema.Schema{Type: schema.TypeString},
ForceNew: true,
Optional: true,
Set: schema.HashString,
Type: schema.TypeSet,
},
Arg_SAPProfileID: {
ConflictsWith: []string{Arg_Processors, Arg_Memory, Arg_ProcType},
Description: "SAP Profile ID for the amount of cores and memory",
Expand Down Expand Up @@ -1422,6 +1436,20 @@ func createSAPInstance(d *schema.ResourceData, sapClient *instance.IBMPISAPInsta
if st, ok := d.GetOk(Arg_StorageType); ok {
body.StorageType = st.(string)
}
var bootVolumeReplicationEnabled bool
if bootVolumeReplicationBoolean, ok := d.GetOk(Arg_BootVolumeReplicationEnabled); ok {
bootVolumeReplicationEnabled = bootVolumeReplicationBoolean.(bool)
body.BootVolumeReplicationEnabled = &bootVolumeReplicationEnabled
}
var replicationSites []string
if sites, ok := d.GetOk(Arg_ReplicationSites); ok {
if !bootVolumeReplicationEnabled {
return nil, fmt.Errorf("must set %s to true in order to specify replication sites", Arg_BootVolumeReplicationEnabled)
} else {
replicationSites = flex.FlattenSet(sites.(*schema.Set))
body.ReplicationSites = replicationSites
}
}
if sp, ok := d.GetOk(Arg_StoragePool); ok {
body.StoragePool = sp.(string)
}
Expand Down Expand Up @@ -1657,6 +1685,21 @@ func createPVMInstance(d *schema.ResourceData, client *instance.IBMPIInstanceCli
if deploymentTarget, ok := d.GetOk(Arg_DeploymentTarget); ok {
body.DeploymentTarget = expandDeploymentTarget(deploymentTarget.(*schema.Set).List())
}
var bootVolumeReplicationEnabled bool
if bootVolumeReplicationBoolean, ok := d.GetOk(Arg_BootVolumeReplicationEnabled); ok {
bootVolumeReplicationEnabled = bootVolumeReplicationBoolean.(bool)
body.BootVolumeReplicationEnabled = &bootVolumeReplicationEnabled
}
var replicationSites []string
if sites, ok := d.GetOk(Arg_ReplicationSites); ok {
if !bootVolumeReplicationEnabled {
return nil, fmt.Errorf("must set %s to true in order to specify replication sites", Arg_BootVolumeReplicationEnabled)
} else {
replicationSites = flex.FlattenSet(sites.(*schema.Set))
body.ReplicationSites = replicationSites
}
}

if tags, ok := d.GetOk(Arg_UserTags); ok {
body.UserTags = flex.FlattenSet(tags.(*schema.Set))
}
Expand Down
58 changes: 58 additions & 0 deletions ibm/service/power/resource_ibm_pi_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,64 @@ func TestAccIBMPIInstanceDeploymentTypeNoStorage(t *testing.T) {
})
}

func TestAccIBMPIInstanceDeploymentGRS(t *testing.T) {
instanceRes := "ibm_pi_instance.power_instance"
bootVolumeData := "data.ibm_pi_volume.power_boot_volume_data"
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: testAccIBMPIInstanceGRSConfig(name, power.OK, "2", "0.25"),
Check: resource.ComposeTestCheckFunc(
testAccCheckIBMPIInstanceExists(instanceRes),
resource.TestCheckResourceAttr(instanceRes, "pi_instance_name", name),
resource.TestCheckResourceAttr(bootVolumeData, "replication_enabled", "true"),
),
},
},
})
}

func testAccIBMPIInstanceGRSConfig(name string, instanceHealthStatus string, memory string, proc string) string {
return fmt.Sprintf(`
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"
}
data "ibm_pi_volume" "power_boot_volume_data" {
pi_cloud_instance_id = "%[1]s"
pi_volume_name = data.ibm_pi_instance_volumes.power_instance_volumes_data.instance_volumes[0].name
}
data "ibm_pi_instance_volumes" "power_instance_volumes_data" {
pi_cloud_instance_id = "%[1]s"
pi_instance_name = ibm_pi_instance.power_instance.pi_instance_name
}
resource "ibm_pi_instance" "power_instance" {
pi_boot_volume_replication_enabled = true
pi_memory = "%[7]s"
pi_processors = "%[6]s"
pi_instance_name = "%[2]s"
pi_proc_type = "shared"
pi_image_id = data.ibm_pi_image.power_image.id
pi_sys_type = "e980"
pi_cloud_instance_id = "%[1]s"
pi_storage_pool = data.ibm_pi_image.power_image.storage_pool
pi_pin_policy = "none"
pi_health_status = "%[5]s"
pi_network {
network_id = data.ibm_pi_network.power_networks.id
}
}
`, acc.Pi_cloud_instance_id, name, acc.Pi_image, acc.Pi_network_name, instanceHealthStatus, proc, memory)
}

func TestAccIBMPIInstanceUserTags(t *testing.T) {
instanceRes := "ibm_pi_instance.power_instance"
name := fmt.Sprintf("tf-pi-instance-%d", acctest.RandIntRange(10, 100))
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/pi_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Review the argument references that you can specify for your resource.
- `pi_affinity_volume`- (Optional, String) Volume (ID or Name) to base storage affinity policy against; required if requesting `affinity` and `pi_affinity_instance` is not provided.
- `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_boot_volume_replication_enabled` - (Optional, Boolean) Indicates if the boot volume should be replication enabled or not.
- `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.

Expand Down Expand Up @@ -106,6 +107,7 @@ Review the argument references that you can specify for your resource.
- `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, 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_replication_sites` - (Optional, List) Indicates the replication sites of the boot volume.
- `pi_sap_profile_id` - (Optional, String) SAP Profile ID for the amount of cores and memory.
- Required only when creating SAP instances.
- `pi_sap_deployment_type` - (Optional, String) Custom SAP deployment type information (For Internal Use Only).
Expand Down

0 comments on commit bba26b8

Please sign in to comment.