Skip to content

Commit

Permalink
feat: [CDS-76701]: GitOps App Project mapping resource (#652)
Browse files Browse the repository at this point in the history
* feat: [CDS-76701]: GitOps App Project mapping resource

* fixing the tests

* Adding docs

* fixing docs

* adding examples

* updating the docs and version
  • Loading branch information
manavjot-harness committed Aug 30, 2023
1 parent 28ba6a7 commit 4372e5b
Show file tree
Hide file tree
Showing 12 changed files with 571 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/659.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
harness_platform_gitops_app_project_mapping - GitOps app project mapping for agents resource.
```
29 changes: 29 additions & 0 deletions docs/data-sources/platform_gitops_app_project_mapping.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "harness_platform_gitops_app_project_mapping Data Source - terraform-provider-harness"
subcategory: "Next Gen"
description: |-
Resource for managing Harness GitOps Application Project Mappings.
---

# harness_platform_gitops_app_project_mapping (Data Source)

Resource for managing Harness GitOps Application Project Mappings.



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `account_id` (String) Account identifier of the GitOps agent's Application Project.
- `agent_id` (String) Agent identifier for which the ArgoCD and Harness project mapping is to be created.
- `identifier` (String) Identifier of the GitOps Application Project.
- `org_id` (String) Organization identifier of the GitOps agent's Application Project.
- `project_id` (String) Project identifier of the GitOps agent's Application Project.

### Read-Only

- `argo_project_name` (String) ArgoCD Project Identifier which is to be mapped to the Harness project.
- `id` (String) The ID of this resource.
29 changes: 29 additions & 0 deletions docs/resources/platform_gitops_app_project_mapping.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "harness_platform_gitops_app_project_mapping Resource - terraform-provider-harness"
subcategory: "Next Gen"
description: |-
Resource for managing Harness GitOps Application Project Mappings.
---

# harness_platform_gitops_app_project_mapping (Resource)

Resource for managing Harness GitOps Application Project Mappings.



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `account_id` (String) Account identifier of the GitOps agent's Application Project.
- `agent_id` (String) Agent identifier for which the ArgoCD and Harness project mapping is to be created.
- `argo_project_name` (String) ArgoCD Project Identifier which is to be mapped to the Harness project.
- `org_id` (String) Organization identifier of the GitOps agent's Application Project.
- `project_id` (String) Project identifier of the GitOps agent's Application Project.

### Read-Only

- `id` (String) The ID of this resource.
- `identifier` (String) Identifier of the GitOps Application Project.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
data "harness_platform_gitops_app_project_mapping" "test" {
identifier = "identifier"
account_id = "account_id"
org_id = "organization_id"
project_id = "project_id"
agent_id = "agent_id"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Import a GitOps agent app project mapping
terraform import harness_platform_gitops_app_project_mapping.example <organization_id>/<project_id>/<agent_id>/<appproject_id>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resource "harness_platform_gitops_app_project_mapping" "test" {
account_id = "account_id"
org_id = "organization_id"
project_id = "project_id"
agent_id = "agent_id"
argo_project_name = "argoProjectName"
}
15 changes: 15 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95 h1:KLq8BE0KwCL+mmXnjLWEAOYO+2l2AE4YMmqG1ZpZHBs=
Expand All @@ -12,6 +14,8 @@ github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kd
github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec=
github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw=
github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo=
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs=
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
Expand All @@ -32,6 +36,7 @@ github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYF
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4=
github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E=
github.com/go-git/go-billy/v5 v5.4.1 h1:Uwp5tDRkPr+l/TnbHOQzp+tmJfLceOlbVucgpTz8ix4=
github.com/go-git/go-git/v5 v5.6.1 h1:q4ZRqQl4pR/ZJHc1L5CFjGA1a10u76aV1iC+nh+bHsk=
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
Expand Down Expand Up @@ -96,8 +101,10 @@ github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S
github.com/hashicorp/terraform-svchost v0.1.1/go.mod h1:mNsjQfZyf/Jhz35v6/0LWcv26+X7JPS+buii2c9/ctc=
github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE=
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jhump/protoreflect v1.6.1 h1:4/2yi5LyDPP7nN+Hiird1SAJ6YoxUm13/oxHGRnbPd8=
github.com/jhump/protoreflect v1.6.1/go.mod h1:RZQ/lnuN+zqeRVpQigTwO6o0AJUkxbnSnpuG7toUTG4=
github.com/jinzhu/copier v0.4.0 h1:w3ciUoD19shMCRargcpm0cm91ytaBhDvuRpz1ODO/U8=
Expand All @@ -123,8 +130,10 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mitchellh/cli v1.1.5/go.mod h1:v8+iFts2sPIKUV1ltktPXMCC8fumSKFItNcD2cLtRR4=
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJJ2JqpQmpLJOu07cU=
github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8=
github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0=
Expand All @@ -136,6 +145,7 @@ github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx
github.com/moby/term v0.0.0-20221205130635-1aeaba878587 h1:HfkjXDfhgVaN5rmueG8cL8KKeFNecRCXFhaJ2qZ5SKA=
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA=
github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
Expand All @@ -148,8 +158,10 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/sebdah/goldie v1.0.0/go.mod h1:jXP4hmWywNEwZzhMuv2ccnqTSFpuq8iyQhtQdkkZBH4=
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
Expand Down Expand Up @@ -183,6 +195,7 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/zclconf/go-cty v1.13.2 h1:4GvrUxe/QUDYuJKAav4EYqdM47/kZa672LwmXFmEKT0=
github.com/zclconf/go-cty v1.13.2/go.mod h1:YKQzy/7pZ7iq2jNFzy5go57xdxdWoLLpaEp4u238AE0=
github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
Expand Down Expand Up @@ -286,7 +299,9 @@ google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
3 changes: 3 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
file_store "github.com/harness/terraform-provider-harness/internal/service/platform/file_store"
"github.com/harness/terraform-provider-harness/internal/service/platform/filters"
gitops_agent "github.com/harness/terraform-provider-harness/internal/service/platform/gitops/agent"
gitops_project_mapping "github.com/harness/terraform-provider-harness/internal/service/platform/gitops/app_project"
gitops_applications "github.com/harness/terraform-provider-harness/internal/service/platform/gitops/applications"
gitops_cluster "github.com/harness/terraform-provider-harness/internal/service/platform/gitops/cluster"
gitops_gnupg "github.com/harness/terraform-provider-harness/internal/service/platform/gitops/gnupg"
Expand Down Expand Up @@ -174,6 +175,7 @@ func Provider(version string) func() *schema.Provider {
"harness_platform_gitops_applications": gitops_applications.DataSourceGitopsApplications(),
"harness_platform_gitops_cluster": gitops_cluster.DataSourceGitopsCluster(),
"harness_platform_gitops_gnupg": gitops_gnupg.DataSourceGitopsGnupg(),
"harness_platform_gitops_app_project_mapping": gitops_project_mapping.DatasourceGitopsAppProjectMapping(),
"harness_platform_gitops_repository": gitops_repository.DataSourceGitopsRepository(),
"harness_platform_gitops_repo_cert": gitops_repo_cert.DataSourceGitOpsRepoCert(),
"harness_platform_gitops_repo_cred": gitops_repo_cred.DataSourceGitOpsRepoCred(),
Expand Down Expand Up @@ -275,6 +277,7 @@ func Provider(version string) func() *schema.Provider {
"harness_platform_gitops_applications": gitops_applications.ResourceGitopsApplication(),
"harness_platform_gitops_cluster": gitops_cluster.ResourceGitopsCluster(),
"harness_platform_gitops_gnupg": gitops_gnupg.ResourceGitopsGnupg(),
"harness_platform_gitops_app_project_mapping": gitops_project_mapping.ResourceGitopsAppProjectMapping(),
"harness_platform_gitops_repository": gitops_repository.ResourceGitopsRepositories(),
"harness_platform_gitops_repo_cert": gitops_repo_cert.ResourceGitopsRepoCerts(),
"harness_platform_gitops_repo_cred": gitops_repo_cred.ResourceGitopsRepoCred(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package app_project_test

import (
"fmt"
"github.com/harness/harness-go-sdk/harness/utils"
"github.com/harness/terraform-provider-harness/internal/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"os"
"strings"
"testing"
)

func TestAccDatasourceGitopsAppProjectMapping(t *testing.T) {

id := fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(5))
id = strings.ReplaceAll(id, "_", "")
accountId := os.Getenv("HARNESS_ACCOUNT_ID")
resourceName := "harness_platform_gitops_app_project_mapping.test"
argoProject := "test123"
resource.UnitTest(t, resource.TestCase{
PreCheck: func() { acctest.TestAccPreCheck(t) },
ProviderFactories: acctest.ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccDatasourceGitopsAppProjectMapping(id, accountId, argoProject),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "argo_project_name", argoProject),
resource.TestCheckResourceAttr(resourceName, "org_id", id),
resource.TestCheckResourceAttr(resourceName, "project_id", id),
resource.TestCheckResourceAttr(resourceName, "agent_id", id),
resource.TestCheckResourceAttr(resourceName, "account_id", accountId),
),
},
},
})
}

func testAccDatasourceGitopsAppProjectMapping(agentId string, accountId string, argoProject string) string {
return fmt.Sprintf(`
resource "harness_platform_organization" "test" {
identifier = "%[1]s"
name = "%[1]s"
}
resource "harness_platform_project" "test" {
identifier = "%[1]s"
name = "%[1]s"
org_id = harness_platform_organization.test.id
}
resource "harness_platform_gitops_agent" "test" {
identifier = "%[1]s"
account_id = "%[2]s"
org_id = harness_platform_organization.test.id
project_id = harness_platform_project.test.id
name = "%[1]s"
type = "MANAGED_ARGO_PROVIDER"
metadata {
namespace = "%[1]s"
high_availability = false
}
}
resource "harness_platform_gitops_app_project_mapping" "test" {
depends_on = [harness_platform_gitops_agent.test]
account_id = "%[2]s"
org_id = harness_platform_organization.test.id
project_id = harness_platform_project.test.id
agent_id = "%[1]s"
argo_project_name = "%[3]s"
}
data "harness_platform_gitops_app_project_mapping" test1 {
depends_on = [harness_platform_gitops_app_project_mapping.test]
identifier = harness_platform_gitops_app_project_mapping.test.identifier
org_id = harness_platform_organization.test.id
account_id = "%[2]s"
project_id = harness_platform_project.test.id
agent_id = "%[1]s"
}
`, agentId, accountId, argoProject)
}
Loading

0 comments on commit 4372e5b

Please sign in to comment.