From e910cdbe005cbb368228d110bbd2befa669291ff Mon Sep 17 00:00:00 2001 From: Mirko Teodorovic Date: Thu, 26 Sep 2024 10:10:42 +0200 Subject: [PATCH] fix: [CDS-101090]: Deprecate identifier in application resource. (#1071) * fix: [CDS-99290]: Fix repo creds, repos, add some validation Signed-off-by: Mirko Teodorovic * docs Signed-off-by: Mirko Teodorovic * revert Signed-off-by: Mirko Teodorovic * Update platform_gitops_repo_cred.md * fix: [CDS-101090]: Make identifier not required Signed-off-by: Mirko Teodorovic * fix: [CDS-101090]: Make identifier not required Signed-off-by: Mirko Teodorovic * Update resource_gitops_cluster.go * Update datasource_gitops_applications.go * changelog Signed-off-by: Mirko Teodorovic * changelog Signed-off-by: Mirko Teodorovic * changelog Signed-off-by: Mirko Teodorovic --------- Signed-off-by: Mirko Teodorovic --- .changelog/1030.txt | 3 +++ .../platform_gitops_applications.md | 2 +- .../resources/platform_gitops_applications.md | 3 ++- .../datasource_gitops_applications.go | 3 ++- .../resource_gitops_applications.go | 23 ++++++++++++------- 5 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 .changelog/1030.txt diff --git a/.changelog/1030.txt b/.changelog/1030.txt new file mode 100644 index 000000000..00302c2a0 --- /dev/null +++ b/.changelog/1030.txt @@ -0,0 +1,3 @@ +```relese-note:fix +harness_platform_gitops_applications: make identifier deprecated, using name instead which is already required +``` diff --git a/docs/data-sources/platform_gitops_applications.md b/docs/data-sources/platform_gitops_applications.md index 3c2540cac..7e18fd90c 100644 --- a/docs/data-sources/platform_gitops_applications.md +++ b/docs/data-sources/platform_gitops_applications.md @@ -36,7 +36,7 @@ data "harness_platform_gitops_applications" "example" { ### Optional -- `identifier` (String) Identifier of the GitOps application. +- `identifier` (String, Deprecated) Identifier of the GitOps application. ### Read-Only diff --git a/docs/resources/platform_gitops_applications.md b/docs/resources/platform_gitops_applications.md index 9d99201ff..baf1a4ac0 100644 --- a/docs/resources/platform_gitops_applications.md +++ b/docs/resources/platform_gitops_applications.md @@ -74,7 +74,7 @@ resource "harness_platform_gitops_applications" "example" { ### Optional -- `identifier` (String) Identifier of the GitOps application. +- `identifier` (String, Deprecated) Identifier of the GitOps application. - `kind` (String) Kind of the GitOps application. - `options_remove_existing_finalizers` (Boolean) Options to remove existing finalizers to delete the GitOps application. - `project` (String) The ArgoCD project name corresponding to this GitOps application. An empty string means that the GitOps application belongs to the default project created by Harness. @@ -139,6 +139,7 @@ Optional: Optional: - `destination` (Block List) Information about the GitOps application's destination. (see [below for nested schema](#nestedblock--application--spec--destination)) +- `project` (String) The ArgoCD project name corresponding to this GitOps application. Value must match mappings of ArgoCD projects to harness project. - `source` (Block List) Contains all information about the source of the GitOps application. (see [below for nested schema](#nestedblock--application--spec--source)) - `sync_policy` (Block List) Controls when a sync will be performed in response to updates in git. (see [below for nested schema](#nestedblock--application--spec--sync_policy)) diff --git a/internal/service/platform/gitops/applications/datasource_gitops_applications.go b/internal/service/platform/gitops/applications/datasource_gitops_applications.go index 72c75609c..f9fa944be 100644 --- a/internal/service/platform/gitops/applications/datasource_gitops_applications.go +++ b/internal/service/platform/gitops/applications/datasource_gitops_applications.go @@ -35,6 +35,7 @@ func DataSourceGitopsApplications() *schema.Resource { Description: "Identifier of the GitOps application.", Type: schema.TypeString, Optional: true, + Deprecated: "This field is deprecated and will be removed in a future release.", }, "agent_id": { Description: "Agent identifier of the GitOps application.", @@ -750,7 +751,7 @@ func datasourceGitopsApplicationRead(ctx context.Context, d *schema.ResourceData if attr, ok := d.GetOk("project_id"); ok { projectIdentifier = attr.(string) } - if attr, ok := d.GetOk("identifier"); ok { + if attr, ok := d.GetOk("name"); ok { queryName = attr.(string) } if attr, ok := d.GetOk("repo_id"); ok { diff --git a/internal/service/platform/gitops/applications/resource_gitops_applications.go b/internal/service/platform/gitops/applications/resource_gitops_applications.go index a6e2b8672..d9a075732 100644 --- a/internal/service/platform/gitops/applications/resource_gitops_applications.go +++ b/internal/service/platform/gitops/applications/resource_gitops_applications.go @@ -41,6 +41,11 @@ func ResourceGitopsApplication() *schema.Resource { Description: "Identifier of the GitOps application.", Type: schema.TypeString, Optional: true, + Deprecated: "This field is deprecated and will be removed in a future release.", + DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { + // Implement logic to suppress the diff here + return true + }, }, "agent_id": { Description: "Agent identifier of the GitOps application.", @@ -735,9 +740,12 @@ func resourceGitopsApplicationRead(ctx context.Context, d *schema.ResourceData, if attr, ok := d.GetOk("project_id"); ok { projectIdentifier = attr.(string) } - if attr, ok := d.GetOk("identifier"); ok { + + // name is required, so must exist + if attr, ok := d.GetOk("name"); ok { queryName = attr.(string) } + if attr, ok := d.GetOk("repo_id"); ok { repoIdentifier = attr.(string) } @@ -767,12 +775,12 @@ func resourceGitopsApplicationUpdate(ctx context.Context, d *schema.ResourceData var skipRepoValidation bool var e diag.Diagnostics - if d.HasChange("identifier") { - oldValue, newValue := d.GetChange("identifier") + if d.HasChange("name") { + oldValue, newValue := d.GetChange("name") if oldValue != "" && oldValue != newValue { - e = append(e, diag.Errorf("%s", "Field 'identifier' cannot be updated after creation.")[0]) + e = append(e, diag.Errorf("%s", "Field 'name' cannot be updated after creation.")[0]) } - if err := d.Set("identifier", oldValue); err != nil { + if err := d.Set("name", oldValue); err != nil { return diag.FromErr(err) } } @@ -824,7 +832,7 @@ func resourceGitopsApplicationUpdate(ctx context.Context, d *schema.ResourceData if attr, ok := d.GetOk("agent_id"); ok { agentIdentifier = attr.(string) } - if attr, ok := d.GetOk("identifier"); ok { + if attr, ok := d.GetOk("name"); ok { appMetaDataName = attr.(string) } if attr, ok := d.GetOk("org_id"); ok { @@ -885,7 +893,7 @@ func resourceGitopsApplicationDelete(ctx context.Context, d *schema.ResourceData if attr, ok := d.GetOk("options_remove_existing_finalizers"); ok { optionsRemoveExistingFinalizers = attr.(bool) } - if attr, ok := d.GetOk("identifier"); ok { + if attr, ok := d.GetOk("name"); ok { requestName = attr.(string) } @@ -906,7 +914,6 @@ func resourceGitopsApplicationDelete(ctx context.Context, d *schema.ResourceData func setApplication(d *schema.ResourceData, app *nextgen.Servicev1Application) { d.SetId(app.Name) - d.Set("identifier", app.Name) d.Set("org_id", app.OrgIdentifier) d.Set("project_id", app.ProjectIdentifier) d.Set("agent_id", app.AgentIdentifier)