diff --git a/ibm/service/power/ibm_pi_constants.go b/ibm/service/power/ibm_pi_constants.go index e8c354ef90..11a0b5fe80 100644 --- a/ibm/service/power/ibm_pi_constants.go +++ b/ibm/service/power/ibm_pi_constants.go @@ -6,7 +6,12 @@ const ( // Arguments Arg_CloudConnectionName = "pi_cloud_connection_name" Arg_CloudInstanceID = "pi_cloud_instance_id" + Arg_ImageAccessKey = "pi_image_access_key" + Arg_ImageBucketName = "pi_image_bucket_name" + Arg_ImageBucketRegion = "pi_image_bucket_region" + Arg_ImageID = "pi_image_id" Arg_ImageName = "pi_image_name" + Arg_ImageSecretKey = "pi_image_secret_key" Arg_InstanceName = "pi_instance_name" Arg_Key = "pi_ssh_key" Arg_KeyName = "pi_key_name" diff --git a/ibm/service/power/resource_ibm_pi_image_export.go b/ibm/service/power/resource_ibm_pi_image_export.go index ed3df33d6a..4151553694 100644 --- a/ibm/service/power/resource_ibm_pi_image_export.go +++ b/ibm/service/power/resource_ibm_pi_image_export.go @@ -9,14 +9,12 @@ import ( "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - - st "github.com/IBM-Cloud/power-go-client/clients/instance" - "github.com/IBM-Cloud/power-go-client/helpers" + "github.com/IBM-Cloud/power-go-client/clients/instance" "github.com/IBM-Cloud/power-go-client/power/models" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func ResourceIBMPIImageExport() *schema.Resource { @@ -31,46 +29,45 @@ func ResourceIBMPIImageExport() *schema.Resource { }, Schema: map[string]*schema.Schema{ - //required attributes - helpers.PICloudInstanceId: { - Type: schema.TypeString, - Required: true, + //Arguments + Arg_CloudInstanceID: { Description: "PI cloud instance ID", ForceNew: true, - }, - helpers.PIImageId: { - Type: schema.TypeString, - Required: true, - Description: "Instance image id", - DiffSuppressFunc: flex.ApplyOnce, - ForceNew: true, - }, - helpers.PIImageBucketName: { - Type: schema.TypeString, Required: true, - Description: "Cloud Object Storage bucket name; bucket-name[/optional/folder]", - ForceNew: true, - }, - helpers.PIImageAccessKey: { Type: schema.TypeString, - Required: true, + }, + Arg_ImageAccessKey: { Description: "Cloud Object Storage access key; required for buckets with private access", - Sensitive: true, ForceNew: true, - }, - - helpers.PIImageSecretKey: { - Type: schema.TypeString, Required: true, - Description: "Cloud Object Storage secret key; required for buckets with private access", Sensitive: true, - ForceNew: true, + Type: schema.TypeString, }, - helpers.PIImageBucketRegion: { + Arg_ImageBucketName: { + Description: "Cloud Object Storage bucket name; bucket-name[/optional/folder]", + ForceNew: true, Type: schema.TypeString, + Required: true, + }, + Arg_ImageBucketRegion: { Description: "Cloud Object Storage region", ForceNew: true, Required: true, + Type: schema.TypeString, + }, + Arg_ImageID: { + Description: "Instance image id", + DiffSuppressFunc: flex.ApplyOnce, + ForceNew: true, + Required: true, + Type: schema.TypeString, + }, + Arg_ImageSecretKey: { + Description: "Cloud Object Storage secret key; required for buckets with private access", + ForceNew: true, + Required: true, + Sensitive: true, + Type: schema.TypeString, }, }, } @@ -83,28 +80,28 @@ func resourceIBMPIImageExportCreate(ctx context.Context, d *schema.ResourceData, return diag.FromErr(err) } - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) - imageid := d.Get(helpers.PIImageId).(string) - bucketName := d.Get(helpers.PIImageBucketName).(string) - accessKey := d.Get(helpers.PIImageAccessKey).(string) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) + imageid := d.Get(Arg_ImageID).(string) + bucketName := d.Get(Arg_ImageBucketName).(string) + accessKey := d.Get(Arg_ImageAccessKey).(string) - client := st.NewIBMPIImageClient(ctx, sess, cloudInstanceID) + client := instance.NewIBMPIImageClient(ctx, sess, cloudInstanceID) // image export var body = &models.ExportImage{ BucketName: &bucketName, AccessKey: &accessKey, - Region: d.Get(helpers.PIImageBucketRegion).(string), - SecretKey: d.Get(helpers.PIImageSecretKey).(string), + Region: d.Get(Arg_ImageBucketRegion).(string), + SecretKey: d.Get(Arg_ImageSecretKey).(string), } imageResponse, err := client.ExportImage(imageid, body) if err != nil { return diag.FromErr(err) } - d.SetId(fmt.Sprintf("%s/%s/%s", imageid, bucketName, d.Get(helpers.PIImageBucketRegion).(string))) + d.SetId(fmt.Sprintf("%s/%s/%s", imageid, bucketName, d.Get(Arg_ImageBucketRegion).(string))) - jobClient := st.NewIBMPIJobClient(ctx, sess, cloudInstanceID) + jobClient := instance.NewIBMPIJobClient(ctx, sess, cloudInstanceID) _, err = waitForIBMPIJobCompleted(ctx, jobClient, *imageResponse.ID, d.Timeout(schema.TimeoutCreate)) if err != nil { return diag.FromErr(err) diff --git a/ibm/service/power/resource_ibm_pi_image_export_test.go b/ibm/service/power/resource_ibm_pi_image_export_test.go index 82def95b39..182dc73bd6 100644 --- a/ibm/service/power/resource_ibm_pi_image_export_test.go +++ b/ibm/service/power/resource_ibm_pi_image_export_test.go @@ -28,17 +28,16 @@ func TestAccIBMPIImageEport(t *testing.T) { func testAccCheckIBMPIImageExportConfig() string { return fmt.Sprintf(` - data "ibm_pi_image" "power_image" { - pi_image_name = "%[6]s" - pi_cloud_instance_id = "%[1]s" + data "ibm_pi_image" "power_image" { + pi_image_name = "%[6]s" + pi_cloud_instance_id = "%[1]s" } resource "ibm_pi_image_export" "power_image_export" { - pi_image_id = data.ibm_pi_image.power_image.id - pi_cloud_instance_id = "%[1]s" - pi_image_bucket_name = "%[2]s" - pi_image_access_key = "%[3]s" - pi_image_secret_key = "%[4]s" - pi_image_bucket_region = "%[5]s" - } - `, acc.Pi_cloud_instance_id, acc.Pi_image_bucket_name, acc.Pi_image_bucket_access_key, acc.Pi_image_bucket_secret_key, acc.Pi_image_bucket_region, acc.Pi_image) + pi_image_id = data.ibm_pi_image.power_image.id + pi_cloud_instance_id = "%[1]s" + pi_image_bucket_name = "%[2]s" + pi_image_access_key = "%[3]s" + pi_image_secret_key = "%[4]s" + pi_image_bucket_region = "%[5]s" + }`, acc.Pi_cloud_instance_id, acc.Pi_image_bucket_name, acc.Pi_image_bucket_access_key, acc.Pi_image_bucket_secret_key, acc.Pi_image_bucket_region, acc.Pi_image) } diff --git a/website/docs/r/pi_image_export.html.markdown b/website/docs/r/pi_image_export.html.markdown index 7b1ccfaad9..ca72e1a6c1 100644 --- a/website/docs/r/pi_image_export.html.markdown +++ b/website/docs/r/pi_image_export.html.markdown @@ -1,5 +1,4 @@ --- - subcategory: "Power Systems" layout: "ibm" page_title: "IBM: pi_image_export" @@ -24,14 +23,14 @@ resource "ibm_pi_image_export" "testacc_image_export"{ } ``` -**Note** +**Notes** * Ensure the exported file is cleaned up manually from the Cloud Object Storage when no longer needed. Power Systems Virtual Server does not support deleting the exported image. Updating any attribute will result in creating a new Export job. * Please find [supported Regions](https://cloud.ibm.com/apidocs/power-cloud#endpoint) for endpoints. * If a Power cloud instance is provisioned at `lon04`, The provider level attributes should be as follows: * `region` - `lon` * `zone` - `lon04` - Example usage: +Example usage: ```terraform provider "ibm" {