generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 41
/
data_source_Infrastructure.go
72 lines (60 loc) · 2.13 KB
/
data_source_Infrastructure.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
package infrastructure
import (
"context"
"fmt"
"strings"
"github.com/antihax/optional"
"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 DataSourceInfrastructure() *schema.Resource {
resource := &schema.Resource{
Description: "Data source for retrieving a Harness Infrastructure.",
ReadContext: dataSourceInfrastructureRead,
Schema: map[string]*schema.Schema{
"identifier": {
Description: "identifier of the Infrastructure.",
Type: schema.TypeString,
Required: true,
},
"env_id": {
Description: "environment identifier.",
Type: schema.TypeString,
Required: true,
},
"type": {
Description: fmt.Sprintf("Type of Infrastructure. Valid values are %s.", strings.Join(nextgen.InfrastructureTypeValues, ", ")),
Type: schema.TypeString,
Computed: true,
},
"yaml": {
Description: "Infrastructure YAML",
Type: schema.TypeString,
Computed: true,
},
"deployment_type": {
Description: fmt.Sprintf("Infrastructure deployment type. Valid values are %s.", strings.Join(nextgen.InfrastructureDeploymentypeValues, ", ")),
Type: schema.TypeString,
Computed: true,
},
},
}
helpers.SetProjectLevelDataSourceSchema(resource.Schema)
return resource
}
func dataSourceInfrastructureRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx)
env_id := d.Get("env_id").(string)
resp, httpResp, err := c.InfrastructuresApi.GetInfrastructureList(ctx, c.AccountId, env_id, &nextgen.InfrastructuresApiGetInfrastructureListOpts{
OrgIdentifier: optional.NewString(d.Get("org_id").(string)),
ProjectIdentifier: optional.NewString(d.Get("project_id").(string)),
})
if err != nil {
return helpers.HandleApiError(err, d, httpResp)
}
readInfrastructure(d, &resp.Data.Content[0])
return nil
}