diff --git a/ibm/service/power/data_source_ibm_pi_instance.go b/ibm/service/power/data_source_ibm_pi_instance.go index 354cfe951b..9c52d410bf 100644 --- a/ibm/service/power/data_source_ibm_pi_instance.go +++ b/ibm/service/power/data_source_ibm_pi_instance.go @@ -6,260 +6,285 @@ package power import ( "context" + "github.com/IBM-Cloud/power-go-client/clients/instance" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - - "github.com/IBM-Cloud/power-go-client/clients/instance" - "github.com/IBM-Cloud/power-go-client/helpers" - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" ) func DataSourceIBMPIInstance() *schema.Resource { - return &schema.Resource{ ReadContext: dataSourceIBMPIInstancesRead, Schema: map[string]*schema.Schema{ - - helpers.PIInstanceName: { - Type: schema.TypeString, + // Arguments + Arg_CloudInstanceID: { + Description: "The GUID of the service instance associated with an account.", Required: true, - Description: "Server Name to be used for pvminstances", + Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, - - helpers.PICloudInstanceId: { - Type: schema.TypeString, + Arg_InstanceName: { + Description: "The unique identifier or name of the instance.", Required: true, + Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, - // Computed Attributes - "volumes": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - "memory": { - Type: schema.TypeFloat, - Computed: true, - }, - "processors": { - Type: schema.TypeFloat, - Computed: true, - }, - "health_status": { - Type: schema.TypeString, - Computed: true, - }, - "addresses": { - Type: schema.TypeList, - Computed: true, - Deprecated: "This field is deprecated, use networks instead", + // Attributes + Attr_Addresses: { + Computed: true, + Description: "The address associated with this instance.", + Deprecated: "This field is deprecated, use networks instead", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "ip": { - Type: schema.TypeString, - Computed: true, + Attr_ExternalIP: { + Computed: true, + Description: "The external IP address of the instance.", + Type: schema.TypeString, }, - "macaddress": { - Type: schema.TypeString, - Computed: true, + Attr_IP: { + Computed: true, + Description: "The IP address of the instance.", + Type: schema.TypeString, }, - "network_id": { - Type: schema.TypeString, - Computed: true, + Attr_MacAddress: { + Computed: true, + Description: "The MAC address of the instance.", + Type: schema.TypeString, }, - "network_name": { - Type: schema.TypeString, - Computed: true, + Attr_NetworkID: { + Computed: true, + Description: "The network ID of the instance.", + Type: schema.TypeString, }, - "type": { - Type: schema.TypeString, - Computed: true, + Attr_NetworkName: { + Computed: true, + Description: "The network name of the instance.", + Type: schema.TypeString, }, - "external_ip": { - Type: schema.TypeString, - Computed: true, + Attr_Type: { + Computed: true, + Description: "The type of the network.", + Type: schema.TypeString, }, }, }, + Type: schema.TypeList, + }, + Attr_DeploymentType: { + Computed: true, + Description: "The custom deployment type.", + Type: schema.TypeString, + }, + Attr_HealthStatus: { + Computed: true, + Description: "The health of the instance.", + Type: schema.TypeString, + }, + Attr_LicenseRepositoryCapacity: { + Computed: true, + Description: "The VTL license repository capacity TB value.", + Type: schema.TypeInt, }, - "networks": { - Type: schema.TypeList, - Computed: true, + Attr_MaxMem: { + Computed: true, + Description: "The maximum amount of memory that can be allocated to the instance without shutting down or rebooting the LPAR.", + Type: schema.TypeFloat, + }, + Attr_MaxProc: { + Computed: true, + Description: "The maximum number of processors that can be allocated to the instance without shutting down or rebooting the LPAR.", + Type: schema.TypeFloat, + }, + Attr_MaxVirtualCores: { + Computed: true, + Description: "The maximum number of virtual cores that can be assigned without rebooting the instance.", + Type: schema.TypeInt, + }, + Attr_Memory: { + Computed: true, + Description: "The amount of memory that is allocated to the instance.", + Type: schema.TypeFloat, + }, + Attr_MinMem: { + Computed: true, + Description: "The minimum amount of memory that must be allocated to the instance.", + Type: schema.TypeFloat, + }, + Attr_MinProc: { + Computed: true, + Description: "The minimum number of processors that must be allocated to the instance.", + Type: schema.TypeFloat, + }, + Attr_MinVirtualCores: { + Computed: true, + Description: "The minimum number of virtual cores that can be assigned without rebooting the instance.", + Type: schema.TypeInt, + }, + Attr_Networks: { + Computed: true, + Description: "List of networks associated with this instance.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "ip": { - Type: schema.TypeString, - Computed: true, + Attr_ExternalIP: { + Computed: true, + Description: "The external IP address of the instance.", + Type: schema.TypeString, }, - "macaddress": { - Type: schema.TypeString, - Computed: true, + Attr_IP: { + Computed: true, + Description: "The IP address of the instance.", + Type: schema.TypeString, }, - "network_id": { - Type: schema.TypeString, - Computed: true, + Attr_MacAddress: { + Computed: true, + Description: "The MAC address of the instance.", + Type: schema.TypeString, }, - "network_name": { - Type: schema.TypeString, - Computed: true, + Attr_NetworkID: { + Computed: true, + Description: "The network ID of the instance.", + Type: schema.TypeString, }, - "type": { - Type: schema.TypeString, - Computed: true, + Attr_NetworkName: { + Computed: true, + Description: "The network name of the instance.", + Type: schema.TypeString, }, - "external_ip": { - Type: schema.TypeString, - Computed: true, + Attr_Type: { + Computed: true, + Description: "The type of the network.", + Type: schema.TypeString, }, - /*"version": { - Type: schema.TypeFloat, - Computed: true, - },*/ }, }, + Type: schema.TypeList, }, - "proctype": { - Type: schema.TypeString, - Computed: true, + Attr_PinPolicy: { + Computed: true, + Description: "The pinning policy of the instance.", + Type: schema.TypeString, }, - - "status": { - Type: schema.TypeString, - Computed: true, - }, - - "minproc": { - Type: schema.TypeFloat, - Computed: true, + Attr_PlacementGroupID: { + Computed: true, + Description: "The ID of the placement group that the instance is a member.", + Type: schema.TypeString, }, - "minmem": { - Type: schema.TypeFloat, - Computed: true, + Attr_Processors: { + Computed: true, + Description: "The number of processors that are allocated to the instance.", + Type: schema.TypeFloat, }, - "maxproc": { - Type: schema.TypeFloat, - Computed: true, + Attr_ProcType: { + Computed: true, + Description: "The procurement type of the instance. Supported values are shared and dedicated.", + Type: schema.TypeString, }, - "maxmem": { - Type: schema.TypeFloat, - Computed: true, + Attr_SharedProcessorPool: { + Computed: true, + Description: "The name of the shared processor pool for the instance.", + Type: schema.TypeString, }, - "pin_policy": { - Type: schema.TypeString, - Computed: true, + Attr_SharedProcessorPoolID: { + Computed: true, + Description: "The ID of the shared processor pool for the instance.", + Type: schema.TypeString, }, - "virtual_cores_assigned": { - Type: schema.TypeInt, - Computed: true, + Attr_Status: { + Computed: true, + Description: "The status of the instance.", + Type: schema.TypeString, }, - "max_virtual_cores": { - Type: schema.TypeInt, - Computed: true, + Attr_StoragePool: { + Computed: true, + Description: "The storage Pool where server is deployed.", + Type: schema.TypeString, }, - "min_virtual_cores": { - Type: schema.TypeInt, - Computed: true, + Attr_StoragePoolAffinity: { + Computed: true, + Description: "Indicates if all volumes attached to the server must reside in the same storage pool.", + Type: schema.TypeBool, }, - "storage_type": { - Type: schema.TypeString, - Computed: true, + Attr_StorageType: { + Computed: true, + Description: "The storage type where server is deployed.", + Type: schema.TypeString, }, - "storage_pool": { - Type: schema.TypeString, - Computed: true, + Attr_VirtualCoresAssigned: { + Computed: true, + Description: "The virtual cores that are assigned to the instance.", + Type: schema.TypeInt, }, - "storage_pool_affinity": { - Type: schema.TypeBool, - Computed: true, - }, - "license_repository_capacity": { - Type: schema.TypeInt, - Computed: true, - }, - PIPlacementGroupID: { - Type: schema.TypeString, - Computed: true, - }, - "deployment_type": { - Type: schema.TypeString, - Computed: true, - }, - Attr_PIInstanceSharedProcessorPool: { - Type: schema.TypeString, - Computed: true, - }, - Attr_PIInstanceSharedProcessorPoolID: { - Type: schema.TypeString, - Computed: true, + Attr_Volumes: { + Computed: true, + Description: "List of volume IDs that are attached to the instance.", + Elem: &schema.Schema{Type: schema.TypeString}, + Type: schema.TypeList, }, }, } } func dataSourceIBMPIInstancesRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - sess, err := meta.(conns.ClientSession).IBMPISession() - if err != nil { return diag.FromErr(err) } - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) powerC := instance.NewIBMPIInstanceClient(ctx, sess, cloudInstanceID) - powervmdata, err := powerC.Get(d.Get(helpers.PIInstanceName).(string)) - + powervmdata, err := powerC.Get(d.Get(Arg_InstanceName).(string)) if err != nil { return diag.FromErr(err) } pvminstanceid := *powervmdata.PvmInstanceID d.SetId(pvminstanceid) - d.Set("memory", powervmdata.Memory) - d.Set("processors", powervmdata.Processors) - d.Set("status", powervmdata.Status) - d.Set("proctype", powervmdata.ProcType) - d.Set("volumes", powervmdata.VolumeIDs) - d.Set("minproc", powervmdata.Minproc) - d.Set("minmem", powervmdata.Minmem) - d.Set("maxproc", powervmdata.Maxproc) - d.Set("maxmem", powervmdata.Maxmem) - d.Set("pin_policy", powervmdata.PinPolicy) - d.Set("virtual_cores_assigned", powervmdata.VirtualCores.Assigned) - d.Set("max_virtual_cores", powervmdata.VirtualCores.Max) - d.Set("min_virtual_cores", powervmdata.VirtualCores.Min) - d.Set("storage_type", powervmdata.StorageType) - d.Set("storage_pool", powervmdata.StoragePool) - d.Set("storage_pool_affinity", powervmdata.StoragePoolAffinity) - d.Set("license_repository_capacity", powervmdata.LicenseRepositoryCapacity) - d.Set("networks", flattenPvmInstanceNetworks(powervmdata.Networks)) - d.Set("deployment_type", powervmdata.DeploymentType) + d.Set(Attr_DeploymentType, powervmdata.DeploymentType) + d.Set(Attr_LicenseRepositoryCapacity, powervmdata.LicenseRepositoryCapacity) + d.Set(Attr_MaxMem, powervmdata.Maxmem) + d.Set(Attr_MaxProc, powervmdata.Maxproc) + d.Set(Attr_MaxVirtualCores, powervmdata.VirtualCores.Max) + d.Set(Attr_Memory, powervmdata.Memory) + d.Set(Attr_MinMem, powervmdata.Minmem) + d.Set(Attr_MinProc, powervmdata.Minproc) + d.Set(Attr_MinVirtualCores, powervmdata.VirtualCores.Min) + d.Set(Attr_Networks, flattenPvmInstanceNetworks(powervmdata.Networks)) + d.Set(Attr_PinPolicy, powervmdata.PinPolicy) + d.Set(Attr_Processors, powervmdata.Processors) + d.Set(Attr_ProcType, powervmdata.ProcType) + d.Set(Attr_SharedProcessorPool, powervmdata.SharedProcessorPool) + d.Set(Attr_SharedProcessorPoolID, powervmdata.SharedProcessorPoolID) + d.Set(Attr_Status, powervmdata.Status) + d.Set(Attr_StorageType, powervmdata.StorageType) + d.Set(Attr_StoragePool, powervmdata.StoragePool) + d.Set(Attr_StoragePoolAffinity, powervmdata.StoragePoolAffinity) + d.Set(Attr_Volumes, powervmdata.VolumeIDs) + d.Set(Attr_VirtualCoresAssigned, powervmdata.VirtualCores.Assigned) + if *powervmdata.PlacementGroup != "none" { - d.Set(PIPlacementGroupID, powervmdata.PlacementGroup) + d.Set(Attr_PlacementGroupID, powervmdata.PlacementGroup) } - d.Set(Attr_PIInstanceSharedProcessorPool, powervmdata.SharedProcessorPool) - d.Set(Attr_PIInstanceSharedProcessorPoolID, powervmdata.SharedProcessorPoolID) if powervmdata.Addresses != nil { pvmaddress := make([]map[string]interface{}, len(powervmdata.Addresses)) for i, pvmip := range powervmdata.Addresses { p := make(map[string]interface{}) - p["ip"] = pvmip.IPAddress - p["network_name"] = pvmip.NetworkName - p["network_id"] = pvmip.NetworkID - p["macaddress"] = pvmip.MacAddress - p["type"] = pvmip.Type - p["external_ip"] = pvmip.ExternalIP + p[Attr_ExternalIP] = pvmip.ExternalIP + p[Attr_IP] = pvmip.IPAddress + p[Attr_MacAddress] = pvmip.MacAddress + p[Attr_NetworkID] = pvmip.NetworkID + p[Attr_NetworkName] = pvmip.NetworkName + p[Attr_Type] = pvmip.Type pvmaddress[i] = p } - d.Set("addresses", pvmaddress) + d.Set(Attr_Addresses, pvmaddress) } if powervmdata.Health != nil { - d.Set("health_status", powervmdata.Health.Status) + d.Set(Attr_HealthStatus, powervmdata.Health.Status) } return nil 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 daf3590105..1c352395a6 100644 --- a/ibm/service/power/data_source_ibm_pi_instance_test.go +++ b/ibm/service/power/data_source_ibm_pi_instance_test.go @@ -13,7 +13,6 @@ import ( ) func TestAccIBMPIInstanceDataSource_basic(t *testing.T) { - resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, @@ -30,10 +29,8 @@ 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) - + 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) } diff --git a/ibm/service/power/data_source_ibm_pi_instances.go b/ibm/service/power/data_source_ibm_pi_instances.go index a266d9c110..8e1c1f16ba 100644 --- a/ibm/service/power/data_source_ibm_pi_instances.go +++ b/ibm/service/power/data_source_ibm_pi_instances.go @@ -6,160 +6,182 @@ package power import ( "context" + "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/hashicorp/go-uuid" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - - "github.com/IBM-Cloud/power-go-client/clients/instance" - "github.com/IBM-Cloud/power-go-client/helpers" - "github.com/IBM-Cloud/power-go-client/power/models" - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" ) func DataSourceIBMPIInstances() *schema.Resource { - return &schema.Resource{ ReadContext: dataSourceIBMPIInstancesAllRead, Schema: map[string]*schema.Schema{ - helpers.PICloudInstanceId: { - Type: schema.TypeString, + // Arguments + Arg_CloudInstanceID: { + Description: "The GUID of the service instance associated with an account.", Required: true, + Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, - // Computed Attributes - "pvm_instances": { - Type: schema.TypeList, - Computed: true, + // Attributes + Attr_PVMInstances: { + Computed: true, + Description: "List of power virtual server instances for the respective cloud instance.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "pvm_instance_id": { - Type: schema.TypeString, - Computed: true, - }, - "memory": { - Type: schema.TypeFloat, - Computed: true, - }, - "processors": { - Type: schema.TypeFloat, - Computed: true, - }, - "health_status": { - Type: schema.TypeString, - Computed: true, - }, - "networks": { - Type: schema.TypeList, + Attr_HealthStatus: { + Computed: true, + Description: "The health of the instance.", + Type: schema.TypeString, + }, + Attr_LicenseRepositoryCapacity: { + Computed: true, + Description: "The VTL license repository capacity TB value.", + Type: schema.TypeInt, + }, + Attr_MaxMem: { + Computed: true, + Description: "The maximum amount of memory that can be allocated to the instance without shutting down or rebooting the LPAR.", + Type: schema.TypeFloat, + }, + Attr_MaxProc: { + Computed: true, + Description: "The maximum number of processors that can be allocated to the instance without shutting down or rebooting the LPAR.", + Type: schema.TypeFloat, + }, + Attr_MaxVirtualCores: { + Computed: true, + Description: "The maximum number of virtual cores that can be assigned without rebooting the instance.", + Type: schema.TypeInt, + }, + Attr_Memory: { + Computed: true, + Description: "The amount of memory that is allocated to the instance.", + Type: schema.TypeFloat, + }, + Attr_MinMem: { + Computed: true, + Description: "The minimum amount of memory that must be allocated to the instance.", + Type: schema.TypeFloat, + }, + Attr_MinProc: { + Computed: true, + Description: "The minimum number of processors that must be allocated to the instance. ", + Type: schema.TypeFloat, + }, + Attr_MinVirtualCores: { + Computed: true, + Description: "The minimum number of virtual cores that can be assigned without rebooting the instance.", + Type: schema.TypeInt, + }, + Attr_Networks: { Computed: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "ip": { - Type: schema.TypeString, - Computed: true, + Attr_ExternalIP: { + Computed: true, + Description: "The external IP address of the instance.", + Type: schema.TypeString, }, - "macaddress": { - Type: schema.TypeString, - Computed: true, + Attr_IP: { + Computed: true, + Description: "The IP address of the instance.", + Type: schema.TypeString, }, - "network_id": { - Type: schema.TypeString, - Computed: true, + Attr_MacAddress: { + Computed: true, + Description: "The MAC address of the instance.", + Type: schema.TypeString, }, - "network_name": { - Type: schema.TypeString, - Computed: true, + Attr_NetworkID: { + Computed: true, + Description: "The network ID of the instance.", + Type: schema.TypeString, }, - "type": { - Type: schema.TypeString, - Computed: true, + Attr_NetworkName: { + Computed: true, + Description: "The network name of the instance.", + Type: schema.TypeString, }, - "external_ip": { - Type: schema.TypeString, - Computed: true, + Attr_Type: { + Computed: true, + Description: "The type of the network.", + Type: schema.TypeString, }, }, }, - }, - "proctype": { - Type: schema.TypeString, - Computed: true, - }, - - "status": { - Type: schema.TypeString, - Computed: true, - }, - - "minproc": { - Type: schema.TypeFloat, - Computed: true, - }, - "minmem": { - Type: schema.TypeFloat, - Computed: true, - }, - "maxproc": { - Type: schema.TypeFloat, - Computed: true, - }, - "maxmem": { - Type: schema.TypeFloat, - Computed: true, - }, - "pin_policy": { - Type: schema.TypeString, - Computed: true, - }, - "virtual_cores_assigned": { - Type: schema.TypeInt, - Computed: true, - }, - "max_virtual_cores": { - Type: schema.TypeInt, - Computed: true, - }, - "min_virtual_cores": { - Type: schema.TypeInt, - Computed: true, - }, - "storage_type": { - Type: schema.TypeString, - Computed: true, - }, - "storage_pool": { - Type: schema.TypeString, - Computed: true, - }, - "storage_pool_affinity": { - Type: schema.TypeBool, - Computed: true, - }, - "license_repository_capacity": { - Type: schema.TypeInt, - Computed: true, - }, - PIPlacementGroupID: { - Type: schema.TypeString, - Computed: true, + Type: schema.TypeList, + }, + Attr_PinPolicy: { + Computed: true, + Description: "The pinning policy of the instance.", + Type: schema.TypeString, + }, + Attr_PlacementGroupID: { + Computed: true, + Description: "The ID of the placement group that the instance is a member.", + Type: schema.TypeString, + }, + Attr_Processors: { + Computed: true, + Description: "The number of processors that are allocated to the instance.", + Type: schema.TypeFloat, + }, + Attr_ProcType: { + Computed: true, + Description: "The procurement type of the instance. Supported values are shared and dedicated.", + Type: schema.TypeString, + }, + Attr_PVMInstanceID: { + Computed: true, + Description: "The unique identifier of the instance.", + Type: schema.TypeString, + }, + Attr_Status: { + Computed: true, + Description: "The status of the instance.", + Type: schema.TypeString, + }, + Attr_StoragePool: { + Computed: true, + Description: "The storage Pool where server is deployed.", + Type: schema.TypeString, + }, + Attr_StoragePoolAffinity: { + Computed: true, + Description: "Indicates if all volumes attached to the server must reside in the same storage pool.", + Type: schema.TypeBool, + }, + Attr_StorageType: { + Computed: true, + Description: "The storage type where server is deployed.", + Type: schema.TypeString, + }, + Attr_VirtualCoresAssigned: { + Computed: true, + Description: "The virtual cores that are assigned to the instance.", + Type: schema.TypeInt, }, }, }, + Type: schema.TypeList, }, }, } } func dataSourceIBMPIInstancesAllRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - sess, err := meta.(conns.ClientSession).IBMPISession() if err != nil { return diag.FromErr(err) } - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) powerC := instance.NewIBMPIInstanceClient(ctx, sess, cloudInstanceID) powervmdata, err := powerC.GetAll() @@ -170,7 +192,7 @@ func dataSourceIBMPIInstancesAllRead(ctx context.Context, d *schema.ResourceData var clientgenU, _ = uuid.GenerateUUID() d.SetId(clientgenU) - d.Set("pvm_instances", flattenPvmInstances(powervmdata.PvmInstances)) + d.Set(Attr_PVMInstances, flattenPvmInstances(powervmdata.PvmInstances)) return nil } @@ -178,51 +200,49 @@ func dataSourceIBMPIInstancesAllRead(ctx context.Context, d *schema.ResourceData func flattenPvmInstances(list []*models.PVMInstanceReference) []map[string]interface{} { result := make([]map[string]interface{}, 0, len(list)) for _, i := range list { - l := map[string]interface{}{ - "pvm_instance_id": *i.PvmInstanceID, - "memory": *i.Memory, - "processors": *i.Processors, - "proctype": *i.ProcType, - "status": *i.Status, - "minproc": i.Minproc, - "minmem": i.Minmem, - "maxproc": i.Maxproc, - "maxmem": i.Maxmem, - "pin_policy": i.PinPolicy, - "virtual_cores_assigned": i.VirtualCores.Assigned, - "max_virtual_cores": i.VirtualCores.Max, - "min_virtual_cores": i.VirtualCores.Min, - "storage_type": i.StorageType, - "storage_pool": i.StoragePool, - "storage_pool_affinity": i.StoragePoolAffinity, - "license_repository_capacity": i.LicenseRepositoryCapacity, - PIPlacementGroupID: i.PlacementGroup, - "networks": flattenPvmInstanceNetworks(i.Networks), + Attr_LicenseRepositoryCapacity: i.LicenseRepositoryCapacity, + Attr_MaxMem: i.Maxmem, + Attr_MaxProc: i.Maxproc, + Attr_MaxVirtualCores: i.VirtualCores.Max, + Attr_Memory: *i.Memory, + Attr_MinMem: i.Minmem, + Attr_MinProc: i.Minproc, + Attr_MinVirtualCores: i.VirtualCores.Min, + Attr_Networks: flattenPvmInstanceNetworks(i.Networks), + Attr_PinPolicy: i.PinPolicy, + Attr_PlacementGroupID: i.PlacementGroup, + Attr_Processors: *i.Processors, + Attr_ProcType: *i.ProcType, + Attr_PVMInstanceID: *i.PvmInstanceID, + Attr_Status: *i.Status, + Attr_StoragePool: i.StoragePool, + Attr_StoragePoolAffinity: i.StoragePoolAffinity, + Attr_StorageType: i.StorageType, + Attr_VirtualCoresAssigned: i.VirtualCores.Assigned, } if i.Health != nil { - l["health_status"] = i.Health.Status + l[Attr_HealthStatus] = i.Health.Status } result = append(result, l) - } return result } +// TODO: REVIEW THIS ONE func flattenPvmInstanceNetworks(list []*models.PVMInstanceNetwork) (networks []map[string]interface{}) { if list != nil { networks = make([]map[string]interface{}, len(list)) for i, pvmip := range list { - p := make(map[string]interface{}) - p["ip"] = pvmip.IPAddress - p["network_name"] = pvmip.NetworkName - p["network_id"] = pvmip.NetworkID - p["macaddress"] = pvmip.MacAddress - p["type"] = pvmip.Type - p["external_ip"] = pvmip.ExternalIP + p[Attr_ExternalIP] = pvmip.ExternalIP + p[Attr_IP] = pvmip.IPAddress + p[Attr_MacAddress] = pvmip.MacAddress + p[Attr_NetworkID] = pvmip.NetworkID + p[Attr_NetworkName] = pvmip.NetworkName + p[Attr_Type] = pvmip.Type networks[i] = p } return networks diff --git a/ibm/service/power/data_source_ibm_pi_instances_test.go b/ibm/service/power/data_source_ibm_pi_instances_test.go index 7dc19f1e19..f707581ef2 100644 --- a/ibm/service/power/data_source_ibm_pi_instances_test.go +++ b/ibm/service/power/data_source_ibm_pi_instances_test.go @@ -13,7 +13,6 @@ import ( ) func TestAccIBMPIInstancesDataSource_basic(t *testing.T) { - resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, @@ -30,9 +29,7 @@ func TestAccIBMPIInstancesDataSource_basic(t *testing.T) { func testAccCheckIBMPIInstancesDataSourceConfig() string { return fmt.Sprintf(` - - data "ibm_pi_instances" "testacc_ds_instance" { - pi_cloud_instance_id = "%s" - }`, acc.Pi_cloud_instance_id) - + data "ibm_pi_instances" "testacc_ds_instance" { + pi_cloud_instance_id = "%s" + }`, acc.Pi_cloud_instance_id) } diff --git a/website/docs/d/pi_instance.html.markdown b/website/docs/d/pi_instance.html.markdown index 75fecd8d53..67319718e1 100644 --- a/website/docs/d/pi_instance.html.markdown +++ b/website/docs/d/pi_instance.html.markdown @@ -1,5 +1,4 @@ --- - subcategory: "Power Systems" layout: "ibm" page_title: "IBM: pi_instance" @@ -11,7 +10,6 @@ description: |- Retrieve information about a Power Systems Virtual Server instance. For more information, about Power Virtual Server instance, see [getting started with IBM Power Systems Virtual Servers](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-getting-started). ## Example usage - ```terraform data "ibm_pi_instance" "ds_instance" { pi_instance_name = "terraform-test-instance" @@ -20,26 +18,24 @@ data "ibm_pi_instance" "ds_instance" { ``` **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: +- 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" zone = "lon04" } ``` - ## 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 name of the instance. +- `pi_instance_name` - (Required, String) The unique identifier or name of the instance. ## Attribute reference In addition to all argument reference list, you can access the following attribute references after your data source is created. @@ -47,8 +43,8 @@ In addition to all argument reference list, you can access the following attribu - `addresses` - (Deprecated, List of objects) - The address associated with this instance. Nested scheme for `addresses`: - - `ip` - (String) The IP address of the instance. - `external_ip` - (String) The external IP address of the instance. + - `ip` - (String) The IP address of the instance. - `macaddress` - (String) The MAC address of the instance. - `network_id` - (String) The network ID of the instance. - `network_name` - (String) The network name of the instance. @@ -56,23 +52,25 @@ In addition to all argument reference list, you can access the following attribu - `deployment_type` - (String) The custom deployment type. - `health_status` - (String) The health of the instance. - `id` - (String) The unique identifier of the instance. -- `license_repository_capacity` - The VTL license repository capacity TB value. Only available with VTL instances. -- `memory` - (Float) The amount of memory that is allocated to the instance. -- `minproc`- (Float) The minimum number of processors that must be allocated to the instance. +- `license_repository_capacity` - (Integer) The VTL license repository capacity TB value. Only available with VTL instances. +- `maxmem`- (Float) The maximum amount of memory that can be allocated to the instance without shutting down or rebooting the `LPAR`. - `maxproc`- (Float) The maximum number of processors that can be allocated to the instance without shutting down or rebooting the `LPAR`. -- `max_virtual_cores` - (Integer) The maximum value that you increase without a reboot. +- `max_virtual_cores` - (Integer) The maximum number of virtual cores that can be assigned without rebooting the instance. +- `memory` - (Float) The amount of memory that is allocated to the instance. - `minmem`- (Float) The minimum amount of memory that must be allocated to the instance. -- `maxmem`- (Float) The maximum amount of memory that can be allocated to the instance without shutting down or rebooting the `LPAR`. -- `min_virtual_cores` - (Integer) The minimum cores assigned to an instance. -- `networks` - List of objects - The network associated with this instance. +- `minproc`- (Float) The minimum number of processors that must be allocated to the instance. +- `min_virtual_cores` - (Integer) The minimum number of virtual cores that can be assigned without rebooting the instance. +- `networks` - (List) List of networks associated with this instance. Nested scheme for `networks`: - - `ip` - (String) The IP address of the instance. - `external_ip` - (String) The external IP address of the instance. + - `ip` - (String) The IP address of the instance. - `macaddress` - (String) The MAC address of the instance. - `network_id` - (String) The network ID of the instance. - `network_name` - (String) The network name of the instance. - `type` - (String) The type of the network. + +- `pin_policy` - (String) The pinning policy of the instance. - `placement_group_id`- (String) The ID of the placement group that the instance is a member. - `processors` - (Float) The number of processors that are allocated to the instance. - `proctype` - (String) The procurement type of the instance. Supported values are `shared` and `dedicated`. @@ -80,7 +78,7 @@ In addition to all argument reference list, you can access the following attribu - `shared_processor_pool_id` - (String) The ID of the shared processor pool for the instance. - `status` - (String) The status of the instance. - `storage_pool` - (String) The storage Pool where server is deployed. -- `storage_pool_affinity` - (Bool) Indicates if all volumes attached to the server must reside in the same storage pool. +- `storage_pool_affinity` - (Boolean) Indicates if all volumes attached to the server must reside in the same storage pool. - `storage_type` - (String) The storage type where server is deployed. - `virtual_cores_assigned` - (Integer) The virtual cores that are assigned to the instance. -- `volumes` - (List of strings) The list of volume IDs that are attached to the instance. +- `volumes` - (List) List of volume IDs that are attached to the instance. diff --git a/website/docs/d/pi_instances.html.markdown b/website/docs/d/pi_instances.html.markdown index ccd79cee46..3bc6ce9033 100644 --- a/website/docs/d/pi_instances.html.markdown +++ b/website/docs/d/pi_instances.html.markdown @@ -1,5 +1,4 @@ --- - subcategory: "Power Systems" layout: "ibm" page_title: "IBM: pi_instances" @@ -11,7 +10,6 @@ description: |- Retrieve information about all Power Systems Virtual Server instances for the given cloud instance. For more information, about Power Virtual Server instances, see [getting started with IBM Power Systems Virtual Servers](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-getting-started). ## Example usage - ```terraform data "ibm_pi_instances" "ds_instance" { pi_cloud_instance_id = "49fba6c9-23f8-40bc-9899-aca322ee7d5b" @@ -19,20 +17,18 @@ data "ibm_pi_instances" "ds_instance" { ``` **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: +- 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" zone = "lon04" } ``` - ## Argument reference Review the argument references that you can specify for your data source. @@ -42,7 +38,7 @@ Review the argument references that you can specify for your data source. ## Attribute reference In addition to all argument reference list, you can access the following attribute references after your data source is created. -- `pvm_instances` - List of power virtual server instances for respective cloud instance. +- `pvm_instances` - (List) List of power virtual server instances for the respective cloud instance. Nested scheme for `pvm_instances`: - `health_status` - (String) The health of the instance. @@ -50,28 +46,27 @@ In addition to all argument reference list, you can access the following attribu - `memory` - (Float) The amount of memory that is allocated to the instance. - `minproc`- (Float) The minimum number of processors that must be allocated to the instance. - `maxproc`- (Float) The maximum number of processors that can be allocated to the instance without shutting down or rebooting the `LPAR`. - - `max_virtual_cores` - (Integer) The maximum value that you increase without a reboot. + - `max_virtual_cores` - (Integer) The maximum number of virtual cores that can be assigned without rebooting the instance. - `minmem`- (Float) The minimum amount of memory that must be allocated to the instance. - `maxmem`- (Float) The maximum amount of memory that can be allocated to the instance without shutting down or rebooting the `LPAR`. - - `min_virtual_cores` - (Integer) The minimum cores assigned to an instance. - - `networks` - List of objects - The network associated with this instance. + - `min_virtual_cores` - (Integer) The minimum number of virtual cores that can be assigned without rebooting the instance. + - `networks` - (List) List of networks associated with this instance. - Nested scheme for `networks`: - - `ip` - (String) The IP address of the instance. - - `external_ip` - (String) The external IP address of the instance. - - `macaddress` - (String) The MAC address of the instance. - - `network_id` - (String) The network ID of the instance. - - `network_name` - (String) The network name of the instance. - - `type` - (String) The type of the network. + Nested scheme for `networks`: + - `external_ip` - (String) The external IP address of the instance. + - `ip` - (String) The IP address of the instance. + - `macaddress` - (String) The MAC address of the instance. + - `network_id` - (String) The network ID of the instance. + - `network_name` - (String) The network name of the instance. + - `type` - (String) The type of the network. + - `pin_policy` - (String) The pinning policy of the instance. - `placement_group_id`- (String) The ID of the placement group that the instance is a member. - `processors` - (Float) The number of processors that are allocated to the instance. - `proctype` - (String) The procurement type of the instance. Supported values are `shared` and `dedicated`. - `pvm_instance_id` - (String) The unique identifier of the instance. - - `shared_processor_pool`- (String) The name of the shared processor pool for the instance. - - `shared_processor_pool_id` - (String) The ID of the shared processor pool for the instance. - `status` - (String) The status of the instance. - `storage_pool` - (String) The storage Pool where server is deployed. - - `storage_pool_affinity` - (Bool) Indicates if all volumes attached to the server must reside in the same storage pool. + - `storage_pool_affinity` - (Boolean) Indicates if all volumes attached to the server must reside in the same storage pool. - `storage_type` - (String) The storage type where server is deployed. - `virtual_cores_assigned` - (Integer) The virtual cores that are assigned to the instance.