-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_source_cf_stack.go
63 lines (50 loc) · 1.35 KB
/
data_source_cf_stack.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package cloudfoundry
import (
"context"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
"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 dataSourceStack() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceStackRead,
Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
},
"description": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
labelsKey: labelsSchema(),
annotationsKey: annotationsSchema(),
},
}
}
func dataSourceStackRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
session := meta.(*managers.Session)
if session == nil {
return diag.Errorf("client is nil")
}
sm := session.ClientV3
query := ccv3.Query{
Key: ccv3.NameFilter,
Values: []string{d.Get("name").(string)},
}
stacks, _, err := sm.GetStacks(query)
if err != nil {
return diag.FromErr(err)
}
if len(stacks) == 0 {
return diag.FromErr(NotFound)
}
d.SetId(stacks[0].GUID)
d.Set("description", stacks[0].Description)
err = metadataRead(stackMetadata, d, meta, true)
if err != nil {
return diag.FromErr(err)
}
return diag.FromErr(err)
}