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

Service broker name and guid #234

Merged
merged 4 commits into from
Feb 14, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions cloudfoundry/data_source_cf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ func dataSourceService() *schema.Resource {
Optional: true,
Default: "",
},
"service_broker_guid": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Default: "",
},
"service_broker_name": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"service_plans": &schema.Schema{
Type: schema.TypeMap,
Computed: true,
Expand All @@ -39,13 +48,17 @@ func dataSourceServiceRead(d *schema.ResourceData, meta interface{}) error {

name := d.Get("name").(string)
space := d.Get("space").(string)
serviceBrokerGUID := d.Get("service_broker_guid").(string)

filters := []ccv2.Filter{
ccv2.FilterEqual(constant.LabelFilter, name),
}
if space != "" {
filters = append(filters, ccv2.FilterBySpace(space))
}
if serviceBrokerGUID != "" {
filters = append(filters, ccv2.FilterEqual(constant.ServiceBrokerGUIDFilter, serviceBrokerGUID))
}
services, _, err := session.ClientV2.GetServices(filters...)
if err != nil {
return err
Expand All @@ -55,6 +68,9 @@ func dataSourceServiceRead(d *schema.ResourceData, meta interface{}) error {
}
service := services[0]
d.SetId(service.GUID)
if serviceBrokerGUID == "" {
d.Set("service_broker_name", service.ServiceBrokerName)
}

servicePlans, _, err := session.ClientV2.GetServicePlans(ccv2.FilterEqual(constant.ServiceGUIDFilter, service.GUID))
if err != nil {
Expand Down
14 changes: 13 additions & 1 deletion docs/data-sources/service.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,28 @@ data "cloudfoundry_service" "redis" {
}
```

The following example looks up a service named 'p-redis', registered as a space-scoped service within the specified Space id provided by a specific service broker (its guid is hardcoded here because service brokers are not always visible to non admin users of cloud foundry).

```hcl
data "cloudfoundry_service" "redis" {
name = "p-redis"
space = "${cloudfoundry_space.dev.id}"
service_broker_guid = "5716f06c-b3a2-4e8a-893f-39870b0c9f42"
}
```

## Argument Reference

The following arguments are supported:

* `name` - (Required) The name of the service to look up
* `space` - (Optional) The space within which the service is defined (as a [space-scoped](http://docs.cloudfoundry.org/services/managing-service-brokers.html#register-broker) service)
* `service_broker_guid` - (Optional) The guid of the service broker which offers the service. You can use this to filter two equally named services from different brokers.

## Attributes Reference

The following attributes are exported:

* `id` - The GUID of the service
* `service_plans` - Map of service plan GUIDs keyed by service "<service name>/<plan name>"
* `service_plans` - Map of service plan GUIDs keyed by service "<service name>/<plan name>"
* `service_broker_name` - The name of the service broker that offers the service.