generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [CDS-76701]: GitOps App Project mapping resource (#652)
* 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
1 parent
28ba6a7
commit 4372e5b
Showing
12 changed files
with
571 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
7 changes: 7 additions & 0 deletions
7
examples/data-sources/harness_platform_gitops_app_project_mapping/data-source.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
2 changes: 2 additions & 0 deletions
2
examples/resources/harness_platform_gitops_app_project_mapping/import.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
7 changes: 7 additions & 0 deletions
7
examples/resources/harness_platform_gitops_app_project_mapping/resource.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
internal/service/platform/gitops/app_project/datasource_gitops_app_project_mapping.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
81 changes: 81 additions & 0 deletions
81
internal/service/platform/gitops/app_project/datasource_gitops_app_project_mapping_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Oops, something went wrong.