generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 41
/
data_source_workspace_ouput.go
98 lines (91 loc) · 2.63 KB
/
data_source_workspace_ouput.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package workspace
import (
"context"
"github.com/harness/harness-go-sdk/harness/nextgen"
"github.com/harness/terraform-provider-harness/helpers"
"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 DataSourceWorkspaceOutput() *schema.Resource {
resource := &schema.Resource{
Description: "Data source for retrieving workspace outputs.",
ReadContext: resourceWorkspaceOutputRead,
Importer: helpers.ProjectResourceImporter,
Schema: map[string]*schema.Schema{
"identifier": {
Description: "Identifier of the Workspace.",
Type: schema.TypeString,
Required: true,
},
"org_id": {
Description: "Organization identifier of the organization the workspace resides in.",
Type: schema.TypeString,
Required: true,
},
"project_id": {
Description: "Project identifier of the project the workspace resides in.",
Type: schema.TypeString,
Required: true,
},
"outputs": {
Description: "",
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Description: "Name associated with the output.",
Type: schema.TypeString,
Computed: true,
},
"value": {
Description: "Value of the output.",
Type: schema.TypeString,
Computed: true,
},
"sensitive": {
Description: "Indicates if the output is sensitive.",
Type: schema.TypeBool,
Computed: true,
},
},
},
},
},
}
return resource
}
func resourceWorkspaceOutputRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx)
id := d.Id()
if id == "" {
d.MarkNewResource()
}
resp, httpResp, err := c.WorkspaceApi.WorkspacesListResources(
ctx,
d.Get("org_id").(string),
d.Get("project_id").(string),
d.Get("identifier").(string),
c.AccountId,
)
if err != nil {
return helpers.HandleApiError(err, d, httpResp)
}
readOutputs(d, &resp)
return nil
}
func readOutputs(d *schema.ResourceData, outputsResp *nextgen.IacmResources) {
d.SetId(d.Get("identifier").(string))
d.Set("org_id", d.Get("org_id").(string))
d.Set("project_id", d.Get("project_id").(string))
var outputs []interface{}
for _, o := range *outputsResp.Outputs {
outputs = append(outputs, map[string]interface{}{
"name": o.Name,
"value": o.Value,
"sensitive": o.Sensitive,
})
}
d.Set("outputs", outputs)
}