From 20f89f5b1644d6813bdee8cb4bb8492fab872299 Mon Sep 17 00:00:00 2001 From: ismirlia <90468712+ismirlia@users.noreply.github.com> Date: Fri, 11 Oct 2024 12:06:36 -0500 Subject: [PATCH] [D] Add datacenter capability details. (#5666) Co-authored-by: michaelkad --- .../power/data_source_ibm_pi_datacenter.go | 162 ++++++++++++++++++ .../power/data_source_ibm_pi_datacenters.go | 115 +++++++++++++ ibm/service/power/ibm_pi_constants.go | 8 + website/docs/d/pi_datacenter.html.markdown | 42 ++++- website/docs/d/pi_datacenters.html.markdown | 46 ++++- 5 files changed, 365 insertions(+), 8 deletions(-) diff --git a/ibm/service/power/data_source_ibm_pi_datacenter.go b/ibm/service/power/data_source_ibm_pi_datacenter.go index 1dd2643f27..4bbb2f969e 100644 --- a/ibm/service/power/data_source_ibm_pi_datacenter.go +++ b/ibm/service/power/data_source_ibm_pi_datacenter.go @@ -7,6 +7,7 @@ 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/IBM-Cloud/terraform-provider-ibm/ibm/flex" "github.com/hashicorp/go-uuid" @@ -28,6 +29,115 @@ func DataSourceIBMPIDatacenter() *schema.Resource { }, // Attributes + Attr_CapabilityDetails: { + Computed: true, + Description: "Additional Datacenter Capability Details.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + Attr_DisasterRecovery: { + Computed: true, + Description: "Disaster Recovery Information.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + Attr_AsynchronousReplication: { + Computed: true, + Description: "Asynchronous Replication Target Information.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + Attr_Enabled: { + Computed: true, + Description: "Service Enabled.", + Type: schema.TypeBool, + }, + Attr_TargetLocations: { + Computed: true, + Description: "List of all replication targets.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + Attr_Region: { + Computed: true, + Description: "regionZone of replication site.", + Type: schema.TypeString, + }, + Attr_Status: { + Computed: true, + Description: "the replication site is active / down.", + Type: schema.TypeString, + }, + }, + }, + Type: schema.TypeList, + }, + }, + }, + Type: schema.TypeList, + }, + Attr_SynchronousReplication: { + Computed: true, + Description: "Synchronous Replication Target Information.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + Attr_Enabled: { + Type: schema.TypeBool, + Computed: true, + Description: "Service Enabled.", + }, + Attr_TargetLocations: { + Computed: true, + Description: "List of all replication targets.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + Attr_Region: { + Computed: true, + Description: "regionZone of replication site.", + Type: schema.TypeString, + }, + Attr_Status: { + Computed: true, + Description: "the replication site is active / down.", + Type: schema.TypeString, + }, + }, + }, + Type: schema.TypeList, + }, + }, + }, + Type: schema.TypeList, + }, + }, + }, + Type: schema.TypeList, + }, + Attr_SupportedSystems: { + Computed: true, + Description: "Datacenter System Types Information.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + Attr_Dedicated: { + Computed: true, + Description: "List of all available dedicated host types.", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Type: schema.TypeList, + }, + Attr_General: { + Computed: true, + Description: "List of all available host types.", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Type: schema.TypeList, + }, + }, + }, + Type: schema.TypeList, + }, + }, + }, + Type: schema.TypeList, + }, Attr_DatacenterCapabilities: { Computed: true, Description: "Datacenter Capabilities.", @@ -87,6 +197,58 @@ func dataSourceIBMPIDatacenterRead(ctx context.Context, d *schema.ResourceData, d.Set(Attr_DatacenterLocation, flex.Flatten(dclocation)) d.Set(Attr_DatacenterStatus, dcData.Status) d.Set(Attr_DatacenterType, dcData.Type) + capabilityDetails := make([]map[string]interface{}, 0, 10) + if dcData.CapabilitiesDetails != nil { + capabilityDetailsMap, err := capabilityDetailsToMap(dcData.CapabilitiesDetails) + if err != nil { + return diag.FromErr(err) + } + capabilityDetails = append(capabilityDetails, capabilityDetailsMap) + } + d.Set(Attr_CapabilityDetails, capabilityDetails) return nil } + +func capabilityDetailsToMap(cd *models.CapabilitiesDetails) (map[string]interface{}, error) { + capabilityDetailsMap := make(map[string]interface{}) + disasterRecoveryMap := disasterRecoveryToMap(cd.DisasterRecovery) + capabilityDetailsMap[Attr_DisasterRecovery] = []map[string]interface{}{disasterRecoveryMap} + + supportedSystemsMap := make(map[string]interface{}) + supportedSystemsMap[Attr_Dedicated] = cd.SupportedSystems.Dedicated + supportedSystemsMap[Attr_General] = cd.SupportedSystems.General + capabilityDetailsMap[Attr_SupportedSystems] = []map[string]interface{}{supportedSystemsMap} + return capabilityDetailsMap, nil +} + +func disasterRecoveryToMap(dr *models.DisasterRecovery) map[string]interface{} { + disasterRecoveryMap := make(map[string]interface{}) + asynchronousReplicationMap := replicationServiceToMap(dr.AsynchronousReplication) + disasterRecoveryMap[Attr_AsynchronousReplication] = []map[string]interface{}{asynchronousReplicationMap} + if dr.SynchronousReplication != nil { + synchronousReplicationMap := replicationServiceToMap(dr.SynchronousReplication) + disasterRecoveryMap[Attr_SynchronousReplication] = []map[string]interface{}{synchronousReplicationMap} + } + + return disasterRecoveryMap +} + +func replicationServiceToMap(rs *models.ReplicationService) map[string]interface{} { + replicationMap := make(map[string]interface{}) + replicationMap[Attr_Enabled] = rs.Enabled + targetLocations := []map[string]interface{}{} + for _, targetLocationsItem := range rs.TargetLocations { + + targetLocationsItemMap := make(map[string]interface{}) + if targetLocationsItem.Region != "" { + targetLocationsItemMap[Attr_Region] = targetLocationsItem.Region + } + if targetLocationsItem.Status != "" { + targetLocationsItemMap[Attr_Status] = targetLocationsItem.Status + } + targetLocations = append(targetLocations, targetLocationsItemMap) + } + replicationMap[Attr_TargetLocations] = targetLocations + return replicationMap +} diff --git a/ibm/service/power/data_source_ibm_pi_datacenters.go b/ibm/service/power/data_source_ibm_pi_datacenters.go index 08059004df..f8d035a6be 100644 --- a/ibm/service/power/data_source_ibm_pi_datacenters.go +++ b/ibm/service/power/data_source_ibm_pi_datacenters.go @@ -24,6 +24,115 @@ func DataSourceIBMPIDatacenters() *schema.Resource { Description: "List of Datacenters", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ + Attr_CapabilityDetails: { + Computed: true, + Description: "Additional Datacenter Capability Details.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + Attr_DisasterRecovery: { + Computed: true, + Description: "Disaster Recovery Information.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + Attr_AsynchronousReplication: { + Computed: true, + Description: "Asynchronous Replication Target Information.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + Attr_Enabled: { + Computed: true, + Description: "Service Enabled.", + Type: schema.TypeBool, + }, + Attr_TargetLocations: { + Computed: true, + Description: "List of all replication targets.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + Attr_Region: { + Computed: true, + Description: "regionZone of replication site.", + Type: schema.TypeString, + }, + Attr_Status: { + Computed: true, + Description: "the replication site is active / down.", + Type: schema.TypeString, + }, + }, + }, + Type: schema.TypeList, + }, + }, + }, + Type: schema.TypeList, + }, + Attr_SynchronousReplication: { + Computed: true, + Description: "Synchronous Replication Target Information.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + Attr_Enabled: { + Type: schema.TypeBool, + Computed: true, + Description: "Service Enabled.", + }, + Attr_TargetLocations: { + Computed: true, + Description: "List of all replication targets.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + Attr_Region: { + Computed: true, + Description: "regionZone of replication site.", + Type: schema.TypeString, + }, + Attr_Status: { + Computed: true, + Description: "the replication site is active / down.", + Type: schema.TypeString, + }, + }, + }, + Type: schema.TypeList, + }, + }, + }, + Type: schema.TypeList, + }, + }, + }, + Type: schema.TypeList, + }, + Attr_SupportedSystems: { + Computed: true, + Description: "Datacenter System Types Information.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + Attr_Dedicated: { + Computed: true, + Description: "List of all available dedicated host types.", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Type: schema.TypeList, + }, + Attr_General: { + Computed: true, + Description: "List of all available host types.", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Type: schema.TypeList, + }, + }, + }, + Type: schema.TypeList, + }, + }, + }, + Type: schema.TypeList, + }, Attr_DatacenterCapabilities: { Computed: true, Description: "Datacenter Capabilities", @@ -73,6 +182,7 @@ func dataSourceIBMPIDatacentersRead(ctx context.Context, d *schema.ResourceData, for _, datacenter := range datacentersData.Datacenters { if datacenter != nil { dc := map[string]interface{}{ + Attr_DatacenterCapabilities: datacenter.Capabilities, Attr_DatacenterHref: datacenter.Href, Attr_DatacenterLocation: map[string]interface{}{ @@ -83,6 +193,11 @@ func dataSourceIBMPIDatacentersRead(ctx context.Context, d *schema.ResourceData, Attr_DatacenterStatus: datacenter.Status, Attr_DatacenterType: datacenter.Type, } + if datacenter.CapabilitiesDetails != nil { + capabilityDetailsMap, _ := capabilityDetailsToMap(datacenter.CapabilitiesDetails) + + dc[Attr_CapabilityDetails] = []map[string]interface{}{capabilityDetailsMap} + } datacenters = append(datacenters, dc) } } diff --git a/ibm/service/power/ibm_pi_constants.go b/ibm/service/power/ibm_pi_constants.go index dee8e2e6b0..d082603e68 100644 --- a/ibm/service/power/ibm_pi_constants.go +++ b/ibm/service/power/ibm_pi_constants.go @@ -120,6 +120,7 @@ const ( Attr_Addresses = "addresses" Attr_AllocatedCores = "allocated_cores" Attr_Architecture = "architecture" + Attr_AsynchronousReplication = "asynchronous_replication" Attr_Auxiliary = "auxiliary" Attr_AuxiliaryChangedVolumeName = "auxiliary_changed_volume_name" Attr_AuxiliaryVolumeName = "auxiliary_volume_name" @@ -131,6 +132,7 @@ const ( Attr_Bootable = "bootable" Attr_BootVolumeID = "boot_volume_id" Attr_Capabilities = "capabilities" + Attr_CapabilityDetails = "capability_details" Attr_Capacity = "capacity" Attr_Certified = "certified" Attr_CIDR = "cidr" @@ -164,6 +166,7 @@ const ( Attr_Datacenters = "datacenters" Attr_DatacenterStatus = "pi_datacenter_status" Attr_DatacenterType = "pi_datacenter_type" + Attr_Dedicated = "dedicated" Attr_Default = "default" Attr_DeleteOnTermination = "delete_on_termination" Attr_DeploymentType = "deployment_type" @@ -171,6 +174,7 @@ const ( Attr_Details = "details" Attr_DhcpID = "dhcp_id" Attr_DhcpManaged = "dhcp_managed" + Attr_DisasterRecovery = "disaster_recovery" Attr_DisasterRecoveryLocations = "disaster_recovery_locations" Attr_DiskFormat = "disk_format" Attr_DiskType = "disk_type" @@ -187,6 +191,7 @@ const ( Attr_FreezeTime = "freeze_time" Attr_FullSystemProfile = "full_system_profile" Attr_Gateway = "gateway" + Attr_General = "general" Attr_GlobalRouting = "global_routing" Attr_GreDestinationAddress = "gre_destination_address" Attr_GreSourceAddress = "gre_source_address" @@ -306,6 +311,7 @@ const ( Attr_RemotePool = "remote_pool" Attr_ReplicationEnabled = "replication_enabled" Attr_ReplicationPoolMap = "replication_pool_map" + Attr_ReplicationServices = "replication_services" Attr_ReplicationSites = "replication_sites" Attr_ReplicationStatus = "replication_status" Attr_ReplicationType = "replication_type" @@ -362,11 +368,13 @@ const ( Attr_StorageTypesCapacity = "storage_types_capacity" Attr_SupportedSystems = "supported_systems" Attr_Synchronized = "synchronized" + Attr_SynchronousReplication = "synchronous_replication" Attr_SystemPoolName = "system_pool_name" Attr_SystemPools = "system_pools" Attr_Systems = "systems" Attr_SysType = "sys_type" Attr_Systype = "systype" + Attr_TargetLocations = "target_locations" Attr_TargetVolumeName = "target_volume_name" Attr_TaskID = "task_id" Attr_TenantID = "tenant_id" diff --git a/website/docs/d/pi_datacenter.html.markdown b/website/docs/d/pi_datacenter.html.markdown index 9ce0e5a12a..1aefd065ec 100644 --- a/website/docs/d/pi_datacenter.html.markdown +++ b/website/docs/d/pi_datacenter.html.markdown @@ -7,22 +7,26 @@ description: |- --- # ibm_pi_datacenter + Retrieve information about a Power Systems Datacenter. ## Example usage + ```terraform data "ibm_pi_datacenter" "datacenter" { pi_datacenter_zone= "dal12" } ``` -**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,13 +35,49 @@ Example usage: ``` ## Argument reference + Review the argument references that you can specify for your data source. - `pi_datacenter_zone` - (Optional, String) Datacenter zone you want to retrieve. If no value is supplied, the `zone` configured within the IBM provider will be utilized. ## Attribute reference + In addition to all argument reference list, you can access the following attribute references after your data source is created. +- `capability_details` - (List) Additional Datacenter Capability Details. + + Nested schema for `capability_details`: + - `disaster_recovery` - (List) Disaster Recovery Information. + + Nested schema for `disaster_recovery`: + - `replication_services`- (List) Replication services. + + Nested schema for `replication_services`: + - `asynchronous_replication` - (List) Asynchronous Replication Target Information. + + Nested schema for `asynchronous_replication`: + - `enabled` - (Boolean) Service Enabled. + - `target_locations` - (List) List of all replication targets. + + Nested schema for `target_locations`: + - `region` - (String) regionZone of replication site. + - `status` - (String) the replication site is `active` or `down`. + - `synchronous_replication` - (List) Synchronous Replication Target Information. + + Nested schema for `synchronous_replication`: + - `enabled` - (Boolean) Service Enabled. + - `target_locations` - (List) List of all replication targets. + + Nested schema for `target_locations`: + - `region` - (String) regionZone of replication site. + - `status` - (String) the replication site is `active` or `down`. + + - `supported_systems` - (List) Datacenter System Types Information. + + Nested schema for `supported_systems`: + - `dedicated` - (List) List of all available dedicated host types. + - `general` - (List) List of all available host types. + - `pi_datacenter_capabilities` - (Map) Datacenter Capabilities. Capabilities are `true` or `false`. Some of `pi_datacenter_capabilities` are: diff --git a/website/docs/d/pi_datacenters.html.markdown b/website/docs/d/pi_datacenters.html.markdown index 6efbda05e9..cbaa14f0ee 100644 --- a/website/docs/d/pi_datacenters.html.markdown +++ b/website/docs/d/pi_datacenters.html.markdown @@ -36,17 +36,49 @@ In addition to all argument reference list, you can access the following attribu - `datacenters` - (List) List of Datacenters Nested schema for `datacenters` + - `capability_details` - (List) Additional Datacenter Capability Details. + + Nested schema for `capability_details`: + - `disaster_recovery` - (List) Disaster Recovery Information. + + Nested schema for `disaster_recovery`: + - `replication_services`- (List) Replication services. + + Nested schema for `replication_services`: + - `asynchronous_replication` - (List) Asynchronous Replication Target Information. + + Nested schema for `asynchronous_replication`: + - `enabled` - (Boolean) Service Enabled. + - `target_locations` - (List) List of all replication targets. + + Nested schema for `target_locations`: + - `region` - (String) regionZone of replication site. + - `status` - (String) the replication site is `active` or `down`. + - `synchronous_replication` - (List) Synchronous Replication Target Information. + + Nested schema for `synchronous_replication`: + - `enabled` - (Boolean) Service Enabled. + - `target_locations` - (List) List of all replication targets. + + Nested schema for `target_locations`: + - `region` - (String) regionZone of replication site. + - `status` - (String) the replication site is `active` or `down`. + + - `supported_systems` - (List) Datacenter System Types Information. + + Nested schema for `supported_systems`: + - `dedicated` - (List) List of all available dedicated host types. + - `general` - (List) List of all available host types. - `pi_datacenter_capabilities` - (Map) Datacenter Capabilities. Capabilities are `true` or `false`. - Some of `pi_datacenter_capabilities` are: - - `cloud-connections`, `disaster-recovery-site`, `metrics`, `power-edge-router`, `power-vpn-connections` - + Some of `pi_datacenter_capabilities` are: + - `cloud-connections`, `disaster-recovery-site`, `metrics`, `power-edge-router`, `power-vpn-connections` - `pi_datacenter_href` - (String) Datacenter href. - `pi_datacenter_location` - (Map) Datacenter location. - Nested schema for `pi_datacenter_location`: - - `region` - (String) Datacenter location region zone. - - `type` - (String) Datacenter location region type. - - `url`- (String) Datacenter location region url. + Nested schema for `pi_datacenter_location`: + - `region` - (String) Datacenter location region zone. + - `type` - (String) Datacenter location region type. + - `url`- (String) Datacenter location region url. - `pi_datacenter_status` - (String) Datacenter status, `active`,`maintenance` or `down`. - `pi_datacenter_type` - (String) Datacenter type, `off-premises` or `on-premises`.