Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Datasource] Add datacenter capability details #5666

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 162 additions & 0 deletions ibm/service/power/data_source_ibm_pi_datacenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.",
Expand Down Expand Up @@ -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
}
115 changes: 115 additions & 0 deletions ibm/service/power/data_source_ibm_pi_datacenters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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{}{
Expand All @@ -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)
}
}
Expand Down
8 changes: 8 additions & 0 deletions ibm/service/power/ibm_pi_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -164,13 +166,15 @@ 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"
Attr_Description = "description"
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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
Loading
Loading