Skip to content

Commit

Permalink
Fix for satellite location resource
Browse files Browse the repository at this point in the history
Added zones parameter to immutable list
Added hosts parameter to satellite location data source
  • Loading branch information
anilkumarnagaraj authored and hkantare committed Sep 28, 2021
1 parent 0fe3e6f commit 2c6a92d
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1 deletion.
50 changes: 50 additions & 0 deletions ibm/data_source_ibm_satellite_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
},
},
}
}
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion ibm/resource_ibm_satellite_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
),

Expand Down
18 changes: 18 additions & 0 deletions ibm/structures.go
Original file line number Diff line number Diff line change
Expand Up @@ -2755,6 +2755,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
Expand Down
7 changes: 7 additions & 0 deletions website/docs/d/satellite_location.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 2c6a92d

Please sign in to comment.