Skip to content

Commit

Permalink
Expose space guid on the schema to target specific space
Browse files Browse the repository at this point in the history
  • Loading branch information
ashishth09 committed Jun 27, 2017
1 parent 81601fa commit 068aad5
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 3 deletions.
9 changes: 8 additions & 1 deletion ibm/data_source_ibm_service_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ func dataSourceIBMServiceInstance() *schema.Resource {
Required: true,
},

"space_guid": {
Type: schema.TypeString,
Required: true,
Description: "The guid of the space in which the instance is present",
},

"credentials": {
Description: "The service broker-provided credentials to use this service.",
Type: schema.TypeMap,
Expand Down Expand Up @@ -61,7 +67,8 @@ func dataSourceIBMServiceInstanceRead(d *schema.ResourceData, meta interface{})
}
siAPI := cfClient.ServiceInstances()
name := d.Get("name").(string)
inst, err := siAPI.FindByName(name)
spaceGUID := d.Get("space_guid").(string)
inst, err := siAPI.FindByNameInSpace(spaceGUID, name)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions ibm/data_source_ibm_service_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ resource "ibm_service_key" "servicekey" {
data "ibm_service_instance" "testacc_ds_service_instance" {
name = "${ibm_service_instance.service.name}"
space_guid = "${data.ibm_space.spacedata.id}"
}
`, cfOrganization, cfSpace, serviceName, serviceKey)

Expand Down
9 changes: 7 additions & 2 deletions ibm/data_source_ibm_service_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ func dataSourceIBMServiceKey() *schema.Resource {
Type: schema.TypeMap,
Computed: true,
},

"name": {
Description: "The name of the service key",
Type: schema.TypeString,
Expand All @@ -28,6 +27,11 @@ func dataSourceIBMServiceKey() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"space_guid": {
Type: schema.TypeString,
Required: true,
Description: "The guid of the space in which the service instance is present",
},
},
}
}
Expand All @@ -40,8 +44,9 @@ func dataSourceIBMServiceKeyRead(d *schema.ResourceData, meta interface{}) error
siAPI := cfClient.ServiceInstances()
skAPI := cfClient.ServiceKeys()
serviceInstanceName := d.Get("service_instance_name").(string)
spaceGUID := d.Get("space_guid").(string)
name := d.Get("name").(string)
inst, err := siAPI.FindByName(serviceInstanceName)
inst, err := siAPI.FindByNameInSpace(spaceGUID, serviceInstanceName)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions ibm/data_source_ibm_service_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ resource "ibm_service_key" "servicekey" {
data "ibm_service_key" "testacc_ds_service_key" {
name = "${ibm_service_key.servicekey.name}"
service_instance_name = "${ibm_service_instance.service.name}"
space_guid = "${data.ibm_space.spacedata.id}"
}`, cfOrganization, cfSpace, serviceName, serviceKey)

}
8 changes: 8 additions & 0 deletions website/docs/d/service_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ Import the details of an existing IBM service instance from IBM Bluemix as a rea
## Example Usage

```hcl
data "ibm_space" "space" {
org = "example.com"
space = "dev"
}
data "ibm_service_instance" "serviceInstance" {
name = "mycloudantdb"
space_guid = "${data.ibm_space.space.id}"
}
```

Expand All @@ -24,6 +30,8 @@ The following arguments are supported:

* `name` - (Required) The name of the service instance. The value can be retrieved by running the `bx service list` command in the [Bluemix CLI](https://console.ng.bluemix.net/docs/cli/reference/bluemix_cli/index.html#getting-started).

* `space_guid` - (Required, string) The GUID of the space where the service instance exists. The values can be retrieved from data source `ibm_space`.

## Attributes Reference

The following attributes are exported:
Expand Down
7 changes: 7 additions & 0 deletions website/docs/d/service_key.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ Import the details of an existing IBM service key from IBM Bluemix as a read-onl
## Example Usage

```hcl
data "ibm_space" "space" {
org = "example.com"
space = "dev"
}
data "ibm_service_key" "serviceKeydata" {
name = "mycloudantdbKey"
service_instance_name = "mycloudantdb"
space_guid = "${data.ibm_space.space.id}"
}
```

Expand All @@ -25,6 +31,7 @@ The following arguments are supported:

* `name` - (Required) The name of the service key. The value can be retrieved by running the `bx service keys` command in the [Bluemix CLI](https://console.ng.bluemix.net/docs/cli/reference/bluemix_cli/index.html#getting-started).
* `service_instance_name` - (Required) The name of the service instance that the service key is associated with. The value can be retrieved by running the `bx service list` command in the Bluemix CLI.
* `space_guid` - (Required, string) The GUID of the space where the service instance exists. The values can be retrieved from data source `ibm_space`.

## Attributes Reference

Expand Down

0 comments on commit 068aad5

Please sign in to comment.