-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add data provider cf_service_instance
- Loading branch information
1 parent
b5755e7
commit 6273800
Showing
6 changed files
with
97 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package cloudfoundry | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/satori/go.uuid" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/terraform-providers/terraform-provider-cf/cloudfoundry/cfapi" | ||
) | ||
|
||
func dataSourceServiceInstance() *schema.Resource { | ||
|
||
return &schema.Resource{ | ||
|
||
Read: dataSourceServiceInstanceRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
|
||
"name_or_id": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"space": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"name": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"service_plan_id": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"tags": &schema.Schema{ | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceServiceInstanceRead(d *schema.ResourceData, meta interface{}) (err error) { | ||
|
||
session := meta.(*cfapi.Session) | ||
if session == nil { | ||
return fmt.Errorf("client is nil") | ||
} | ||
|
||
sm := session.ServiceManager() | ||
|
||
var ( | ||
name_or_id string | ||
space string | ||
guid string | ||
serviceInstance cfapi.CCServiceInstance | ||
) | ||
|
||
name_or_id = d.Get("name_or_id").(string) | ||
space = d.Get("space").(string) | ||
|
||
isUUID := uuid.FromStringOrNil(name_or_id) | ||
if &isUUID == nil || uuid.Equal(isUUID, uuid.Nil) { | ||
guid, serviceInstance, err = sm.FindServiceInstance(name_or_id, space) | ||
} else { | ||
guid = name_or_id | ||
serviceInstance, err = sm.ReadServiceInstance(name_or_id) | ||
} | ||
if err != nil { | ||
return err | ||
} | ||
|
||
d.SetId(guid) | ||
d.Set("name", serviceInstance.Name) | ||
d.Set("service_plan_id", serviceInstance.ServicePlanGUID) | ||
d.Set("tags", serviceInstance.Tags) | ||
|
||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters