Skip to content

Commit

Permalink
fix: [CDS-101090]: Deprecate identifier in application resource. (#1071)
Browse files Browse the repository at this point in the history
* fix: [CDS-99290]: Fix repo creds, repos, add some validation

Signed-off-by: Mirko Teodorovic <[email protected]>

* docs

Signed-off-by: Mirko Teodorovic <[email protected]>

* revert

Signed-off-by: Mirko Teodorovic <[email protected]>

* Update platform_gitops_repo_cred.md

* fix: [CDS-101090]: Make identifier not required

Signed-off-by: Mirko Teodorovic <[email protected]>

* fix: [CDS-101090]: Make identifier not required

Signed-off-by: Mirko Teodorovic <[email protected]>

* Update resource_gitops_cluster.go

* Update datasource_gitops_applications.go

* changelog

Signed-off-by: Mirko Teodorovic <[email protected]>

* changelog

Signed-off-by: Mirko Teodorovic <[email protected]>

* changelog

Signed-off-by: Mirko Teodorovic <[email protected]>

---------

Signed-off-by: Mirko Teodorovic <[email protected]>
  • Loading branch information
mteodor authored Sep 26, 2024
1 parent 81e95ba commit e910cdb
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .changelog/1030.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```relese-note:fix
harness_platform_gitops_applications: make identifier deprecated, using name instead which is already required
```
2 changes: 1 addition & 1 deletion docs/data-sources/platform_gitops_applications.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion docs/resources/platform_gitops_applications.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}

Expand All @@ -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)
Expand Down

0 comments on commit e910cdb

Please sign in to comment.