-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_source_cf_asg.go
42 lines (34 loc) · 980 Bytes
/
data_source_cf_asg.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package cloudfoundry
import (
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2"
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/terraform-providers/terraform-provider-cloudfoundry/cloudfoundry/managers"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceAsg() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceAsgRead,
Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
},
},
}
}
func dataSourceAsgRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
session := meta.(*managers.Session)
if session == nil {
return diag.Errorf("client is nil")
}
asgs, _, err := session.ClientV2.GetSecurityGroups(ccv2.FilterByName(d.Get("name").(string)))
if err != nil {
return diag.FromErr(err)
}
if len(asgs) == 0 {
return diag.FromErr(NotFound)
}
d.SetId(asgs[0].GUID)
return nil
}