diff --git a/ibm/service/power/data_source_ibm_pi_dhcp.go b/ibm/service/power/data_source_ibm_pi_dhcp.go index b42bbc98dc..621a7e3d49 100644 --- a/ibm/service/power/data_source_ibm_pi_dhcp.go +++ b/ibm/service/power/data_source_ibm_pi_dhcp.go @@ -6,15 +6,12 @@ package power import ( "context" "fmt" - "log" - st "github.com/IBM-Cloud/power-go-client/clients/instance" + "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" ) @@ -22,89 +19,82 @@ func DataSourceIBMPIDhcp() *schema.Resource { return &schema.Resource{ ReadContext: dataSourceIBMPIDhcpRead, Schema: map[string]*schema.Schema{ - - // Required Arguments + // Arguments Arg_CloudInstanceID: { - Type: schema.TypeString, + Description: "The GUID of the service instance associated with an account.", Required: true, + Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, Arg_DhcpID: { - Type: schema.TypeString, + Description: "ID of the DHCP Server.", Required: true, - Description: "The ID of the DHCP Server", + Type: schema.TypeString, }, // Attributes Attr_DhcpID: { - Type: schema.TypeString, Computed: true, - Description: "The ID of the DHCP Server", + Deprecated: "The field is deprecated, use pi_dhcp_id instead.", + Description: "ID of the DHCP Server.", + Type: schema.TypeString, }, - Attr_DhcpLeases: { - Type: schema.TypeList, + Attr_Leases: { Computed: true, - Description: "The list of DHCP Server PVM Instance leases", + Description: "List of DHCP Server PVM Instance leases.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ Attr_DhcpLeaseInstanceIP: { - Type: schema.TypeString, Computed: true, - Description: "The IP of the PVM Instance", + Description: "IP of the PVM Instance.", + Type: schema.TypeString, }, Attr_DhcpLeaseInstanceMac: { - Type: schema.TypeString, Computed: true, - Description: "The MAC Address of the PVM Instance", + Description: "MAC Address of the PVM Instance.", + Type: schema.TypeString, }, }, }, + Type: schema.TypeList, }, Attr_DhcpNetworkID: { - Type: schema.TypeString, Computed: true, - Description: "The ID of the DHCP Server private network", - }, - Attr_DhcpNetworkName: { + Description: "ID of the DHCP Server private network.", Type: schema.TypeString, - Computed: true, - Description: "The name of the DHCP Server private network", }, - Attr_DhcpStatus: { + Attr_NetworkName: { + Computed: true, + Description: "Name of the DHCP Server private network.", Type: schema.TypeString, + }, + Attr_Status: { Computed: true, - Description: "The status of the DHCP Server", + Description: "Status of the DHCP Server.", + Type: schema.TypeString, }, }, } } func dataSourceIBMPIDhcpRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - - // session sess, err := meta.(conns.ClientSession).IBMPISession() if err != nil { return diag.FromErr(err) } - // arguments cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) dhcpID := d.Get(Arg_DhcpID).(string) - - // client - client := st.NewIBMPIDhcpClient(ctx, sess, cloudInstanceID) - - // get dhcp + client := instance.NewIBMPIDhcpClient(ctx, sess, cloudInstanceID) dhcpServer, err := client.Get(dhcpID) if err != nil { log.Printf("[DEBUG] get DHCP failed %v", err) return diag.FromErr(err) } - // set attributes d.SetId(fmt.Sprintf("%s/%s", cloudInstanceID, *dhcpServer.ID)) d.Set(Attr_DhcpID, *dhcpServer.ID) - d.Set(Attr_DhcpStatus, *dhcpServer.Status) + d.Set(Attr_Status, *dhcpServer.Status) if dhcpServer.Network != nil { dhcpNetwork := dhcpServer.Network @@ -112,7 +102,7 @@ func dataSourceIBMPIDhcpRead(ctx context.Context, d *schema.ResourceData, meta i d.Set(Attr_DhcpNetworkID, *dhcpNetwork.ID) } if dhcpNetwork.Name != nil { - d.Set(Attr_DhcpNetworkName, *dhcpNetwork.Name) + d.Set(Attr_NetworkName, *dhcpNetwork.Name) } } @@ -124,7 +114,7 @@ func dataSourceIBMPIDhcpRead(ctx context.Context, d *schema.ResourceData, meta i Attr_DhcpLeaseInstanceMac: *lease.InstanceMacAddress, } } - d.Set(Attr_DhcpLeases, leaseList) + d.Set(Attr_Leases, leaseList) } return nil diff --git a/ibm/service/power/data_source_ibm_pi_dhcp_test.go b/ibm/service/power/data_source_ibm_pi_dhcp_test.go index 8db9170a35..76eecbe42f 100644 --- a/ibm/service/power/data_source_ibm_pi_dhcp_test.go +++ b/ibm/service/power/data_source_ibm_pi_dhcp_test.go @@ -13,7 +13,6 @@ import ( ) func TestAccIBMPIDhcpDataSourceBasic(t *testing.T) { - resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, diff --git a/ibm/service/power/data_source_ibm_pi_dhcps.go b/ibm/service/power/data_source_ibm_pi_dhcps.go index 79c2586dae..02344815c1 100644 --- a/ibm/service/power/data_source_ibm_pi_dhcps.go +++ b/ibm/service/power/data_source_ibm_pi_dhcps.go @@ -7,93 +7,80 @@ import ( "context" "log" - st "github.com/IBM-Cloud/power-go-client/clients/instance" + "github.com/IBM-Cloud/power-go-client/clients/instance" "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" ) -/* -Datasource to get the list of dhcp servers in a power instance -*/ - +// Datasource to list dhcp servers in a power instance func DataSourceIBMPIDhcps() *schema.Resource { - return &schema.Resource{ ReadContext: dataSourceIBMPIDhcpServersRead, Schema: map[string]*schema.Schema{ - - // Required Arguments + // Arguments Arg_CloudInstanceID: { - Type: schema.TypeString, + Description: "The GUID of the service instance associated with an account.", Required: true, + Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, // Attributes Attr_DhcpServers: { - Type: schema.TypeList, Computed: true, - Description: "The list of all the DHCP Servers", + Description: "List of all the DHCP Servers.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ Attr_DhcpID: { - Type: schema.TypeString, Computed: true, - Description: "The ID of the DHCP Server", + Description: "ID of the DHCP Server.", + Type: schema.TypeString, }, Attr_DhcpNetworkID: { - Type: schema.TypeString, Computed: true, - Description: "The ID of the DHCP Server private network", - }, - Attr_DhcpNetworkName: { + Description: "ID of the DHCP Server private network.", Type: schema.TypeString, - Computed: true, - Description: "The name of the DHCP Server private network", }, - Attr_DhcpStatus: { + Attr_NetworkName: { + Computed: true, + Description: "Name of the DHCP Server private network.", Type: schema.TypeString, + }, + Attr_Status: { Computed: true, - Description: "The status of the DHCP Server", + Description: "Status of the DHCP Server.", + Type: schema.TypeString, }, }, }, + Type: schema.TypeList, }, }, } } func dataSourceIBMPIDhcpServersRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - - // session and client sess, err := meta.(conns.ClientSession).IBMPISession() if err != nil { return diag.FromErr(err) } - // arguments cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) - - // client - client := st.NewIBMPIDhcpClient(ctx, sess, cloudInstanceID) - - // get all dhcp + client := instance.NewIBMPIDhcpClient(ctx, sess, cloudInstanceID) dhcpServers, err := client.GetAll() if err != nil { log.Printf("[DEBUG] get all DHCP failed %v", err) return diag.FromErr(err) } - // set attributes servers := make([]map[string]interface{}, 0, len(dhcpServers)) for _, dhcpServer := range dhcpServers { server := map[string]interface{}{ - Attr_DhcpID: *dhcpServer.ID, - Attr_DhcpStatus: *dhcpServer.Status, + Attr_DhcpID: *dhcpServer.ID, + Attr_Status: *dhcpServer.Status, } if dhcpServer.Network != nil { dhcpNetwork := dhcpServer.Network @@ -101,7 +88,7 @@ func dataSourceIBMPIDhcpServersRead(ctx context.Context, d *schema.ResourceData, d.Set(Attr_DhcpNetworkID, *dhcpNetwork.ID) } if dhcpNetwork.Name != nil { - d.Set(Attr_DhcpNetworkName, *dhcpNetwork.Name) + d.Set(Attr_NetworkName, *dhcpNetwork.Name) } } servers = append(servers, server) diff --git a/ibm/service/power/data_source_ibm_pi_dhcps_test.go b/ibm/service/power/data_source_ibm_pi_dhcps_test.go index 84645bae3c..ec787992ea 100644 --- a/ibm/service/power/data_source_ibm_pi_dhcps_test.go +++ b/ibm/service/power/data_source_ibm_pi_dhcps_test.go @@ -13,7 +13,6 @@ import ( ) func TestAccIBMPIDhcpServersDataSourceBasic(t *testing.T) { - resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, diff --git a/ibm/service/power/ibm_pi_constants.go b/ibm/service/power/ibm_pi_constants.go index 11f7a890dc..d564ce2586 100644 --- a/ibm/service/power/ibm_pi_constants.go +++ b/ibm/service/power/ibm_pi_constants.go @@ -109,6 +109,7 @@ const ( Attr_IsActive = "is_active" Attr_Jumbo = "jumbo" Attr_Key = "key" + Attr_KeyCreationDate = "creation_date" Attr_KeyID = "key_id" Attr_KeyName = "name" Attr_Keys = "keys" @@ -290,8 +291,6 @@ const ( Attr_IBMiRDSUsers = "ibmi_rds_users" OS_IBMI = "ibmi" - Arg_PIInstanceSharedProcessorPool = "pi_shared_processor_pool" - PVMInstanceHealthOk = "OK" PVMInstanceHealthWarning = "WARNING" @@ -326,6 +325,7 @@ const ( Attr_PIInstanceSharedProcessorPool = "shared_processor_pool" Attr_PIInstanceSharedProcessorPoolID = "shared_processor_pool_id" + Arg_PIInstanceSharedProcessorPool = "pi_shared_processor_pool" // Placement Group PIPlacementGroupID = "placement_group_id" @@ -411,6 +411,5 @@ const ( PIWorkspaceDatacenter = "pi_datacenter" PIWorkspaceResourceGroup = "pi_resource_group_id" PIWorkspacePlan = "pi_plan" - - PIVirtualOpticalDevice = "pi_virtual_optical_device" + PIVirtualOpticalDevice = "pi_virtual_optical_device" ) diff --git a/website/docs/d/pi_dhcp.html.markdown b/website/docs/d/pi_dhcp.html.markdown index 74a73de098..6cc6f13a5d 100644 --- a/website/docs/d/pi_dhcp.html.markdown +++ b/website/docs/d/pi_dhcp.html.markdown @@ -1,5 +1,4 @@ --- - subcategory: "Power Systems" layout: "ibm" page_title: "IBM: pi_dhcp" @@ -8,11 +7,9 @@ description: |- --- # ibm_pi_dhcp - Retrieve information about a DHCP Server. 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 - ```terraform data "ibm_pi_dhcp" "example" { pi_cloud_instance_id = "" @@ -20,36 +17,35 @@ data "ibm_pi_dhcp" "example" { } ``` +**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" + zone = "lon04" + } + ``` + ## Argument reference Review the argument references that you can specify for your data source. -- `pi_cloud_instance_id` - (Required, String) Cloud Instance ID of a PCloud Instance. -- `pi_dhcp_id` - (Required, String) The ID of the DHCP Server. +- `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. +- `pi_dhcp_id` - (Required, String) ID of the DHCP Server. ## Attribute reference In addition to all argument reference list, you can access the following attribute references after your data source is created. -- `id` - (String) The ID of the DHCP Server. -- `leases` - (List) The list of DHCP Server PVM Instance leases. +- `dhcp_id` - (Deprecated, String) ID of the DHCP Server. +- `leases` - (List) List of DHCP Server PVM Instance leases. Nested scheme for `leases`: - - `instance_ip` - (String) The IP of the PVM Instance. - - `instance_mac` - (String) The MAC Address of the PVM Instance. -- `network_id`- (String) The ID of the DHCP Server private network. -- `network_name` - The name of the DHCP Server private network. -- `status` - (String) The status of the DHCP Server. - -**Note** - -* 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" - } - ``` \ No newline at end of file + - `instance_ip` - (String) IP of the PVM Instance. + - `instance_mac` - (String) MAC Address of the PVM Instance. +- `network` - (String) ID of the DHCP Server private network (deprecated - replaced by `network_id`). +- `network_id`- (String) ID of the DHCP Server private network. +- `network_name` - (String) Name of the DHCP Server private network. +- `status` - (String) Status of the DHCP Server. diff --git a/website/docs/d/pi_dhcps.html.markdown b/website/docs/d/pi_dhcps.html.markdown index 1f0095f1d7..eeb180a553 100644 --- a/website/docs/d/pi_dhcps.html.markdown +++ b/website/docs/d/pi_dhcps.html.markdown @@ -1,5 +1,4 @@ --- - subcategory: "Power Systems" layout: "ibm" page_title: "IBM: pi_dhcps" @@ -8,47 +7,42 @@ description: |- --- # ibm_pi_dhcps - Retrieve information about all DHCP Servers. 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 - ```terraform data "ibm_pi_dhcps" "example" { pi_cloud_instance_id = "" } ``` -## Argument reference +**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" + zone = "lon04" + } + ``` + +## Argument reference Review the argument references that you can specify for your data source. -- `pi_cloud_instance_id` - (Required, String) Cloud Instance ID of a PCloud Instance. +- `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. ## Attribute reference - In addition to all argument reference list, you can access the following attribute references after your data source is created. -- `servers` - (List) The list of all the DHCP Servers. +- `servers` - (List) List of all the DHCP Servers. Nested scheme for `servers`: - - `dhcp_id` - (String) The ID of the DHCP Server. - - `network_id`- (String) The ID of the DHCP Server private network. - - `network_name` - The name of the DHCP Server private network. - - `status` - (String) The status of the DHCP Server. - -**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" - zone = "lon04" - } - ``` \ No newline at end of file + - `dhcp_id` - (String) ID of the DHCP Server. + - `network` - (String) ID of the DHCP Server private network (deprecated - replaced by `network_id`). + - `network_id`- (String) ID of the DHCP Server private network. + - `network_name` - (String) Name of the DHCP Server private network. + - `status` - (String) Status of the DHCP Server.