diff --git a/go.mod b/go.mod index 51eab17d82..34261cf23c 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ toolchain go1.23.4 require ( github.com/IBM-Cloud/bluemix-go v0.0.0-20241117121028-a3be206688b3 github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113 - github.com/IBM-Cloud/power-go-client v1.9.0 + github.com/IBM-Cloud/power-go-client v1.10.0-beta7 github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca github.com/IBM/appconfiguration-go-admin-sdk v0.4.4 github.com/IBM/appid-management-go-sdk v0.0.0-20210908164609-dd0e0eaf732f diff --git a/go.sum b/go.sum index f94b2c321d..cda34c5166 100644 --- a/go.sum +++ b/go.sum @@ -95,8 +95,8 @@ github.com/IBM-Cloud/bluemix-go v0.0.0-20241117121028-a3be206688b3/go.mod h1:/7h github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113 h1:f2Erqfea1dKpaTFagTJM6W/wnD3JGq/Vn9URh8nuRwk= github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113/go.mod h1:xUQL9SGAjoZFd4GNjrjjtEpjpkgU7RFXRyHesbKTjiY= github.com/IBM-Cloud/ibm-cloud-cli-sdk v0.5.3/go.mod h1:RiUvKuHKTBmBApDMUQzBL14pQUGKcx/IioKQPIcRQjs= -github.com/IBM-Cloud/power-go-client v1.9.0 h1:nnErpb/7TJQe8P7OfIlJPhSJVq5oyuCJlMje9Ry6XEY= -github.com/IBM-Cloud/power-go-client v1.9.0/go.mod h1:UDyXeIKEp6r7yWUXYu3r0ZnFSlNZ2YeQTHwM2Tmlgv0= +github.com/IBM-Cloud/power-go-client v1.10.0-beta7 h1:nxAuY/0axYwOq2jb2jVZqu3nmPP/7/sFC6HCi8RhMUA= +github.com/IBM-Cloud/power-go-client v1.10.0-beta7/go.mod h1:UDyXeIKEp6r7yWUXYu3r0ZnFSlNZ2YeQTHwM2Tmlgv0= github.com/IBM-Cloud/softlayer-go v1.0.5-tf h1:koUAyF9b6X78lLLruGYPSOmrfY2YcGYKOj/Ug9nbKNw= github.com/IBM-Cloud/softlayer-go v1.0.5-tf/go.mod h1:6HepcfAXROz0Rf63krk5hPZyHT6qyx2MNvYyHof7ik4= github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca h1:crniVcf+YcmgF03NmmfonXwSQ73oJF+IohFYBwknMxs= diff --git a/ibm/service/power/data_source_ibm_pi_instance.go b/ibm/service/power/data_source_ibm_pi_instance.go index bb2f9b4e78..3edd9eb061 100644 --- a/ibm/service/power/data_source_ibm_pi_instance.go +++ b/ibm/service/power/data_source_ibm_pi_instance.go @@ -39,6 +39,11 @@ func DataSourceIBMPIInstance() *schema.Resource { Description: "The CRN of this resource.", Type: schema.TypeString, }, + Attr_DedicatedHostID: { + Computed: true, + Description: "The dedicated host ID where the shared processor pool resides.", + Type: schema.TypeString, + }, Attr_DeploymentType: { Computed: true, Description: "The custom deployment type.", @@ -285,6 +290,7 @@ func dataSourceIBMPIInstancesRead(ctx context.Context, d *schema.ResourceData, m } d.Set(Attr_UserTags, tags) } + d.Set(Attr_DedicatedHostID, powervmdata.DedicatedHostID) d.Set(Attr_DeploymentType, powervmdata.DeploymentType) d.Set(Attr_LicenseRepositoryCapacity, powervmdata.LicenseRepositoryCapacity) d.Set(Attr_MaxMem, powervmdata.Maxmem) diff --git a/ibm/service/power/data_source_ibm_pi_instances.go b/ibm/service/power/data_source_ibm_pi_instances.go index 3eaf053446..d414260942 100644 --- a/ibm/service/power/data_source_ibm_pi_instances.go +++ b/ibm/service/power/data_source_ibm_pi_instances.go @@ -41,6 +41,11 @@ func DataSourceIBMPIInstances() *schema.Resource { Description: "The CRN of this resource.", Type: schema.TypeString, }, + Attr_DedicatedHostID: { + Computed: true, + Description: "The dedicated host ID where the shared processor pool resides.", + Type: schema.TypeString, + }, Attr_Fault: { Computed: true, Description: "Fault information.", @@ -267,6 +272,7 @@ func flattenPvmInstances(list []*models.PVMInstanceReference, meta interface{}) result := make([]map[string]interface{}, 0, len(list)) for _, i := range list { l := map[string]interface{}{ + Attr_DedicatedHostID: i.DedicatedHostID, Attr_LicenseRepositoryCapacity: i.LicenseRepositoryCapacity, Attr_MaxMem: i.Maxmem, Attr_MaxProc: i.Maxproc, diff --git a/ibm/service/power/ibm_pi_constants.go b/ibm/service/power/ibm_pi_constants.go index 4c93778d71..93f6d49cb5 100644 --- a/ibm/service/power/ibm_pi_constants.go +++ b/ibm/service/power/ibm_pi_constants.go @@ -216,6 +216,7 @@ const ( Attr_DatacenterStatus = "pi_datacenter_status" Attr_DatacenterType = "pi_datacenter_type" Attr_Dedicated = "dedicated" + Attr_DedicatedHostID = "dedicated_host_id" Attr_Default = "default" Attr_DeleteOnTermination = "delete_on_termination" Attr_DeploymentType = "deployment_type" diff --git a/ibm/service/power/resource_ibm_pi_instance.go b/ibm/service/power/resource_ibm_pi_instance.go index e5e6deab8f..7fea2c65d6 100644 --- a/ibm/service/power/resource_ibm_pi_instance.go +++ b/ibm/service/power/resource_ibm_pi_instance.go @@ -383,6 +383,16 @@ func ResourceIBMPIInstance() *schema.Resource { Description: "The CRN of this resource.", Type: schema.TypeString, }, + Attr_DedicatedHostID: { + Computed: true, + Description: "The dedicated host ID where the shared processor pool resides.", + Type: schema.TypeString, + }, + Attr_Fault: { + Computed: true, + Description: "Fault information.", + Type: schema.TypeMap, + }, Attr_HealthStatus: { Computed: true, Description: "PI Instance health status", @@ -460,11 +470,6 @@ func ResourceIBMPIInstance() *schema.Resource { Description: "PI instance status", Type: schema.TypeString, }, - Attr_Fault: { - Computed: true, - Description: "Fault information.", - Type: schema.TypeMap, - }, }, } } @@ -598,18 +603,15 @@ func resourceIBMPIInstanceRead(ctx context.Context, d *schema.ResourceData, meta if powervmdata.Status != nil { d.Set(Attr_Status, powervmdata.Status) } + d.Set(Arg_CloudInstanceID, cloudInstanceID) + d.Set(Arg_ImageID, powervmdata.ImageID) + d.Set(Arg_InstanceName, powervmdata.ServerName) d.Set(Arg_ProcType, powervmdata.ProcType) - d.Set(Attr_MinProcessors, powervmdata.Minproc) - d.Set(Attr_Progress, powervmdata.Progress) - if powervmdata.StorageType != nil && *powervmdata.StorageType != "" { - d.Set(Arg_StorageType, powervmdata.StorageType) - } d.Set(Arg_StoragePool, powervmdata.StoragePool) d.Set(Arg_StoragePoolAffinity, powervmdata.StoragePoolAffinity) - d.Set(Arg_CloudInstanceID, cloudInstanceID) d.Set(Attr_InstanceID, powervmdata.PvmInstanceID) - d.Set(Arg_InstanceName, powervmdata.ServerName) - d.Set(Arg_ImageID, powervmdata.ImageID) + d.Set(Attr_MinProcessors, powervmdata.Minproc) + d.Set(Attr_Progress, powervmdata.Progress) if *powervmdata.PlacementGroup != None { d.Set(Arg_PlacementGroupID, powervmdata.PlacementGroup) } @@ -638,6 +640,7 @@ func resourceIBMPIInstanceRead(ctx context.Context, d *schema.ResourceData, meta d.Set(Arg_SAPProfileID, powervmdata.SapProfile.ProfileID) } d.Set(Arg_SysType, powervmdata.SysType) + d.Set(Attr_DedicatedHostID, powervmdata.DedicatedHostID) d.Set(Attr_MinMemory, powervmdata.Minmem) d.Set(Attr_MaxProcessors, powervmdata.Maxproc) d.Set(Attr_MaxMemory, powervmdata.Maxmem) @@ -653,8 +656,8 @@ func resourceIBMPIInstanceRead(ctx context.Context, d *schema.ResourceData, meta d.Set(Attr_MaxVirtualCores, powervmdata.VirtualCores.Max) d.Set(Attr_MinVirtualCores, powervmdata.VirtualCores.Min) } - d.Set(Arg_LicenseRepositoryCapacity, powervmdata.LicenseRepositoryCapacity) d.Set(Arg_DeploymentType, powervmdata.DeploymentType) + d.Set(Arg_LicenseRepositoryCapacity, powervmdata.LicenseRepositoryCapacity) if powervmdata.SoftwareLicenses != nil { d.Set(Arg_IBMiCSS, powervmdata.SoftwareLicenses.IbmiCSS) d.Set(Arg_IBMiPHA, powervmdata.SoftwareLicenses.IbmiPHA) @@ -681,7 +684,6 @@ func resourceIBMPIInstanceRead(ctx context.Context, d *schema.ResourceData, meta } func resourceIBMPIInstanceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - name := d.Get(Arg_InstanceName).(string) mem := d.Get(Arg_Memory).(float64) procs := d.Get(Arg_Processors).(float64) @@ -1531,7 +1533,6 @@ func checkCloudInstanceCapability(cloudInstance *models.CloudInstance, custom_ca } func createSAPInstance(d *schema.ResourceData, sapClient *instance.IBMPISAPInstanceClient) (*models.PVMInstanceList, error) { - name := d.Get(Arg_InstanceName).(string) profileID := d.Get(Arg_SAPProfileID).(string) imageid := d.Get(Arg_ImageID).(string) @@ -1727,7 +1728,7 @@ func createPVMInstance(d *schema.ResourceData, client *instance.IBMPIInstanceCli SysType: systype, ImageID: flex.PtrToString(imageid), ProcType: flex.PtrToString(processortype), - Replicants: replicants, + Replicants: &replicants, UserData: encodeBase64(userData), ReplicantNamingScheme: flex.PtrToString(replicationNamingScheme), ReplicantAffinityPolicy: flex.PtrToString(replicationpolicy), @@ -1864,7 +1865,7 @@ func createPVMInstance(d *schema.ResourceData, client *instance.IBMPIInstanceCli } if vsn, ok := d.GetOk(Arg_VirtualSerialNumber); ok { vsnListType := vsn.([]interface{}) - vsnCreateModel := vsnSetToCreateModel(vsnListType, d) + vsnCreateModel := vsnSetToCreateModel(vsnListType) body.VirtualSerialNumber = vsnCreateModel } @@ -1879,6 +1880,7 @@ func createPVMInstance(d *schema.ResourceData, client *instance.IBMPIInstanceCli return pvmList, nil } + func expandDeploymentTarget(dt []interface{}) *models.DeploymentTarget { dtexpanded := &models.DeploymentTarget{} for _, v := range dt { @@ -1888,6 +1890,7 @@ func expandDeploymentTarget(dt []interface{}) *models.DeploymentTarget { } return dtexpanded } + func splitID(id string) (id1, id2 string, err error) { parts, err := flex.IdParts(id) if err != nil { @@ -1897,7 +1900,8 @@ func splitID(id string) (id1, id2 string, err error) { id2 = parts[1] return } -func vsnSetToCreateModel(vsnSetList []interface{}, d *schema.ResourceData) *models.CreateServerVirtualSerialNumber { + +func vsnSetToCreateModel(vsnSetList []interface{}) *models.CreateServerVirtualSerialNumber { vsnItemMap := vsnSetList[0].(map[string]interface{}) serialString := vsnItemMap[Attr_Serial].(string) model := &models.CreateServerVirtualSerialNumber{ @@ -1910,6 +1914,7 @@ func vsnSetToCreateModel(vsnSetList []interface{}, d *schema.ResourceData) *mode return model } + func flattenVirtualSerialNumberToList(vsn *models.GetServerVirtualSerialNumber) []map[string]interface{} { v := make([]map[string]interface{}, 1) v[0] = map[string]interface{}{ diff --git a/ibm/service/power/resource_ibm_pi_instance_test.go b/ibm/service/power/resource_ibm_pi_instance_test.go index 73a65937c7..d45801d0e2 100644 --- a/ibm/service/power/resource_ibm_pi_instance_test.go +++ b/ibm/service/power/resource_ibm_pi_instance_test.go @@ -23,6 +23,25 @@ import ( st "github.com/IBM-Cloud/power-go-client/clients/instance" ) +func TestAccIBMPIInstanceBasic(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: testAccCheckIBMPIInstanceConfig(name, power.OK), + Check: resource.ComposeTestCheckFunc( + testAccCheckIBMPIInstanceExists(instanceRes), + resource.TestCheckResourceAttr(instanceRes, "pi_instance_name", name), + ), + }, + }, + }) +} + func testAccCheckIBMPIInstanceConfig(name, instanceHealthStatus string) string { return fmt.Sprintf(` resource "ibm_pi_key" "key" { @@ -66,236 +85,24 @@ func testAccCheckIBMPIInstanceConfig(name, instanceHealthStatus string) string { `, acc.Pi_cloud_instance_id, name, acc.Pi_image, acc.Pi_network_name, instanceHealthStatus, acc.PiStorageType) } -func testAccCheckIBMPIInstanceDeploymentTypeConfig(name, instanceHealthStatus, epic, systype 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_cloud_instance_id = "%[1]s" - pi_image_name = "%[3]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_cloud_instance_id = "%[1]s" - pi_deployment_type = "%[6]s" - pi_health_status = "%[5]s" - pi_image_id = data.ibm_pi_image.power_image.id - pi_instance_name = "%[2]s" - pi_key_pair_name = ibm_pi_key.key.name - pi_memory = "2" - pi_proc_type = "dedicated" - pi_processors = "1" - pi_storage_type = "%[8]s" - pi_sys_type = "%[7]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, epic, systype, acc.PiStorageType) -} - -func testAccCheckIBMPIInstanceIBMiLicense(name, instanceHealthStatus string, IBMiCSS bool, IBMiRDSUsers int) string { - return fmt.Sprintf(` - data "ibm_pi_image" "power_image" { - pi_cloud_instance_id = "%[1]s" - pi_image_name = "%[3]s" - } - data "ibm_pi_network" "power_networks" { - pi_cloud_instance_id = "%[1]s" - pi_network_name = "%[4]s" - } - resource "ibm_pi_volume" "power_volume" { - pi_cloud_instance_id = "%[1]s" - pi_volume_name = "%[2]s" - pi_volume_size = 1 - pi_volume_type = "tier3" - } - resource "ibm_pi_instance" "power_instance" { - pi_cloud_instance_id = "%[1]s" - pi_health_status = "%[5]s" - pi_ibmi_css = %[6]t - pi_ibmi_rds_users = %[7]d - pi_image_id = data.ibm_pi_image.power_image.id - pi_instance_name = "%[2]s" - pi_memory = "2" - pi_proc_type = "shared" - pi_processors = "0.25" - pi_storage_pool = data.ibm_pi_image.power_image.storage_pool - pi_sys_type = "s922" - pi_volume_ids = [ibm_pi_volume.power_volume.volume_id] - 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, IBMiCSS, IBMiRDSUsers) -} - -func testAccIBMPIInstanceNetworkConfig(name, privateNetIP 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 AAAAB3NzaC1yc2EAAAABJQAAAQEArb2aK0mekAdbYdY9rwcmeNSxqVCwez3WZTYEq+1Nwju0x5/vQFPSD2Kp9LpKBbxx3OVLN4VffgGUJznz9DAr7veLkWaf3iwEil6U4rdrhBo32TuDtoBwiczkZ9gn1uJzfIaCJAJdnO80Kv9k0smbQFq5CSb9H+F5VGyFue/iVd5/b30MLYFAz6Jg1GGWgw8yzA4Gq+nO7HtyuA2FnvXdNA3yK/NmrTiPCdJAtEPZkGu9LcelkQ8y90ArlKfjtfzGzYDE4WhOufFxyWxciUePh425J2eZvElnXSdGha+FCfYjQcvqpCVoBAG70U4fJBGjB+HL/GpCXLyiYXPrSnzC9w==" - } - resource "ibm_pi_network" "power_networks" { - pi_cidr = "192.168.17.0/24" - pi_cloud_instance_id = "%[1]s" - pi_dns = ["127.0.0.1"] - pi_gateway = "192.168.17.2" - pi_network_name = "%[2]s" - pi_network_type = "vlan" - pi_ipaddress_range { - pi_ending_ip_address = "192.168.17.254" - pi_starting_ip_address = "192.168.17.3" - } - } - resource "ibm_pi_instance" "power_instance" { - pi_cloud_instance_id = "%[1]s" - pi_image_id = "%[4]s" - pi_instance_name = "%[2]s" - pi_key_pair_name = ibm_pi_key.key.name - pi_memory = "2" - pi_proc_type = "shared" - pi_processors = "0.25" - pi_storage_type = "tier3" - pi_sys_type = "s922" - pi_network { - network_id = resource.ibm_pi_network.power_networks.network_id - ip_address = "%[3]s" - } - } - `, acc.Pi_cloud_instance_id, name, privateNetIP, acc.Pi_image) -} - -func testAccIBMPIInstanceVTLConfig(name string) string { - return fmt.Sprintf(` - resource "ibm_pi_key" "vtl_key" { - pi_cloud_instance_id = "%[1]s" - pi_key_name = "%[2]s" - pi_ssh_key = "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEArb2aK0mekAdbYdY9rwcmeNSxqVCwez3WZTYEq+1Nwju0x5/vQFPSD2Kp9LpKBbxx3OVLN4VffgGUJznz9DAr7veLkWaf3iwEil6U4rdrhBo32TuDtoBwiczkZ9gn1uJzfIaCJAJdnO80Kv9k0smbQFq5CSb9H+F5VGyFue/iVd5/b30MLYFAz6Jg1GGWgw8yzA4Gq+nO7HtyuA2FnvXdNA3yK/NmrTiPCdJAtEPZkGu9LcelkQ8y90ArlKfjtfzGzYDE4WhOufFxyWxciUePh425J2eZvElnXSdGha+FCfYjQcvqpCVoBAG70U4fJBGjB+HL/GpCXLyiYXPrSnzC9w==" - } - - resource "ibm_pi_network" "vtl_network" { - pi_cloud_instance_id = "%[1]s" - pi_network_name = "%[2]s" - pi_network_type = "pub-vlan" - } - - resource "ibm_pi_instance" "vtl_instance" { - pi_cloud_instance_id = "%[1]s" - pi_image_id = "%[3]s" - pi_instance_name = "%[2]s" - pi_key_pair_name = ibm_pi_key.vtl_key.name - pi_license_repository_capacity = "3" - pi_memory = "22" - pi_proc_type = "shared" - pi_processors = "2" - pi_storage_type = "tier1" - pi_sys_type = "s922" - pi_network { - network_id = ibm_pi_network.vtl_network.network_id - } - } - - `, acc.Pi_cloud_instance_id, name, acc.Pi_image) -} - -func testAccCheckIBMPIInstanceReplicantConfig(name string) string { - return fmt.Sprintf(` - resource "ibm_pi_volume" "power_volume" { - pi_cloud_instance_id = "%[1]s" - pi_volume_name = "%[2]s" - pi_volume_shareable = true - pi_volume_size = 1 - pi_volume_type = "tier3" - } - resource "ibm_pi_instance" "power_instance" { - pi_cloud_instance_id = "%[1]s" - pi_image_id = "%[3]s" - pi_instance_name = "%[2]s" - pi_memory = "2" - pi_proc_type = "shared" - pi_processors = "1" - pi_replicants = 3 - pi_replication_policy = "affinity" - pi_replication_scheme = "suffix" - pi_sys_type = "s922" - pi_volume_ids = [resource.ibm_pi_volume.power_volume.volume_id] - pi_network { - network_id = "%[4]s" - } - } - `, acc.Pi_cloud_instance_id, name, acc.Pi_image, acc.Pi_network_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 testAccCheckIBMPIInstanceUserTagsConfig(name, instanceHealthStatus string, userTagsString 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_cloud_instance_id = "%[1]s" - pi_image_name = "%[3]s" - } - data "ibm_pi_network" "power_networks" { - pi_cloud_instance_id = "%[1]s" - pi_network_name = "%[4]s" - } - resource "ibm_pi_volume" "power_volume" { - pi_cloud_instance_id = "%[1]s" - pi_volume_name = "%[2]s" - pi_volume_pool = data.ibm_pi_image.power_image.storage_pool - pi_volume_shareable = true - pi_volume_size = 20 - pi_volume_type = "%[6]s" - } - resource "ibm_pi_instance" "power_instance" { - pi_cloud_instance_id = "%[1]s" - pi_health_status = "%[5]s" - pi_image_id = data.ibm_pi_image.power_image.id - pi_instance_name = "%[2]s" - pi_key_pair_name = ibm_pi_key.key.name - pi_memory = "2" - pi_proc_type = "shared" - pi_processors = "0.25" - pi_storage_pool = data.ibm_pi_image.power_image.storage_pool - pi_storage_type = "%[6]s" - pi_sys_type = "s922" - pi_volume_ids = [ibm_pi_volume.power_volume.volume_id] - pi_network { - network_id = data.ibm_pi_network.power_networks.id - } - pi_user_tags = %[7]s - } - `, acc.Pi_cloud_instance_id, name, acc.Pi_image, acc.Pi_network_name, instanceHealthStatus, acc.PiStorageType, userTagsString) +func TestAccIBMPIInstanceStorageConnection(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: testAccCheckIBMPIInstanceStorageConnectionConfig(name, power.OK), + Check: resource.ComposeTestCheckFunc( + testAccCheckIBMPIInstanceExists(instanceRes), + resource.TestCheckResourceAttr(instanceRes, "pi_instance_name", name), + resource.TestCheckResourceAttr(instanceRes, "pi_storage_connection", acc.Pi_storage_connection), + ), + }, + }, + }) } func testAccCheckIBMPIInstanceStorageConnectionConfig(name, instanceHealthStatus string) string { @@ -323,69 +130,8 @@ func testAccCheckIBMPIInstanceStorageConnectionConfig(name, instanceHealthStatus } `, acc.Pi_cloud_instance_id, name, acc.Pi_image, acc.Pi_network_name, acc.Pi_storage_connection, instanceHealthStatus) } -func testAccCheckIBMPIInstanceDestroy(s *terraform.State) error { - sess, err := acc.TestAccProvider.Meta().(conns.ClientSession).IBMPISession() - if err != nil { - return err - } - - for _, rs := range s.RootModule().Resources { - if rs.Type != "ibm_pi_instance" { - continue - } - - idArr, err := flex.IdParts(rs.Primary.ID) - if err != nil { - return err - } - - cloudInstanceID := idArr[0] - for _, instanceID := range idArr[1:] { - client := st.NewIBMPIInstanceClient(context.Background(), sess, cloudInstanceID) - _, err = client.Get(instanceID) - if err == nil { - return fmt.Errorf("PI Instance still exists: %s", rs.Primary.ID) - } - } - } - - return nil -} -func testAccCheckIBMPIInstanceExists(n string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - if rs.Primary.ID == "" { - return errors.New("No Record ID is set") - } - - sess, err := acc.TestAccProvider.Meta().(conns.ClientSession).IBMPISession() - if err != nil { - return err - } - - idArr, err := flex.IdParts(rs.Primary.ID) - if err != nil { - return err - } - - cloudInstanceID := idArr[0] - for _, instanceID := range idArr[1:] { - client := st.NewIBMPIInstanceClient(context.Background(), sess, cloudInstanceID) - _, err = client.Get(instanceID) - if err != nil { - return err - } - } - - return nil - } -} - -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{ @@ -394,7 +140,7 @@ func TestAccIBMPIInstanceBasic(t *testing.T) { CheckDestroy: testAccCheckIBMPIInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckIBMPIInstanceConfig(name, power.Warning), + Config: testAccCheckIBMPIInstanceDeplomentTargetConfig(name), Check: resource.ComposeTestCheckFunc( testAccCheckIBMPIInstanceExists(instanceRes), resource.TestCheckResourceAttr(instanceRes, "pi_instance_name", name), @@ -403,26 +149,29 @@ func TestAccIBMPIInstanceBasic(t *testing.T) { }, }) } -func TestAccIBMPIInstanceStorageConnection(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: testAccCheckIBMPIInstanceStorageConnectionConfig(name, power.OK), - Check: resource.ComposeTestCheckFunc( - testAccCheckIBMPIInstanceExists(instanceRes), - resource.TestCheckResourceAttr(instanceRes, "pi_instance_name", name), - resource.TestCheckResourceAttr(instanceRes, "pi_storage_connection", acc.Pi_storage_connection), - ), - }, - }, - }) + +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 TestAccIBMPIInstanceDeploymentTarget(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{ @@ -431,7 +180,7 @@ func TestAccIBMPIInstanceDeploymentTarget(t *testing.T) { CheckDestroy: testAccCheckIBMPIInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckIBMPIInstanceDeplomentTargetConfig(name), + Config: testAccCheckIBMPIInstanceDeploymentTypeConfig(name, power.OK, "EPIC", "e980"), Check: resource.ComposeTestCheckFunc( testAccCheckIBMPIInstanceExists(instanceRes), resource.TestCheckResourceAttr(instanceRes, "pi_instance_name", name), @@ -440,7 +189,8 @@ func TestAccIBMPIInstanceDeploymentTarget(t *testing.T) { }, }) } -func TestAccIBMPIInstanceDeploymentType(t *testing.T) { + +func TestAccIBMPIInstanceDeploymentTypeNoStorage(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{ @@ -449,7 +199,7 @@ func TestAccIBMPIInstanceDeploymentType(t *testing.T) { CheckDestroy: testAccCheckIBMPIInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckIBMPIInstanceDeploymentTypeConfig(name, power.OK, "EPIC", "e980"), + Config: testAccCheckIBMPIInstanceDeploymentTypeConfig(name, power.OK, "VMNoStorage", "s922"), Check: resource.ComposeTestCheckFunc( testAccCheckIBMPIInstanceExists(instanceRes), resource.TestCheckResourceAttr(instanceRes, "pi_instance_name", name), @@ -459,6 +209,40 @@ func TestAccIBMPIInstanceDeploymentType(t *testing.T) { }) } +func testAccCheckIBMPIInstanceDeploymentTypeConfig(name, instanceHealthStatus, epic, systype 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_cloud_instance_id = "%[1]s" + pi_image_name = "%[3]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_cloud_instance_id = "%[1]s" + pi_deployment_type = "%[6]s" + pi_health_status = "%[5]s" + pi_image_id = data.ibm_pi_image.power_image.id + pi_instance_name = "%[2]s" + pi_key_pair_name = ibm_pi_key.key.name + pi_memory = "2" + pi_proc_type = "dedicated" + pi_processors = "1" + pi_storage_type = "%[8]s" + pi_sys_type = "%[7]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, epic, systype, acc.PiStorageType) +} + func TestAccIBMPIInstanceIBMiLicense(t *testing.T) { instanceRes := "ibm_pi_instance.power_instance" name := fmt.Sprintf("tf-pi-instance-%d", acctest.RandIntRange(10, 100)) @@ -493,6 +277,41 @@ func TestAccIBMPIInstanceIBMiLicense(t *testing.T) { }) } +func testAccCheckIBMPIInstanceIBMiLicense(name, instanceHealthStatus string, IBMiCSS bool, IBMiRDSUsers int) string { + return fmt.Sprintf(` + data "ibm_pi_image" "power_image" { + pi_cloud_instance_id = "%[1]s" + pi_image_name = "%[3]s" + } + data "ibm_pi_network" "power_networks" { + pi_cloud_instance_id = "%[1]s" + pi_network_name = "%[4]s" + } + resource "ibm_pi_volume" "power_volume" { + pi_cloud_instance_id = "%[1]s" + pi_volume_name = "%[2]s" + pi_volume_size = 1 + pi_volume_type = "tier3" + } + resource "ibm_pi_instance" "power_instance" { + pi_cloud_instance_id = "%[1]s" + pi_health_status = "%[5]s" + pi_ibmi_css = %[6]t + pi_ibmi_rds_users = %[7]d + pi_image_id = data.ibm_pi_image.power_image.id + pi_instance_name = "%[2]s" + pi_memory = "2" + pi_proc_type = "shared" + pi_processors = "0.25" + pi_storage_pool = data.ibm_pi_image.power_image.storage_pool + pi_sys_type = "s922" + pi_volume_ids = [ibm_pi_volume.power_volume.volume_id] + 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, IBMiCSS, IBMiRDSUsers) +} + func TestAccIBMPIInstanceReplicant(t *testing.T) { instanceRes := "ibm_pi_instance.power_instance" name := fmt.Sprintf("tf-pi-instance-%d", acctest.RandIntRange(10, 100)) @@ -515,6 +334,34 @@ func TestAccIBMPIInstanceReplicant(t *testing.T) { }) } +func testAccCheckIBMPIInstanceReplicantConfig(name string) string { + return fmt.Sprintf(` + resource "ibm_pi_volume" "power_volume" { + pi_cloud_instance_id = "%[1]s" + pi_volume_name = "%[2]s" + pi_volume_shareable = true + pi_volume_size = 1 + pi_volume_type = "tier3" + } + resource "ibm_pi_instance" "power_instance" { + pi_cloud_instance_id = "%[1]s" + pi_image_id = "%[3]s" + pi_instance_name = "%[2]s" + pi_memory = "2" + pi_proc_type = "shared" + pi_processors = "1" + pi_replicants = 3 + pi_replication_policy = "affinity" + pi_replication_scheme = "suffix" + pi_sys_type = "s922" + pi_volume_ids = [resource.ibm_pi_volume.power_volume.volume_id] + pi_network { + network_id = "%[4]s" + } + } + `, acc.Pi_cloud_instance_id, name, acc.Pi_image, acc.Pi_network_name) +} + func TestAccIBMPIInstanceNetwork(t *testing.T) { instanceRes := "ibm_pi_instance.power_instance" name := fmt.Sprintf("tf-pi-instance-%d", acctest.RandIntRange(10, 100)) @@ -539,6 +386,43 @@ func TestAccIBMPIInstanceNetwork(t *testing.T) { }) } +func testAccIBMPIInstanceNetworkConfig(name, privateNetIP 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 AAAAB3NzaC1yc2EAAAABJQAAAQEArb2aK0mekAdbYdY9rwcmeNSxqVCwez3WZTYEq+1Nwju0x5/vQFPSD2Kp9LpKBbxx3OVLN4VffgGUJznz9DAr7veLkWaf3iwEil6U4rdrhBo32TuDtoBwiczkZ9gn1uJzfIaCJAJdnO80Kv9k0smbQFq5CSb9H+F5VGyFue/iVd5/b30MLYFAz6Jg1GGWgw8yzA4Gq+nO7HtyuA2FnvXdNA3yK/NmrTiPCdJAtEPZkGu9LcelkQ8y90ArlKfjtfzGzYDE4WhOufFxyWxciUePh425J2eZvElnXSdGha+FCfYjQcvqpCVoBAG70U4fJBGjB+HL/GpCXLyiYXPrSnzC9w==" + } + resource "ibm_pi_network" "power_networks" { + pi_cidr = "192.168.17.0/24" + pi_cloud_instance_id = "%[1]s" + pi_dns = ["127.0.0.1"] + pi_gateway = "192.168.17.2" + pi_network_name = "%[2]s" + pi_network_type = "vlan" + pi_ipaddress_range { + pi_ending_ip_address = "192.168.17.254" + pi_starting_ip_address = "192.168.17.3" + } + } + resource "ibm_pi_instance" "power_instance" { + pi_cloud_instance_id = "%[1]s" + pi_image_id = "%[4]s" + pi_instance_name = "%[2]s" + pi_key_pair_name = ibm_pi_key.key.name + pi_memory = "2" + pi_proc_type = "shared" + pi_processors = "0.25" + pi_storage_type = "tier3" + pi_sys_type = "s922" + pi_network { + network_id = resource.ibm_pi_network.power_networks.network_id + ip_address = "%[3]s" + } + } + `, acc.Pi_cloud_instance_id, name, privateNetIP, acc.Pi_image) +} + func TestAccIBMPIInstanceVTL(t *testing.T) { instanceRes := "ibm_pi_instance.vtl_instance" name := fmt.Sprintf("tf-pi-vtl-instance-%d", acctest.RandIntRange(10, 100)) @@ -559,6 +443,39 @@ func TestAccIBMPIInstanceVTL(t *testing.T) { }) } +func testAccIBMPIInstanceVTLConfig(name string) string { + return fmt.Sprintf(` + resource "ibm_pi_key" "vtl_key" { + pi_cloud_instance_id = "%[1]s" + pi_key_name = "%[2]s" + pi_ssh_key = "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEArb2aK0mekAdbYdY9rwcmeNSxqVCwez3WZTYEq+1Nwju0x5/vQFPSD2Kp9LpKBbxx3OVLN4VffgGUJznz9DAr7veLkWaf3iwEil6U4rdrhBo32TuDtoBwiczkZ9gn1uJzfIaCJAJdnO80Kv9k0smbQFq5CSb9H+F5VGyFue/iVd5/b30MLYFAz6Jg1GGWgw8yzA4Gq+nO7HtyuA2FnvXdNA3yK/NmrTiPCdJAtEPZkGu9LcelkQ8y90ArlKfjtfzGzYDE4WhOufFxyWxciUePh425J2eZvElnXSdGha+FCfYjQcvqpCVoBAG70U4fJBGjB+HL/GpCXLyiYXPrSnzC9w==" + } + + resource "ibm_pi_network" "vtl_network" { + pi_cloud_instance_id = "%[1]s" + pi_network_name = "%[2]s" + pi_network_type = "pub-vlan" + } + + resource "ibm_pi_instance" "vtl_instance" { + pi_cloud_instance_id = "%[1]s" + pi_image_id = "%[3]s" + pi_instance_name = "%[2]s" + pi_key_pair_name = ibm_pi_key.vtl_key.name + pi_license_repository_capacity = "3" + pi_memory = "22" + pi_proc_type = "shared" + pi_processors = "2" + pi_storage_type = "tier1" + pi_sys_type = "s922" + pi_network { + network_id = ibm_pi_network.vtl_network.network_id + } + } + + `, acc.Pi_cloud_instance_id, name, acc.Pi_image) +} + func TestAccIBMPISAPInstance(t *testing.T) { instanceRes := "ibm_pi_instance.sap" name := fmt.Sprintf("tf-pi-sap-%d", acctest.RandIntRange(10, 100)) @@ -626,7 +543,7 @@ func TestAccIBMPIInstanceMixedStorage(t *testing.T) { CheckDestroy: testAccCheckIBMPIInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccIBMPIInstanceMixedStorage(name, power.Warning), + Config: testAccIBMPIInstanceMixedStorage(name), Check: resource.ComposeTestCheckFunc( testAccCheckIBMPIInstanceExists(instanceRes), resource.TestCheckResourceAttr(instanceRes, "pi_instance_name", name), @@ -637,7 +554,7 @@ func TestAccIBMPIInstanceMixedStorage(t *testing.T) { }) } -func testAccIBMPIInstanceMixedStorage(name, healthStatus string) string { +func testAccIBMPIInstanceMixedStorage(name string) string { return fmt.Sprintf(` resource "ibm_pi_key" "key" { pi_cloud_instance_id = "%[1]s" @@ -813,63 +730,6 @@ func testAccCheckIBMPIStoppedInstanceConfigUpdate(name, instanceHealthStatus, pr `, acc.Pi_cloud_instance_id, name, acc.Pi_image, acc.Pi_network_name, instanceHealthStatus, proc, memory, action) } -func testAccCheckIBMPIInstanceStatus(n, status string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - if rs.Primary.ID == "" { - return errors.New("No Record ID is set") - } - - sess, err := acc.TestAccProvider.Meta().(conns.ClientSession).IBMPISession() - if err != nil { - return err - } - - cloudInstanceID, instanceID, err := splitID(rs.Primary.ID) - if err == nil { - return err - } - client := st.NewIBMPIInstanceClient(context.Background(), sess, cloudInstanceID) - - instance, err := client.Get(instanceID) - if err != nil { - return err - } - - for { - if instance.Status != &status { - time.Sleep(2 * time.Minute) - } else { - break - } - } - - return nil - } -} - -func TestAccIBMPIInstanceDeploymentTypeNoStorage(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, power.OK, "VMNoStorage", "s922"), - Check: resource.ComposeTestCheckFunc( - testAccCheckIBMPIInstanceExists(instanceRes), - resource.TestCheckResourceAttr(instanceRes, "pi_instance_name", name), - ), - }, - }, - }) -} - func TestAccIBMPIInstanceVirtualSerialNumber(t *testing.T) { instanceRes := "ibm_pi_instance.power_instance" name := fmt.Sprintf("tf-pi-instance-%d", acctest.RandIntRange(10, 100)) @@ -1020,3 +880,147 @@ func TestAccIBMPIInstanceUserTags(t *testing.T) { }, }) } + +func testAccCheckIBMPIInstanceUserTagsConfig(name, instanceHealthStatus string, userTagsString 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_cloud_instance_id = "%[1]s" + pi_image_name = "%[3]s" + } + data "ibm_pi_network" "power_networks" { + pi_cloud_instance_id = "%[1]s" + pi_network_name = "%[4]s" + } + resource "ibm_pi_volume" "power_volume" { + pi_cloud_instance_id = "%[1]s" + pi_volume_name = "%[2]s" + pi_volume_pool = data.ibm_pi_image.power_image.storage_pool + pi_volume_shareable = true + pi_volume_size = 20 + pi_volume_type = "%[6]s" + } + resource "ibm_pi_instance" "power_instance" { + pi_cloud_instance_id = "%[1]s" + pi_health_status = "%[5]s" + pi_image_id = data.ibm_pi_image.power_image.id + pi_instance_name = "%[2]s" + pi_key_pair_name = ibm_pi_key.key.name + pi_memory = "2" + pi_proc_type = "shared" + pi_processors = "0.25" + pi_storage_pool = data.ibm_pi_image.power_image.storage_pool + pi_storage_type = "%[6]s" + pi_sys_type = "s922" + pi_volume_ids = [ibm_pi_volume.power_volume.volume_id] + pi_network { + network_id = data.ibm_pi_network.power_networks.id + } + pi_user_tags = %[7]s + } + `, acc.Pi_cloud_instance_id, name, acc.Pi_image, acc.Pi_network_name, instanceHealthStatus, acc.PiStorageType, userTagsString) +} + +func testAccCheckIBMPIInstanceDestroy(s *terraform.State) error { + sess, err := acc.TestAccProvider.Meta().(conns.ClientSession).IBMPISession() + if err != nil { + return err + } + + for _, rs := range s.RootModule().Resources { + if rs.Type != "ibm_pi_instance" { + continue + } + + idArr, err := flex.IdParts(rs.Primary.ID) + if err != nil { + return err + } + + cloudInstanceID := idArr[0] + for _, instanceID := range idArr[1:] { + client := st.NewIBMPIInstanceClient(context.Background(), sess, cloudInstanceID) + _, err = client.Get(instanceID) + if err == nil { + return fmt.Errorf("PI Instance still exists: %s", rs.Primary.ID) + } + } + } + + return nil +} + +func testAccCheckIBMPIInstanceExists(n string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Not found: %s", n) + } + if rs.Primary.ID == "" { + return errors.New("No Record ID is set") + } + + sess, err := acc.TestAccProvider.Meta().(conns.ClientSession).IBMPISession() + if err != nil { + return err + } + + idArr, err := flex.IdParts(rs.Primary.ID) + if err != nil { + return err + } + + cloudInstanceID := idArr[0] + for _, instanceID := range idArr[1:] { + client := st.NewIBMPIInstanceClient(context.Background(), sess, cloudInstanceID) + _, err = client.Get(instanceID) + if err != nil { + return err + } + } + + return nil + } +} + +func testAccCheckIBMPIInstanceStatus(n, status string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Not found: %s", n) + } + if rs.Primary.ID == "" { + return errors.New("No Record ID is set") + } + + sess, err := acc.TestAccProvider.Meta().(conns.ClientSession).IBMPISession() + if err != nil { + return err + } + + cloudInstanceID, instanceID, err := splitID(rs.Primary.ID) + if err == nil { + return err + } + client := st.NewIBMPIInstanceClient(context.Background(), sess, cloudInstanceID) + + instance, err := client.Get(instanceID) + if err != nil { + return err + } + + for { + if instance.Status != &status { + time.Sleep(2 * time.Minute) + } else { + break + } + } + + return nil + } +} diff --git a/website/docs/d/pi_instance.html.markdown b/website/docs/d/pi_instance.html.markdown index 2d25bae4d0..9f3a6bf913 100644 --- a/website/docs/d/pi_instance.html.markdown +++ b/website/docs/d/pi_instance.html.markdown @@ -47,6 +47,7 @@ Review the argument references that you can specify for your data source. In addition to all argument reference list, you can access the following attribute references after your data source is created. - `crn` - (String) The CRN of this resource. +- `dedicated_host_id` - (String) The dedicated host ID where the shared processor pool resides. - `deployment_type` - (String) The custom deployment type. - `fault` - (Map) Fault information, if any. diff --git a/website/docs/d/pi_instances.html.markdown b/website/docs/d/pi_instances.html.markdown index d3914c0102..d88676604a 100644 --- a/website/docs/d/pi_instances.html.markdown +++ b/website/docs/d/pi_instances.html.markdown @@ -48,6 +48,7 @@ In addition to all argument reference list, you can access the following attribu Nested scheme for `pvm_instances`: - `crn` - (String) The CRN of this resource. + - `dedicated_host_id` - (String) The dedicated host ID where the shared processor pool resides. - `fault` - (Map) Fault information, if any. Nested scheme for `fault`: @@ -96,4 +97,3 @@ In addition to all argument reference list, you can access the following attribu Nested scheme for `virtual_serial_number`: - `description` - (String) Description for virtual serial number. - `serial` - (String) Virtual serial number. - diff --git a/website/docs/r/pi_instance.html.markdown b/website/docs/r/pi_instance.html.markdown index 22dc544e37..bb6473f596 100644 --- a/website/docs/r/pi_instance.html.markdown +++ b/website/docs/r/pi_instance.html.markdown @@ -104,7 +104,7 @@ Review the argument references that you can specify for your resource. - 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_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. @@ -126,9 +126,9 @@ Review the argument references that you can specify for your resource. - `pi_virtual_serial_number` - (Optional, List) Virtual Serial Number information. If using `ibm_pi_virtual_serial_number` resource to manage a virtual serial number assigned to this instance, it is strongly recommended to ignore changes in this argument using the `ignore_changes` meta-argument in the `lifecycle`. Nested scheme for `pi_virtual_serial_number`: - - `description` - (String, Optional) Description of virtual serial number. - - `serial` - (String, Required) Provide an existing reserved Virtual Serial Number or specify 'auto-assign' for auto generated Virtual Serial Number. - + - `description` - (String, Optional) Description of virtual serial number. + - `serial` - (String, Required) Provide an existing reserved Virtual Serial Number or specify 'auto-assign' for auto generated Virtual Serial Number. + ~> **Note** When set to "auto-assign", changes to `serial` outside of terraform will not be detected. In addition, if a new generated virtual serial number is needed, the old serial must be removed before a new one is generated. - `pi_volume_ids` - (Optional, List of String) The list of volume IDs that you want to attach to the instance during creation. @@ -137,6 +137,7 @@ Review the argument references that you can specify for your resource. In addition to all argument reference list, you can access the following attribute reference after your resource is created. - `crn` - (String) The CRN of this resource. +- `dedicated_host_id` - (String) The dedicated host ID where the shared processor pool resides. - `fault` - (Map) Fault information, if any. Nested scheme for `fault`: