From e3d5ef7ebaa99484c423d0d992315be32cf78e06 Mon Sep 17 00:00:00 2001 From: anilkumarnagaraj Date: Fri, 24 Sep 2021 12:31:25 +0530 Subject: [PATCH] Fix for satellite location resource Added zones parameter to immutable list Added hosts parameter to satellite location data source --- ibm/data_source_ibm_satellite_location.go | 50 +++++++++++++++++++ ibm/resource_ibm_satellite_location.go | 2 +- ibm/structures.go | 18 +++++++ .../docs/d/satellite_location.html.markdown | 7 +++ 4 files changed, 76 insertions(+), 1 deletion(-) diff --git a/ibm/data_source_ibm_satellite_location.go b/ibm/data_source_ibm_satellite_location.go index f54f5a2bb1..a0b740b955 100644 --- a/ibm/data_source_ibm_satellite_location.go +++ b/ibm/data_source_ibm_satellite_location.go @@ -93,6 +93,44 @@ func dataSourceIBMSatelliteLocation() *schema.Resource { Computed: true, Sensitive: true, }, + "hosts": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "host_id": { + Type: schema.TypeString, + Computed: true, + }, + "host_name": { + Type: schema.TypeString, + Computed: true, + }, + "cluster_name": { + Type: schema.TypeString, + Computed: true, + }, + "ip_address": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "zone": { + Type: schema.TypeString, + Computed: true, + }, + "host_labels": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + Set: schema.HashString, + }, + }, + }, + }, }, } } @@ -148,6 +186,18 @@ func dataSourceIBMSatelliteLocationRead(d *schema.ResourceData, meta interface{} d.Set("ingress_secret", *instance.Ingress.SecretName) } + getSatHostOptions := &kubernetesserviceapiv1.GetSatelliteHostsOptions{ + Controller: &location, + } + + hostList, response, err := satClient.GetSatelliteHosts(getSatHostOptions) + if err != nil { + return fmt.Errorf("Error retrieving location hosts %s : %s\n%s", location, err, response) + } + if hostList != nil { + d.Set("hosts", flattenSatelliteHosts(hostList)) + } + tags, err := GetTagsUsingCRN(meta, *instance.Crn) if err != nil { log.Printf( diff --git a/ibm/resource_ibm_satellite_location.go b/ibm/resource_ibm_satellite_location.go index 5f93380ae6..70156e44b2 100644 --- a/ibm/resource_ibm_satellite_location.go +++ b/ibm/resource_ibm_satellite_location.go @@ -41,7 +41,7 @@ func resourceIBMSatelliteLocation() *schema.Resource { return resourceTagsCustomizeDiff(diff) }, func(_ context.Context, diff *schema.ResourceDiff, v interface{}) error { - return immutableResourceCustomizeDiff([]string{satLocation, sateLocZone, "resource_group_id"}, diff) + return immutableResourceCustomizeDiff([]string{satLocation, sateLocZone, "resource_group_id", "zones"}, diff) }, ), diff --git a/ibm/structures.go b/ibm/structures.go index 873848ca51..e2ffa766c6 100644 --- a/ibm/structures.go +++ b/ibm/structures.go @@ -2661,6 +2661,24 @@ func flattenSatelliteWorkerPools(list []kubernetesserviceapiv1.GetWorkerPoolResp return workerPools } +func flattenSatelliteHosts(hostList []kubernetesserviceapiv1.MultishiftQueueNode) []map[string]interface{} { + hosts := make([]map[string]interface{}, len(hostList)) + for i, host := range hostList { + l := map[string]interface{}{ + "host_id": *host.ID, + "host_name": *host.Name, + "status": *host.Health.Status, + "ip_address": *host.Assignment.IpAddress, + "cluster_name": *host.Assignment.ClusterName, + "zone": *host.Assignment.Zone, + "host_labels": *&host.Labels, + } + hosts[i] = l + } + + return hosts +} + func flattenWorkerPoolHostLabels(hostLabels map[string]string) *schema.Set { mapped := make([]string, len(hostLabels)) idx := 0 diff --git a/website/docs/d/satellite_location.html.markdown b/website/docs/d/satellite_location.html.markdown index d9a63a459a..dbe1eacad2 100644 --- a/website/docs/d/satellite_location.html.markdown +++ b/website/docs/d/satellite_location.html.markdown @@ -34,6 +34,13 @@ In addition to all argument reference list, you can access the following attribu - `ingress_secret` - (String) The Ingress secret. - `host_attached_count` - (Integer) The total number of hosts that are attached to the Satellite location. - `host_available_count` - (Integer) The available number of hosts that can be assigned to a cluster resource in the Satellite location. +* `hosts`- Collection of hosts in a location + * `host_id`- ID of the host + * `host_name`- Name of the host + * `cluster_name`- Host are used for control plane or ROKS satellite cluster + * `status`- Status of the host + * `zone`- The name of the zone + * `host_labels`- Host Labels - `logging_account_id` - (String) The account ID for IBM Cloud Log Analysis with IBM Cloud Log Analysis log forwarding. - `managed_from` - (String) The IBM Cloud metro from which the Satellite location is managed. To list available multizone regions, run `ibmcloud ks locations`. such as `wdc04`, `wdc06`, or `lon04`. - `resource_group_id` - (String) The ID of the resource group.