-
Notifications
You must be signed in to change notification settings - Fork 154
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
New resource: tfe_workspace_variable_set #537
Conversation
This is more in line with run tasks, which has a similar design
This is similar to how importing workspace run tasks can be imported.
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.
This is awesome!!!
Gonna road-test this real quick. |
a5439b4
to
5d03384
Compare
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.
Caught one straightforward bug with import, and there's that weirdness with the deprecation warning.
And then there's one other thing, which I couldn't chase down to a root cause before quitting time.
- Say you follow the examples where you have:
- One varset resource with no workspace_ids declared.
- A
for_each
'dtfe_workspace_variable_set
working from a set of workspace IDs.
- You apply once, everything's in a stable state.
- You remove one workspace ID from the set and apply again.
- Works as expected, deleting the attachment.
- You do nothing, and apply again.
- Whoa, it detects drift in the state of the varset resource's
workspace_ids
! The state recorded the varset's workspace_ids as including the ID you removed from the attachment resource, which no longer exists in the real infrastructure (as expected, because the apply removed it!).
- Whoa, it detects drift in the state of the varset resource's
- If you apply again, you can see the drift is now resolved.
Note: Objects have changed outside of Terraform
Terraform detected the following changes made outside of Terraform since the last "terraform apply":
# tfe_variable_set.fail has changed
~ resource "tfe_variable_set" "fail" {
id = "varset-HcoqnodMamWSuLvw"
name = "failure"
~ workspace_ids = [
- "ws-Go49bka15DGPyE4b",
# (1 unchanged element hidden)
]
# (2 unchanged attributes hidden)
}
Unless you have made equivalent changes to your configuration, or ignored the relevant attributes using ignore_changes,
the following plan may include actions to undo or respond to these changes.
I'm not sure what to do about that. Strip the workspace_ids out of the state if that argument isn't set? Hmm.
Anyway, see ya Monday.
// Update the config. | ||
log.Printf("[INFO] User = %#v", membership.User) |
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.
?? Seems unrelated, though I guess I'm not against it.
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.
It is. This just looked like developer logging
@@ -80,6 +80,7 @@ func resourceTFEVariableSetCreate(d *schema.ResourceData, meta interface{}) erro | |||
|
|||
if workspaceIDs, workspacesSet := d.GetOk("workspace_ids"); !*options.Global && workspacesSet { | |||
log.Printf("[DEBUG] Apply variable set %s to workspaces %v", name, workspaceIDs) | |||
warnWorkspaceIdsDeprecation() |
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.
I cannot for the life of me get this deprecation warning to fire when I have workspace_ids
set, even by setting TF_LOG=info
or whatever. Any thoughts?
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.
I could not, either, unless I changed the log to say [DEBUG] and set TF_LOG_PROVIDER to DEBUG. I think there must be something wrong with the WARN log level in either the SDK or terraform itself!
--
2022-06-27T10:56:06.615-0600 [DEBUG] provider.terraform-provider-tfe: 2022/06/27 10:56:06 [WARN] Truncating attribute path of 0 diagnostics for TypeSet
2022-06-27T10:56:06.978-0600 [DEBUG] provider.terraform-provider-tfe: 2022/06/27 10:56:06 [DEBUG] Apply variable set Test Varset to workspaces &{0x16cc000 map[3773104766:ws-sdUGzEWvMSs35Rwq] {1 {0 0}}}
2022-06-27T10:56:06.978-0600 [DEBUG] provider.terraform-provider-tfe: 2022/06/27 10:56:06 [DEBUG] The workspace_ids field of tfe_variable_set is deprecated as of release 0.33.0 and may be removed in a future version. The preferred method of associating a variable set to a workspace is by using the tfe_workspace_variable_set resource.
2022-06-27T10:56:07.571-0600 [DEBUG] provider.terraform-provider-tfe: 2022/06/27 10:56:07 [DEBUG] Read configuration of variable set: varset-cMjkscyw39QNSDmW
2022-06-27T10:56:08.332-0600 [DEBUG] provider.terraform-provider-tfe: 2022/06/27 10:56:08 [DEBUG] Create env variable: A_VARIABLE
The question is, do we change this to a DEBUG log or keep it WARN and go looking for the fix upstream?
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.
@nfagerlund maybe we should go with WARN and migrate from log.Print to tflog before the next release.
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.
OK, cool, I think I like that idea. Weird that we haven't run into this WARN issue before???
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.
There are no other warn logs in this repo!
Co-authored-by: Nick Fagerlund <nick.fagerlund@gmail.com>
Co-authored-by: Nick Fagerlund <nick.fagerlund@gmail.com>
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.
We went back to figure out why one of us could repro that drift reporting problem and the other couldn't, and it turned out I was running an old 1.1.x dev version of Terraform and the spurious drift reporting doesn't happen in Terraform 1.2. 🤦 So that was a Terraform bug, and it's fixed. Twist ending!!
With that, I'm feeling good about this PR.
Description
Adds resource to add workspaces to variables sets instead of managing all workspace ids in the variable set resource. This is based on #526, with the following differences:
tfe_variable_set
fieldworkspace_ids
and migrates examples to the new resource.Closes: #467
Testing plan
You can use the config in the website documentation as a starter config. Here are some configs I tested with:
Basic config
Using for_each to apply varsets to tagged workspaces
1. Create some workspaces, some tagged "prod" 2. Apply this config, changing the organization nameAlso try importing using ORGANIZATION/WORKSPACE NAME/VARSET NAME import id
Output from acceptance tests