Skip to content

Commit

Permalink
Added input to ibm container data source in order to skip listing bou…
Browse files Browse the repository at this point in the history
…nded services
  • Loading branch information
Jan Feddern committed Nov 20, 2020
1 parent 3180618 commit 3703100
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
34 changes: 23 additions & 11 deletions ibm/data_source_ibm_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,13 @@ func dataSourceIBMContainerCluster() *schema.Resource {
Computed: true,
},

"list_bounded_services": {
Type: schema.TypeBool,
Default: true,
Optional: true,
Description: "If set to false bounded services won't be listed.",
},

ResourceControllerURL: {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -352,19 +359,24 @@ func dataSourceIBMContainerClusterRead(d *schema.ResourceData, meta interface{})
for i, worker := range workerFields {
workers[i] = worker.ID
}
servicesBoundToCluster, err := csAPI.ListServicesBoundToCluster(name, "", targetEnv)
if err != nil {
return fmt.Errorf("Error retrieving services bound to cluster: %s", err)
}

listBoundedServices := d.Get("list_bounded_services").(bool)
boundedServices := make([]map[string]interface{}, 0)
for _, service := range servicesBoundToCluster {
boundedService := make(map[string]interface{})
boundedService["service_name"] = service.ServiceName
boundedService["service_id"] = service.ServiceID
boundedService["service_key_name"] = service.ServiceKeyName
boundedService["namespace"] = service.Namespace
boundedServices = append(boundedServices, boundedService)
if listBoundedServices {
servicesBoundToCluster, err := csAPI.ListServicesBoundToCluster(name, "", targetEnv)
if err != nil {
return fmt.Errorf("Error retrieving services bound to cluster: %s", err)
}
for _, service := range servicesBoundToCluster {
boundedService := make(map[string]interface{})
boundedService["service_name"] = service.ServiceName
boundedService["service_id"] = service.ServiceID
boundedService["service_key_name"] = service.ServiceKeyName
boundedService["namespace"] = service.Namespace
boundedServices = append(boundedServices, boundedService)
}
}

workerPools, err := workerPoolsAPI.ListWorkerPools(name, targetEnv)
if err != nil {
return fmt.Errorf("Error retrieving worker pools of the cluster %s: %s", name, err)
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/container_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ The following arguments are supported:
* `cluster_name_id` - (Deprecated, string) Name of the Cluster
* `name` - (Optional, string) Name or ID of the cluster.
* `alb_type` - (Optional, string) Used to filter the albs based on type. Valid values are `private`, `public` and `all`. The default value is `all`.
* `list_bounded_services` - (Optional, bool) If set to false services which are bound to the cluster are not going to be listed. The default value is `true`.
* `org_guid` - (Deprecated, string) The GUID for the IBM Cloud organization associated with the cluster. You can retrieve the value from the `ibm_org` data source or by running the `ibmcloud iam orgs --guid` command in the [IBM Cloud CLI](https://cloud.ibm.com/docs/cli?topic=cloud-cli-getting-started).
* `space_guid` - (Deprecated, string) The GUID for the IBM Cloud space associated with the cluster. You can retrieve the value from the `ibm_space` data source or by running the `ibmcloud iam space <space-name> --guid` command in the IBM Cloud CLI.
* `account_guid` - (Deprecated, string) The GUID for the IBM Cloud account associated with the cluster. You can retrieve the value from the `ibm_account` data source or by running the `ibmcloud iam accounts` command in the IBM Cloud CLI.
Expand Down

0 comments on commit 3703100

Please sign in to comment.