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

gitlab_project_variable: fix nondeterministic reads when using environment_scope #409

Merged
merged 2 commits into from
Sep 15, 2020

Conversation

armsnyder
Copy link
Collaborator

@armsnyder armsnyder commented Sep 12, 2020

Supersedes #324
Fixes #213
Fixes #195
Fixes #278

tl;dr I borrowed just the read function logic from #324 and added the environment_scope filter query to the update and delete functions.

This PR fixes a behavior where gitlab_project_variable resources for keys with multiple environment scopes were not reading data from a unique variable, but could read from any variable with the specified key, causing unexpected drift.

For users with the feature flag on or who are using GitLab 13.4+, this also lets them change environment scopes and remove variables with environment scopes, for gitlab_project_variable resources that have non-unique keys.

Note that one big difference between this and #324 is that I decided to only modify the read function, and not modify the update or delete functions, apart from adding the environment_scope filter query. I thought that those functions as implemented in #324 were not idempotent-safe. I would rather wait for a proper fix from GitLab (see previous paragraph) than try to work around the API in the provider for older GitLab versions. The environment_scope filter query in those functions ensures that people using the feature flag or on future versions of GitLab will have a better time.

I tried using a MigrateState in the schema to handle the ID format change, but it didn't work when I tested it. I ended up with an ID format error. Instead, I have the read function handle both ID formats.

Note that the gitlab/resource_gitlab_project_variable_test.go file is easier to review side-by-side than inline, since I rewrote it from scratch to make sure it was exercising all behaviors.

I've tested this locally with GitLab v13.1 and v13.4 to make sure both versions work.

Incidentally this PR is a step toward #205, by having a destroy test that leaves the GitLab project alone and checks that the resources under test are removed from GitLab.

@armsnyder armsnyder force-pushed the project-variable-scope branch 10 times, most recently from 21db403 to 285ad4e Compare September 12, 2020 03:52
@armsnyder
Copy link
Collaborator Author

@roidelapluie @nicholasklick @sfang97 This is the continuation of #324, which has merge conflicts. I simplified the resource implementation greatly from that PR (see PR description for why). On the other hand the test file is a lot to review, but I wanted to make sure the resource was fully covered. ❤️

@armsnyder armsnyder force-pushed the project-variable-scope branch from 285ad4e to aebe687 Compare September 12, 2020 06:24
@armsnyder armsnyder force-pushed the project-variable-scope branch from aebe687 to a9bcbee Compare September 12, 2020 06:59
website/docs/r/project_variable.html.markdown Outdated Show resolved Hide resolved
gitlab/util.go Outdated Show resolved Hide resolved
- remove indirection to build and parse the resource id
- link to issue in the resource docs
- small test cleanup by making a isGitLabVersionLessThan SkipFunc
@roidelapluie
Copy link
Collaborator

awesome

@nicholasklick
Copy link
Collaborator

nicholasklick commented Sep 14, 2020

@roidelapluie @armsnyder if this is good to go can we merge it?

@armsnyder armsnyder merged commit 68c8c0e into gitlabhq:master Sep 15, 2020
@armsnyder armsnyder deleted the project-variable-scope branch September 15, 2020 01:44
@abelmokadem
Copy link

Any ETA for the release?

@armsnyder
Copy link
Collaborator Author

@abelmokadem Soon™! It's our first time releasing to the Terraform Registry, but we're making progress in the #411 issue.

@@ -12,6 +12,10 @@ This resource allows you to create and manage CI/CD variables for your GitLab pr
For further information on variables, consult the [gitlab
documentation](https://docs.gitlab.com/ce/ci/variables/README.html#variables).

~> **Important:** If your GitLab version is older than 13.4, you may see nondeterministic behavior

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

13.2.0 you mean?

@github-actions github-actions bot locked and limited conversation to collaborators Nov 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
4 participants