generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 41
/
yaml_config_data_source.go
62 lines (53 loc) · 1.66 KB
/
yaml_config_data_source.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
package yamlconfig
import (
"context"
"github.com/harness/harness-go-sdk/harness/cd/cac"
"github.com/harness/terraform-provider-harness/internal"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func DataSourceYamlConfig() *schema.Resource {
return &schema.Resource{
Description: "Data source for retrieving a yaml config.",
ReadContext: dataSourceYamlConfigRead,
Schema: map[string]*schema.Schema{
"id": {
Description: "Unique identifier of the yaml resource.",
Type: schema.TypeString,
Computed: true,
},
"name": {
Description: "Name of the yaml resource.",
Type: schema.TypeString,
Computed: true,
},
"path": {
Description: "Path to the yaml file.",
Type: schema.TypeString,
Required: true,
},
"app_id": {
Description: "Unique identifier of the application. This is not required for account level resources (i.e. cloud providers, connectors, etc.).",
Type: schema.TypeString,
Optional: true,
},
"content": {
Description: "Content of the yaml file.",
Type: schema.TypeString,
Computed: true,
},
},
}
}
func dataSourceYamlConfigRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
c := meta.(*internal.Session)
app_id := d.Get("app_id").(string)
path := cac.YamlPath(d.Get("path").(string))
entity, err := c.CDClient.ConfigAsCodeClient.FindYamlByPath(app_id, path)
if err != nil {
return diag.FromErr(err)
} else if entity == nil {
return diag.Errorf("yaml config not found at %s", path)
}
return readYamlConfig(d, entity)
}