diff --git a/go.sum b/go.sum index 8157e04ed6..ae50835cc2 100644 --- a/go.sum +++ b/go.sum @@ -125,8 +125,6 @@ github.com/IBM/go-sdk-core/v5 v5.6.3/go.mod h1:tt/B9rxLkRtglE7pvqLuYikgCXaZFL3bt github.com/IBM/go-sdk-core/v5 v5.9.5/go.mod h1:YlOwV9LeuclmT/qi/LAK2AsobbAP42veV0j68/rlZsE= github.com/IBM/go-sdk-core/v5 v5.10.2/go.mod h1:WZPFasUzsKab/2mzt29xPcfruSk5js2ywAPwW4VJjdI= github.com/IBM/go-sdk-core/v5 v5.17.4/go.mod h1:KsAAI7eStAWwQa4F96MLy+whYSh39JzNjklZRbN/8ns= -github.com/IBM/go-sdk-core/v5 v5.20.1 h1:dzeyifh1kfRLw8VfAIIS5okZYuqLTqplPZP/Kcsgdlo= -github.com/IBM/go-sdk-core/v5 v5.20.1/go.mod h1:Q3BYO6iDA2zweQPDGbNTtqft5tDcEpm6RTuqMlPcvbw= github.com/IBM/go-sdk-core/v5 v5.21.0 h1:DUnYhvC4SoC8T84rx5omnhY3+xcQg/Whyoa3mDPIMkk= github.com/IBM/go-sdk-core/v5 v5.21.0/go.mod h1:Q3BYO6iDA2zweQPDGbNTtqft5tDcEpm6RTuqMlPcvbw= github.com/IBM/ibm-backup-recovery-sdk-go v1.0.3 h1:9TZHocmCfgmF8TGVrpP1kFyQbjcqLNW7+bM07lefpKQ= diff --git a/ibm/acctest/acctest.go b/ibm/acctest/acctest.go index 4ce6af4577..a28f9d7b75 100644 --- a/ibm/acctest/acctest.go +++ b/ibm/acctest/acctest.go @@ -237,6 +237,7 @@ var ( Pi_image_bucket_region string Pi_image_bucket_secret_key string Pi_image_id string + Pi_instance_id string Pi_instance_name string Pi_key_name string Pi_network_address_group_id string @@ -1315,10 +1316,16 @@ func init() { fmt.Println("[INFO] Set the environment variable PI_SNAPSHOT_ID for testing ibm_pi_instance_snapshot data source else it is set to default value '1ea33118-4c43-4356-bfce-904d0658de82'") } - Pi_instance_name = os.Getenv("PI_PVM_INSTANCE_NAME") + Pi_instance_id = os.Getenv("PI_INSTANCE_ID") + if Pi_instance_id == "" { + Pi_instance_id = "terraform-test-power" + fmt.Println("[INFO] Set the environment variable PI_INSTANCE_ID for testing ibm_pi_instance resource else it is set to default value 'terraform-test-power'") + } + + Pi_instance_name = os.Getenv("PI_INSTANCE_NAME") if Pi_instance_name == "" { Pi_instance_name = "terraform-test-power" - fmt.Println("[INFO] Set the environment variable PI_PVM_INSTANCE_ID for testing Pi_instance_name resource else it is set to default value 'terraform-test-power'") + fmt.Println("[INFO] Set the environment variable PI_INSTANCE_NAME for testing ibm_pi_instance resource else it is set to default value 'terraform-test-power'") } Pi_dhcp_id = os.Getenv("PI_DHCP_ID") diff --git a/ibm/service/power/data_source_ibm_pi_instance.go b/ibm/service/power/data_source_ibm_pi_instance.go index 2e90034b72..c77431280e 100644 --- a/ibm/service/power/data_source_ibm_pi_instance.go +++ b/ibm/service/power/data_source_ibm_pi_instance.go @@ -27,11 +27,20 @@ func DataSourceIBMPIInstance() *schema.Resource { Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, + Arg_InstanceID: { + AtLeastOneOf: []string{Arg_InstanceID, Arg_InstanceName}, + ConflictsWith: []string{Arg_InstanceName}, + Description: "The ID of the PVM instance.", + Optional: true, + Type: schema.TypeString, + }, Arg_InstanceName: { - Description: "The unique identifier or name of the instance.", - Required: true, - Type: schema.TypeString, - ValidateFunc: validation.NoZeroValues, + AtLeastOneOf: []string{Arg_InstanceID, Arg_InstanceName}, + ConflictsWith: []string{Arg_InstanceID}, + Deprecated: "The pi_instance_name field is deprecated. Please use pi_instance_id instead", + Description: "The name of the PVM instance.", + Optional: true, + Type: schema.TypeString, }, // Attributes @@ -301,9 +310,15 @@ func dataSourceIBMPIInstancesRead(ctx context.Context, d *schema.ResourceData, m } cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) + var instanceID string + if v, ok := d.GetOk(Arg_InstanceID); ok { + instanceID = v.(string) + } else if v, ok := d.GetOk(Arg_InstanceName); ok { + instanceID = v.(string) + } powerC := instance.NewIBMPIInstanceClient(ctx, sess, cloudInstanceID) - powervmdata, err := powerC.Get(d.Get(Arg_InstanceName).(string)) + powervmdata, err := powerC.Get(instanceID) if err != nil { tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Get failed: %s", err.Error()), "(Data) ibm_pi_instance", "read") log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) diff --git a/ibm/service/power/data_source_ibm_pi_instance_console_languages.go b/ibm/service/power/data_source_ibm_pi_instance_console_languages.go index f45fb725ab..24ceceacac 100644 --- a/ibm/service/power/data_source_ibm_pi_instance_console_languages.go +++ b/ibm/service/power/data_source_ibm_pi_instance_console_languages.go @@ -29,11 +29,20 @@ func DataSourceIBMPIInstanceConsoleLanguages() *schema.Resource { Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, + Arg_InstanceID: { + AtLeastOneOf: []string{Arg_InstanceID, Arg_InstanceName}, + ConflictsWith: []string{Arg_InstanceName}, + Description: "The ID of the PVM instance.", + Optional: true, + Type: schema.TypeString, + }, Arg_InstanceName: { - Description: "The unique identifier or name of the instance.", - Required: true, - Type: schema.TypeString, - ValidateFunc: validation.NoZeroValues, + AtLeastOneOf: []string{Arg_InstanceID, Arg_InstanceName}, + ConflictsWith: []string{Arg_InstanceID}, + Deprecated: "The pi_instance_name field is deprecated. Please use pi_instance_id instead", + Description: "The name of the PVM instance.", + Optional: true, + Type: schema.TypeString, }, // Attributes @@ -69,10 +78,15 @@ func dataSourceIBMPIInstanceConsoleLanguagesRead(ctx context.Context, d *schema. } cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) - instanceName := d.Get(Arg_InstanceName).(string) + var instanceID string + if v, ok := d.GetOk(Arg_InstanceID); ok { + instanceID = v.(string) + } else if v, ok := d.GetOk(Arg_InstanceName); ok { + instanceID = v.(string) + } client := instance.NewIBMPIInstanceClient(ctx, sess, cloudInstanceID) - languages, err := client.GetConsoleLanguages(instanceName) + languages, err := client.GetConsoleLanguages(instanceID) if err != nil { tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GetConsoleLanguages failed: %s", err.Error()), "(Data) ibm_pi_instance_console_languages", "read") log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) diff --git a/ibm/service/power/data_source_ibm_pi_instance_console_languages_test.go b/ibm/service/power/data_source_ibm_pi_instance_console_languages_test.go index 9d52aa963f..f5d193ba79 100644 --- a/ibm/service/power/data_source_ibm_pi_instance_console_languages_test.go +++ b/ibm/service/power/data_source_ibm_pi_instance_console_languages_test.go @@ -31,7 +31,7 @@ func TestAccIBMPIInstanceConsoleLanguages(t *testing.T) { func testAccCheckIBMPIInstanceConsoleLanguagesConfig() string { return fmt.Sprintf(` data "ibm_pi_console_languages" "example" { - pi_cloud_instance_id = "%s" - pi_instance_name = "%s" - }`, acc.Pi_cloud_instance_id, acc.Pi_instance_name) + pi_cloud_instance_id = "%[1]s" + pi_instance_id = "%[2]s" + }`, acc.Pi_cloud_instance_id, acc.Pi_instance_id) } diff --git a/ibm/service/power/data_source_ibm_pi_instance_ip.go b/ibm/service/power/data_source_ibm_pi_instance_ip.go index 95f0f4707c..22bf5014c1 100644 --- a/ibm/service/power/data_source_ibm_pi_instance_ip.go +++ b/ibm/service/power/data_source_ibm_pi_instance_ip.go @@ -29,11 +29,20 @@ func DataSourceIBMPIInstanceIP() *schema.Resource { Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, + Arg_InstanceID: { + AtLeastOneOf: []string{Arg_InstanceID, Arg_InstanceName}, + ConflictsWith: []string{Arg_InstanceName}, + Description: "The ID of the PVM instance.", + Optional: true, + Type: schema.TypeString, + }, Arg_InstanceName: { - Description: "The unique identifier or name of the instance.", - Required: true, - Type: schema.TypeString, - ValidateFunc: validation.NoZeroValues, + AtLeastOneOf: []string{Arg_InstanceID, Arg_InstanceName}, + ConflictsWith: []string{Arg_InstanceID}, + Deprecated: "The pi_instance_name field is deprecated. Please use pi_instance_id instead", + Description: "The name of the PVM instance.", + Optional: true, + Type: schema.TypeString, }, Arg_NetworkName: { Description: "The subnet that the instance belongs to.", @@ -109,10 +118,16 @@ func dataSourceIBMPIInstancesIPRead(ctx context.Context, d *schema.ResourceData, } cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) + var instanceID string + if v, ok := d.GetOk(Arg_InstanceID); ok { + instanceID = v.(string) + } else if v, ok := d.GetOk(Arg_InstanceName); ok { + instanceID = v.(string) + } networkName := d.Get(Arg_NetworkName).(string) powerC := instance.NewIBMPIInstanceClient(ctx, sess, cloudInstanceID) - powervmdata, err := powerC.Get(d.Get(Arg_InstanceName).(string)) + powervmdata, err := powerC.Get(instanceID) if err != nil { tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Get failed: %s", err.Error()), "(Data) ibm_pi_instance_ip", "read") log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) diff --git a/ibm/service/power/data_source_ibm_pi_instance_ip_test.go b/ibm/service/power/data_source_ibm_pi_instance_ip_test.go index b8963ee639..150af0bad6 100644 --- a/ibm/service/power/data_source_ibm_pi_instance_ip_test.go +++ b/ibm/service/power/data_source_ibm_pi_instance_ip_test.go @@ -30,8 +30,8 @@ func TestAccIBMPIInstanceIPDataSource_basic(t *testing.T) { func testAccCheckIBMPIInstanceIPDataSourceConfig() string { return fmt.Sprintf(` data "ibm_pi_instance_ip" "testacc_ds_instance_ip" { - pi_network_name = "%[1]s" - pi_instance_name = "%[2]s" - pi_cloud_instance_id = "%[3]s" - }`, acc.Pi_network_name, acc.Pi_instance_name, acc.Pi_cloud_instance_id) + pi_cloud_instance_id = "%[1]s" + pi_instance_id = "%[2]s" + pi_network_name = "%[3]s" + }`, acc.Pi_cloud_instance_id, acc.Pi_instance_id, acc.Pi_network_name) } diff --git a/ibm/service/power/data_source_ibm_pi_instance_test.go b/ibm/service/power/data_source_ibm_pi_instance_test.go index 080692e296..e5d424307a 100644 --- a/ibm/service/power/data_source_ibm_pi_instance_test.go +++ b/ibm/service/power/data_source_ibm_pi_instance_test.go @@ -31,7 +31,7 @@ func TestAccIBMPIInstanceDataSource_basic(t *testing.T) { func testAccCheckIBMPIInstanceDataSourceConfig() string { return fmt.Sprintf(` data "ibm_pi_instance" "testacc_ds_instance" { - pi_instance_name="%s" - pi_cloud_instance_id = "%s" - }`, acc.Pi_instance_name, acc.Pi_cloud_instance_id) + pi_cloud_instance_id = "%[1]s" + pi_instance_id = "%[2]s" + }`, acc.Pi_cloud_instance_id, acc.Pi_instance_id) } diff --git a/ibm/service/power/data_source_ibm_pi_instance_volumes.go b/ibm/service/power/data_source_ibm_pi_instance_volumes.go index b49af5829b..ee07929d44 100644 --- a/ibm/service/power/data_source_ibm_pi_instance_volumes.go +++ b/ibm/service/power/data_source_ibm_pi_instance_volumes.go @@ -29,11 +29,20 @@ func DataSourceIBMPIInstanceVolumes() *schema.Resource { Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, + Arg_InstanceID: { + AtLeastOneOf: []string{Arg_InstanceID, Arg_InstanceName}, + ConflictsWith: []string{Arg_InstanceName}, + Description: "The PVM instance ID.", + Optional: true, + Type: schema.TypeString, + }, Arg_InstanceName: { - Description: "The unique identifier or name of the instance.", - Required: true, - Type: schema.TypeString, - ValidateFunc: validation.NoZeroValues, + AtLeastOneOf: []string{Arg_InstanceID, Arg_InstanceName}, + ConflictsWith: []string{Arg_InstanceID}, + Deprecated: "The pi_instance_name field is deprecated. Please use pi_instance_id instead", + Description: "The name of the PVM instance.", + Optional: true, + Type: schema.TypeString, }, // Attribute @@ -47,11 +56,26 @@ func DataSourceIBMPIInstanceVolumes() *schema.Resource { Description: "List of volumes attached to instance.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ + Attr_Auxiliary: { + Computed: true, + Description: "Indicates if the volume is auxiliary or not.", + Type: schema.TypeBool, + }, + Attr_AuxiliaryVolumeName: { + Computed: true, + Description: "The auxiliary volume name.", + Type: schema.TypeString, + }, Attr_Bootable: { Computed: true, Description: "Indicates if the volume is boot capable.", Type: schema.TypeBool, }, + Attr_ConsistencyGroupName: { + Computed: true, + Description: "The name of consistency group at storage controller level.", + Type: schema.TypeString, + }, Attr_CreationDate: { Computed: true, Description: "Date volume was created.", @@ -62,11 +86,21 @@ func DataSourceIBMPIInstanceVolumes() *schema.Resource { Description: "The CRN of this resource.", Type: schema.TypeString, }, + Attr_DeleteOnTermination: { + Computed: true, + Description: "Indicates if the volume should be deleted when the server terminates.", + Type: schema.TypeBool, + }, Attr_FreezeTime: { Computed: true, Description: "The freeze time of remote copy.", Type: schema.TypeString, }, + Attr_GroupID: { + Computed: true, + Description: "The volume group id in which the volume belongs.", + Type: schema.TypeString, + }, Attr_Href: { Computed: true, Description: "The hyper link of the volume.", @@ -77,21 +111,46 @@ func DataSourceIBMPIInstanceVolumes() *schema.Resource { Description: "The unique identifier of the volume.", Type: schema.TypeString, }, + Attr_IOThrottleRate: { + Computed: true, + Description: "Amount of iops assigned to the volume", + Type: schema.TypeString, + }, Attr_LastUpdateDate: { Computed: true, Description: "The last updated date of the volume.", Type: schema.TypeString, }, + Attr_MasterVolumeName: { + Computed: true, + Description: "Indicates master volume name", + Type: schema.TypeString, + }, + Attr_MirroringState: { + Computed: true, + Description: "Mirroring state for replication enabled volume", + Type: schema.TypeString, + }, Attr_Name: { Computed: true, Description: "The name of the volume.", Type: schema.TypeString, }, + Attr_OutOfBandDeleted: { + Computed: true, + Description: "Indicates if the volume does not exist on storage controller.", + Type: schema.TypeBool, + }, Attr_Pool: { Computed: true, Description: "Volume pool, name of storage pool where the volume is located.", Type: schema.TypeString, }, + Attr_PrimaryRole: { + Computed: true, + Description: "Indicates whether master/aux volume is playing the primary role.", + Type: schema.TypeString, + }, Attr_ReplicationEnabled: { Computed: true, Description: "Indicates if the volume should be replication enabled or not.", @@ -103,6 +162,16 @@ func DataSourceIBMPIInstanceVolumes() *schema.Resource { Elem: &schema.Schema{Type: schema.TypeString}, Type: schema.TypeList, }, + Attr_ReplicationStatus: { + Computed: true, + Description: "The replication status of the volume.", + Type: schema.TypeString, + }, + Attr_ReplicationType: { + Computed: true, + Description: "The replication type of the volume, 'metro' or 'global'.", + Type: schema.TypeString, + }, Attr_Shareable: { Computed: true, Description: "Indicates if the volume is shareable between VMs.", @@ -130,6 +199,21 @@ func DataSourceIBMPIInstanceVolumes() *schema.Resource { Set: schema.HashString, Type: schema.TypeSet, }, + Attr_VolumePool: { + Computed: true, + Description: "Name of the storage pool where the volume is located.", + Type: schema.TypeString, + }, + Attr_VolumeType: { + Computed: true, + Description: "Name of storage template used to create the volume.", + Type: schema.TypeString, + }, + Attr_WWN: { + Computed: true, + Description: "The world wide name of the volume.", + Type: schema.TypeString, + }, }, }, Type: schema.TypeList, @@ -147,9 +231,15 @@ func dataSourceIBMPIInstanceVolumesRead(ctx context.Context, d *schema.ResourceD } cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) + var instanceID string + if v, ok := d.GetOk(Arg_InstanceID); ok { + instanceID = v.(string) + } else if v, ok := d.GetOk(Arg_InstanceName); ok { + instanceID = v.(string) + } volumeC := instance.NewIBMPIVolumeClient(ctx, sess, cloudInstanceID) - volumedata, err := volumeC.GetAllInstanceVolumes(d.Get(Arg_InstanceName).(string)) + volumedata, err := volumeC.GetAllInstanceVolumes(instanceID) if err != nil { tfErr := flex.TerraformErrorf(err, fmt.Sprintf(" failed: %s", err.Error()), "(Data) ibm_pi_instance_volumes", "read") log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) @@ -171,18 +261,32 @@ func flattenVolumesInstances(list []*models.VolumeReference, meta any) []map[str result := make([]map[string]any, 0, len(list)) for _, i := range list { l := map[string]any{ - Attr_Bootable: *i.Bootable, - Attr_CreationDate: i.CreationDate.String(), - Attr_Href: *i.Href, - Attr_ID: *i.VolumeID, - Attr_LastUpdateDate: i.LastUpdateDate.String(), - Attr_Name: *i.Name, - Attr_Pool: i.VolumePool, - Attr_ReplicationEnabled: i.ReplicationEnabled, - Attr_Shareable: *i.Shareable, - Attr_Size: *i.Size, - Attr_State: *i.State, - Attr_Type: *i.DiskType, + Attr_Auxiliary: *i.Auxiliary, + Attr_AuxiliaryVolumeName: i.AuxVolumeName, + Attr_Bootable: *i.Bootable, + Attr_ConsistencyGroupName: i.ConsistencyGroupName, + Attr_CreationDate: i.CreationDate.String(), + Attr_GroupID: i.GroupID, + Attr_Href: *i.Href, + Attr_ID: *i.VolumeID, + Attr_IOThrottleRate: i.IoThrottleRate, + Attr_LastUpdateDate: i.LastUpdateDate.String(), + Attr_MasterVolumeName: i.MasterVolumeName, + Attr_MirroringState: i.MirroringState, + Attr_Name: *i.Name, + Attr_OutOfBandDeleted: i.OutOfBandDeleted, + Attr_Pool: i.VolumePool, + Attr_PrimaryRole: i.PrimaryRole, + Attr_ReplicationEnabled: i.ReplicationEnabled, + Attr_ReplicationStatus: i.ReplicationStatus, + Attr_ReplicationType: i.ReplicationType, + Attr_Shareable: *i.Shareable, + Attr_Size: *i.Size, + Attr_State: *i.State, + Attr_Type: *i.DiskType, + Attr_VolumePool: i.VolumePool, + Attr_VolumeType: i.VolumeType, + Attr_WWN: *i.Wwn, } if i.Crn != "" { l[Attr_CRN] = i.Crn @@ -192,6 +296,9 @@ func flattenVolumesInstances(list []*models.VolumeReference, meta any) []map[str } l[Attr_UserTags] = tags } + if i.DeleteOnTermination != nil { + l[Attr_DeleteOnTermination] = *i.DeleteOnTermination + } if i.FreezeTime != nil { l[Attr_FreezeTime] = i.FreezeTime.String() } diff --git a/ibm/service/power/data_source_ibm_pi_instance_volumes_test.go b/ibm/service/power/data_source_ibm_pi_instance_volumes_test.go index e5f184da57..722f426db5 100644 --- a/ibm/service/power/data_source_ibm_pi_instance_volumes_test.go +++ b/ibm/service/power/data_source_ibm_pi_instance_volumes_test.go @@ -12,13 +12,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) -func TestAccIBMPIVolumesDataSource_basic(t *testing.T) { +func TestAccIBMPIInstanceVolumesDataSource_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckIBMPIVolumesDataSourceConfig(), + Config: testAccCheckIBMPIInstanceVolumesDataSourceConfig(), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet("data.ibm_pi_instance_volumes.testacc_ds_volumes", "id"), ), @@ -27,10 +27,10 @@ func TestAccIBMPIVolumesDataSource_basic(t *testing.T) { }) } -func testAccCheckIBMPIVolumesDataSourceConfig() string { +func testAccCheckIBMPIInstanceVolumesDataSourceConfig() string { return fmt.Sprintf(` data "ibm_pi_instance_volumes" "testacc_ds_volumes" { - pi_instance_name = "%s" - pi_cloud_instance_id = "%s" - }`, acc.Pi_instance_name, acc.Pi_cloud_instance_id) + pi_cloud_instance_id = "%[1]s" + pi_instance_id = "%[2]s" + }`, acc.Pi_cloud_instance_id, acc.Pi_instance_id) } diff --git a/ibm/service/power/data_source_ibm_pi_pvm_snapshot.go b/ibm/service/power/data_source_ibm_pi_pvm_snapshot.go index c3e1ea5292..a0d862c6cc 100644 --- a/ibm/service/power/data_source_ibm_pi_pvm_snapshot.go +++ b/ibm/service/power/data_source_ibm_pi_pvm_snapshot.go @@ -5,6 +5,7 @@ package power import ( "context" + "fmt" "log" "github.com/IBM-Cloud/power-go-client/clients/instance" @@ -28,11 +29,20 @@ func DataSourceIBMPIPVMSnapshot() *schema.Resource { Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, + Arg_InstanceID: { + AtLeastOneOf: []string{Arg_InstanceID, Arg_InstanceName}, + ConflictsWith: []string{Arg_InstanceName}, + Description: "The ID of the PVM instance.", + Optional: true, + Type: schema.TypeString, + }, Arg_InstanceName: { - Description: "The unique identifier or name of the instance.", - Required: true, - Type: schema.TypeString, - ValidateFunc: validation.NoZeroValues, + AtLeastOneOf: []string{Arg_InstanceID, Arg_InstanceName}, + ConflictsWith: []string{Arg_InstanceID}, + Deprecated: "The pi_instance_name field is deprecated. Please use pi_instance_id instead", + Description: "The name of the PVM instance.", + Optional: true, + Type: schema.TypeString, }, // Attributes @@ -105,19 +115,29 @@ func DataSourceIBMPIPVMSnapshot() *schema.Resource { } } -func dataSourceIBMPISnapshotRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func dataSourceIBMPISnapshotRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { sess, err := meta.(conns.ClientSession).IBMPISession() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("IBMPISession failed: %s", err.Error()), "(Data) ibm_pi_pvm_snapshot", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) - powerinstancename := d.Get(Arg_InstanceName).(string) + var instanceID string + if v, ok := d.GetOk(Arg_InstanceID); ok { + instanceID = v.(string) + } else if v, ok := d.GetOk(Arg_InstanceName); ok { + instanceID = v.(string) + } + snapshot := instance.NewIBMPIInstanceClient(ctx, sess, cloudInstanceID) - snapshotData, err := snapshot.GetSnapShotVM(powerinstancename) + snapshotData, err := snapshot.GetSnapShotVM(instanceID) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GetSnapShotVM failed: %s", err.Error()), "(Data) ibm_pi_pvm_snapshot", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } var clientgenU, _ = uuid.GenerateUUID() @@ -127,11 +147,11 @@ func dataSourceIBMPISnapshotRead(ctx context.Context, d *schema.ResourceData, me return nil } -func flattenPVMSnapshotInstances(list []*models.Snapshot, meta interface{}) []map[string]interface{} { +func flattenPVMSnapshotInstances(list []*models.Snapshot, meta any) []map[string]any { log.Printf("Calling the flattenPVMSnapshotInstances call with list %d", len(list)) - result := make([]map[string]interface{}, 0, len(list)) + result := make([]map[string]any, 0, len(list)) for _, i := range list { - l := map[string]interface{}{ + l := map[string]any{ Attr_Action: i.Action, Attr_CreationDate: i.CreationDate.String(), Attr_Description: i.Description, diff --git a/ibm/service/power/data_source_ibm_pi_pvm_snapshot_test.go b/ibm/service/power/data_source_ibm_pi_pvm_snapshot_test.go index 0394b660a7..96c58369cc 100644 --- a/ibm/service/power/data_source_ibm_pi_pvm_snapshot_test.go +++ b/ibm/service/power/data_source_ibm_pi_pvm_snapshot_test.go @@ -12,14 +12,14 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) -func TestAccIBMPISnapshotDataSource_basic(t *testing.T) { +func TestAccIBMPIPVMSnapshotDataSource_basic(t *testing.T) { snapshotRes := "data.ibm_pi_pvm_snapshots.testacc_pi_snapshots" resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckIBMPISnapshotDataSourceConfig(), + Config: testAccCheckIBMPIPVMSnapshotDataSourceConfig(), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet(snapshotRes, "id"), ), @@ -28,10 +28,10 @@ func TestAccIBMPISnapshotDataSource_basic(t *testing.T) { }) } -func testAccCheckIBMPISnapshotDataSourceConfig() string { +func testAccCheckIBMPIPVMSnapshotDataSourceConfig() string { return fmt.Sprintf(` data "ibm_pi_pvm_snapshots" "testacc_pi_snapshots" { - pi_instance_name = "%s" - pi_cloud_instance_id = "%s" - }`, acc.Pi_instance_name, acc.Pi_cloud_instance_id) + pi_cloud_instance_id = "%[1]s" + pi_instance_id = "%[2]s" + }`, acc.Pi_cloud_instance_id, acc.Pi_instance_id) } diff --git a/ibm/service/power/ibm_pi_constants.go b/ibm/service/power/ibm_pi_constants.go index 26e3b47130..b82927bbbc 100644 --- a/ibm/service/power/ibm_pi_constants.go +++ b/ibm/service/power/ibm_pi_constants.go @@ -555,6 +555,7 @@ const ( Attr_VolumeSnapshots = "volume_snapshots" Attr_VolumesSnapshots = "volume_snapshots" Attr_VolumeStatus = "volume_status" + Attr_VolumeType = "volume_type" Attr_VPCCRNs = "vpc_crns" Attr_VPCEnabled = "vpc_enabled" Attr_WorkloadType = "workload_type" diff --git a/website/docs/d/pi_console_languages.html.markdown b/website/docs/d/pi_console_languages.html.markdown index 7e99febe21..53755aeb91 100644 --- a/website/docs/d/pi_console_languages.html.markdown +++ b/website/docs/d/pi_console_languages.html.markdown @@ -10,12 +10,12 @@ description: |- Retrieve information about all the available Console Languages for an Instance. For more information, see [getting started with IBM Power Systems Virtual Servers](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-getting-started). -## Example usage +## Example Usage ```terraform data "ibm_pi_console_languages" "example" { - pi_cloud_instance_id = "" - pi_instance_name = "" + pi_cloud_instance_id = "e6b579b7-d94b-42e5-a19d-5d1e0b2547c4" + pi_instance_id = "b0f1b2e4-cc61-49df-a6c2-29fa58b4a915" } ``` @@ -40,7 +40,8 @@ Example usage: Review the argument references that you can specify for your data source. - `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. -- `pi_instance_name` - (Required, String) The unique identifier or name of the instance. +- `pi_instance_id` - (Optional, String) The PVM instance ID. +- `pi_instance_name` - (Deprecated, Optional, String) The unique identifier or name of the instance. Passing the name of the instance could fail or fetch stale data. Please pass an id and use `pi_instance_id` instead. ## Attribute Reference diff --git a/website/docs/d/pi_instance.html.markdown b/website/docs/d/pi_instance.html.markdown index 0904d6e9de..be23d26159 100644 --- a/website/docs/d/pi_instance.html.markdown +++ b/website/docs/d/pi_instance.html.markdown @@ -14,8 +14,8 @@ Retrieve information about a Power Systems Virtual Server instance. For more inf ```terraform data "ibm_pi_instance" "ds_instance" { - pi_instance_name = "terraform-test-instance" pi_cloud_instance_id = "49fba6c9-23f8-40bc-9899-aca322ee7d5b" + pi_instance_id = "e6b579b7-d94b-42e5-a19d-5d1e0b2547c4" } ``` @@ -40,7 +40,8 @@ Example usage: Review the argument references that you can specify for your data source. - `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. -- `pi_instance_name` - (Required, String) The unique identifier or name of the instance. +- `pi_instance_id` - (Optional, String) The PVM instance ID. +- `pi_instance_name` - (Deprecated, Optional, String) The unique identifier or name of the instance. Passing the name of the instance could fail or fetch stale data. Please pass an id and use `pi_instance_id` instead. ## Attribute Reference diff --git a/website/docs/d/pi_instance_ip.html.markdown b/website/docs/d/pi_instance_ip.html.markdown index 17242bf2d9..4448dba07b 100644 --- a/website/docs/d/pi_instance_ip.html.markdown +++ b/website/docs/d/pi_instance_ip.html.markdown @@ -14,9 +14,9 @@ Retrieve information about a Power Systems Virtual Server instance IP address. F ```terraform data "ibm_pi_instance_ip" "ds_instance_ip" { - pi_instance_name = "terraform-test-instance" - pi_network_name = "APP" pi_cloud_instance_id = "49fba6c9-23f8-40bc-9899-aca322ee7d5b" + pi_instance_id = "9f1b78d2-5c83-4a6f-aef4-6e48d2f5d91d" + pi_network_name = "APP" } ``` @@ -41,8 +41,9 @@ Example usage: Review the argument references that you can specify for your data source. - `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. -- `pi_instance_name` - (Required, String) The unique identifier or name of the instance. -- `pi_network_name` - (Required, String) The subnet that the instance belongs to. +- `pi_instance_id` - (Optional, String) The unique identifier the instance. +- `pi_instance_name` - (Deprecated, Optional, String) The unique identifier or name of the instance. Passing the name of the instance could fail or fetch stale data. Please pass an id and use `pi_instance_id` instead +- `pi_network_name` - (Required, String) The subnet name that the instance belongs to. ## Attribute Reference diff --git a/website/docs/d/pi_instance_volumes.html.markdown b/website/docs/d/pi_instance_volumes.html.markdown index 9a20cec501..fc141b5b10 100644 --- a/website/docs/d/pi_instance_volumes.html.markdown +++ b/website/docs/d/pi_instance_volumes.html.markdown @@ -16,8 +16,8 @@ The following example retrieves information about the volumes attached to the `t ```terraform data "ibm_pi_instance_volumes" "ds_volumes" { - pi_instance_name = "terraform-test-instance" pi_cloud_instance_id = "49fba6c9-23f8-40bc-9899-aca322ee7d5b" + pi_instance_id = "e6b579b7-d94b-42e5-a19d-5d1e0b2547c4" } ``` @@ -42,7 +42,8 @@ Example usage: Review the argument references that you can specify for your data source. - `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. -- `pi_instance_name` - (Required, String) The unique identifier or name of the instance. +- `pi_instance_id` - (Optional, String) The PVM instance ID. +- `pi_instance_name` - (Deprecated, Optional, String) The unique identifier or name of the instance. Passing the name of the instance could fail or fetch stale data. Please pass an id and use `pi_instance_id` instead. ## Attribute Reference @@ -52,19 +53,34 @@ In addition to all argument reference list, you can access the following attribu - `instance_volumes` - (List) List of volumes attached to instance. Nested scheme for `instance_volumes`: + - `auxiliary_volume_name` - (String) The auxiliary volume name. + - `auxiliary` - (Boolean) Indicates if the volume is auxiliary or not. - `bootable`- (Boolean) Indicates if the volume is boot capable. + - `consistency_group_name` - (String) The consistency group name if volume is a part of volume group. - `creation_date` - (String) Date of volume creation. - `crn` - (String) The CRN of this resource. + - `delete_on_termination` - (Boolean) Indicates if the volume should be deleted when the server terminates. - `freeze_time` - (String) Time of remote copy relationship. + - `group_id` - (String) The volume group id to which volume belongs. - `href` - (String) The hyper link of the volume. - `id` - (String) The unique identifier of the volume. + - `io_throttle_rate` - (String) Amount of iops assigned to the volume. - `last_update_date` - (String) The date when the volume last updated. + - `master_volume_name` - (String) The master volume name. + - `mirroring_state` - (String) Mirroring state for replication enabled volume. - `name` - (String) The name of the volume. + - `out_of_band_deleted` - (Bool) Indicates if the volume does not exist on storage controller. - `pool` - (String) Volume pool, name of storage pool where the volume is located. + - `primary_role` - (String) Indicates whether `master`/`auxiliary` volume is playing the primary role. - `replication_enabled` - (Boolean) Indicates whether replication is enabled on the volume. - `replication_sites` - (List) List of replication sites for volume replication. + - `replication_status` - (String) The replication status of the volume. + - `replication_type` - (String) The replication type of the volume, `metro` or `global`. - `shareable` - (Boolean) Indicates if the volume is shareable between VMs. - `size` - (Integer) The size of this volume in GB. - `state` - (String) The state of the volume. - `type` - (String) The disk type that is used for this volume. - `user_tags` - (List) List of user tags attached to the resource. + - `volume_pool` - (String) Name of the storage pool where the volume is located. + - `volume_type` - (String) Name of storage template used to create the volume. + - `wwn` - (String) The world wide name of the volume. diff --git a/website/docs/d/pi_pvm_snapshots.html.markdown b/website/docs/d/pi_pvm_snapshots.html.markdown index b8b42531ac..92fa944eca 100644 --- a/website/docs/d/pi_pvm_snapshots.html.markdown +++ b/website/docs/d/pi_pvm_snapshots.html.markdown @@ -7,23 +7,27 @@ description: |- --- # ibm_pi_pvm_snapshots + Retrieve information about a Power Systems Virtual Server instance snapshots. For more information, about Power Virtual Server PVM instance snapshots, see [getting started with IBM Power Systems Virtual Servers](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-getting-started). -## Example usage +## Example Usage + ```terraform data "ibm_pi_pvm_snapshots" "ds_pvm_snapshots" { - pi_instance_name = "terraform-test-instance" pi_cloud_instance_id = "49fba6c9-23f8-40bc-9899-aca322ee7d5b" + pi_instance_id = "e6b579b7-d94b-42e5-a19d-5d1e0b2547c4" } ``` -**Notes** +### Notes + - 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: + ```terraform provider "ibm" { region = "lon" @@ -31,14 +35,17 @@ Example usage: } ``` -## Argument reference -Review the argument references that you can specify for your data source. +## Argument Reference + +Review the argument references that you can specify for your data source. - `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. -- `pi_instance_name` - (Required, String) The unique identifier or name of the instance. +- `pi_instance_id` - (Optional, String) The PVM instance ID. +- `pi_instance_name` - (Deprecated, Optional, String) The unique identifier or name of the instance. Passing the name of the instance could fail or fetch stale data. Please pass an id and use `pi_instance_id` instead. + +## Attribute Reference -## Attribute reference -In addition to all argument reference list, you can access the following attribute references after your data source is created. +In addition to all argument reference list, you can access the following attribute references after your data source is created. - `pvm_snapshots` - The list of Power Virtual Machine instance snapshots.