Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use schema.TypeSet for application sync_policy #228

Merged
merged 5 commits into from
Jan 20, 2023

Conversation

onematchfox
Copy link
Collaborator

This PR changes the type of application.spec.sync_policy.automated and application.spec.sync_policy.retry.backoff from schema.TypeMap to schema.TypeSet.

Motivation:

When using schema.TypeMap it is not possible to define the set of keys required as per the provider SDK docs:

Using the Elem block to define specific keys for the map is currently not possible.

This leads to some subtle issues. For example, if users do not define all keys this will result in a perpetual diff since all keys are stored in state when flattening the resource. This is illustrated in the fix to the tests containing in 913b530.

Additionally, the use of maps prevents us from generating docs for the provider since the keys are not defined.

Impact:

Obviously this is a breaking change to existing consumers of the provider. Although, as illustrated in the documentation updates the upgrade path is a simple one.

resource "argocd_application" "this" {
  ...

    sync_policy {
      automated = {
        prune = true
      }
      retry {
        backoff = {
          max_duration = "2m"
        }
      }
    }
}

would change to

resource "argocd_application" "this" {
   ... 

    sync_policy {
      automated {
        prune = true
      }
      retry {
        backoff {
          max_duration = "2m"
        }
      }
    }
}

Removes the "expected diff" which results from the state containing all 3 map keys whilst the resource definition only defines 2.
`schema.TypeSet` fits these resources better since, as per the [provider SDK docs](https://developer.hashicorp.com/terraform/plugin/sdkv2/schemas/schema-types#typemap):

> Using the Elem block to define specific keys for the map is currently not possible.
@oboukili
Copy link
Collaborator

That's great, using TypeMap at the time was mainly because it allowed for faster iteration (as you can imagine through what you experienced with this PR). Great stuff!
Since it's introducing a breaking change, let's first merge the outstanding PRs.

@oboukili
Copy link
Collaborator

Hi @onematchfox , since the other PRs are in a standby state, feel free to merge and release this as a new major version, since there is a breaking change (make sure to specify this in the release notes). Thanks!

@onematchfox onematchfox merged commit 7ce3476 into argoproj-labs:master Jan 20, 2023
@onematchfox onematchfox deleted the feat/sync-policy branch January 20, 2023 09:30
MrLuje pushed a commit to MrLuje/terraform-provider-argocd that referenced this pull request Apr 23, 2023
* chore: don't clean `.vscode` folder

* build(deps): bump `hashicorp/terraform-plugin-sdk` to `v2.24.1`

* tests: remove duplicate `v` from log message

* tests: add `allow_empty` to ArgoCD simple wait test

Removes the "expected diff" which results from the state containing all 3 map keys whilst the resource definition only defines 2.

* feat!: use set instead of map in  `argocd_application.spec.sync_policy`

`schema.TypeSet` fits these resources better since, as per the [provider SDK docs](https://developer.hashicorp.com/terraform/plugin/sdkv2/schemas/schema-types#typemap):

> Using the Elem block to define specific keys for the map is currently not possible.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants