generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 41
/
datasource_gitops_app_project_mapping.go
79 lines (72 loc) · 2.68 KB
/
datasource_gitops_app_project_mapping.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
package app_project
import (
"context"
"github.com/antihax/optional"
hh "github.com/harness/harness-go-sdk/harness/helpers"
"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 DatasourceGitopsAppProjectMapping() *schema.Resource {
resource := &schema.Resource{
Description: "Resource for managing Harness GitOps Application Project Mappings.",
ReadContext: datasourceGitopsAppProjectMappingRead,
Importer: helpers.ProjectResourceImporter,
Schema: map[string]*schema.Schema{
"account_id": {
Description: "Account identifier of the GitOps agent's Application Project.",
Type: schema.TypeString,
Required: true,
},
"org_id": {
Description: "Organization identifier of the GitOps agent's Application Project.",
Type: schema.TypeString,
Required: true,
},
"project_id": {
Description: "Project identifier of the GitOps agent's Application Project.",
Type: schema.TypeString,
Required: true,
},
"agent_id": {
Description: "Agent identifier for which the ArgoCD and Harness project mapping is to be created.",
Type: schema.TypeString,
Required: true,
},
"identifier": {
Description: "Identifier of the GitOps Application Project.",
Type: schema.TypeString,
Required: true,
},
"argo_project_name": {
Description: "ArgoCD Project Identifier which is to be mapped to the Harness project.",
Type: schema.TypeString,
Computed: true,
},
},
}
return resource
}
func datasourceGitopsAppProjectMappingRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx)
ctx = context.WithValue(ctx, nextgen.ContextAccessToken, hh.EnvVars.BearerToken.Get())
agentIdentifier := d.Get("agent_id").(string)
identifier := d.Get("identifier").(string)
resp, httpResp, err := c.ProjectMappingsApi.AppProjectMappingServiceGetAppProjectMappingV2(ctx, agentIdentifier, identifier, &nextgen.ProjectMappingsApiAppProjectMappingServiceGetAppProjectMappingV2Opts{
AccountIdentifier: optional.NewString(c.AccountId),
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)
}
if &resp == nil {
d.SetId("")
d.MarkNewResource()
return nil
}
readAppProjectMapping(d, &resp)
return nil
}