-
Notifications
You must be signed in to change notification settings - Fork 319
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
Conversation
21db403
to
285ad4e
Compare
@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. ❤️ |
285ad4e
to
aebe687
Compare
aebe687
to
a9bcbee
Compare
- remove indirection to build and parse the resource id - link to issue in the resource docs - small test cleanup by making a isGitLabVersionLessThan SkipFunc
awesome |
@roidelapluie @armsnyder if this is good to go can we merge it? |
Any ETA for the release? |
@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 |
There was a problem hiding this comment.
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?
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. Theenvironment_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.