-
Notifications
You must be signed in to change notification settings - Fork 160
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
Fix remote state consumers compatibility for Terraform Enterprise #303
Conversation
b7f2a77
to
96352db
Compare
In v0.25.0, a regression was introduced when adding the new remote state consumers feature. Unlike other relationships in the provider - which are serialized in the same original resource document - remote state consumers on a workspace only exist at a separate endpoint which must be read. When the endpoint can't be read in the case of a preexisting Terraform Enterprise installation without the feature, it causes a failure when doing anything with the tfe_workspace resource. An ideal scenario would be for a version check to determine whether a call should be made - but the current tooling here is minimal. Instead, we apply the following heuristic to make it backwards compatible for TFE: If a call to the remote state consumers endpoint fails and is a 404 Not Found, assume that the only plausible reason for it is an old TFE installation: ignore it entirely and set the computed global_remote_state attribute to an implicit 'true' value (which indicates the old behavior which is not configurable until you upgrade your Terraform Enterprise installation). This is reasonable because having reached that point, the primary call to read the workspace succeeded, meaning you are authorized to the workspace and the likelihood of the remote state consumers call failing from a Not Found error for any other reason is exceedingly small.
96352db
to
6539bf5
Compare
Also, make our ability to mock API responses a little bit more extensible so we can test varying API behavior more readily in future.
I'm not sure what the best way to handle this is but I do think indicating that version 0.25.0 isn't compatible with versions of TFE earlier that v20210401 is still useful information. Maybe keeping the changelog the way it was and/or indicating something that explains the bug more in-depth in 0.25.1? Or maybe just adding a notes section to 0.25.1 that explains what the regression was? It seems like something like that might be helpful. |
…t for remote_staet_consumers
The value we are setting manually for the backwards compatibility case (empty remote state consumers) should always be written.
@lafentres Ah yeah, good point, we should make that CHANGELOG entry a little louder. |
Description
In v0.25.0, a regression was introduced when adding the new remote state consumers feature. Unlike other relationships in the provider - which are serialized in the same original resource document - remote state consumers on a workspace only exist at a separate endpoint which must be read. When the endpoint can't be read in the case of a preexisting Terraform Enterprise installation without the feature, it causes a failure when doing anything with the tfe_workspace resource.
An ideal scenario would be for a version check to determine whether a call should be made - but the current tooling here is minimal. Instead, we apply the following heuristic to make it backwards compatible for TFE:
If a call to the remote state consumers endpoint fails and is a 404 Not Found, assume that the only plausible reason for it is an old TFE installation: ignore it entirely and set the computed global_remote_state attribute to an implicit 'true' value (which indicates the old behavior which is not configurable until you upgrade your Terraform Enterprise installation). This is reasonable because having reached that point, the primary call to read the workspace succeeded, meaning you are authorized to the workspace and the likelihood of the remote state consumers call failing from a Not Found error for any other reason is exceedingly small.
Note this proposes a change from what was indicated in de8f3fa (requiring TFE v20210401 to use >=0.25.x of this provider), instead making the change backwards compatible as a bugfix.
Testing plan
Do all of the following with any released Terraform Enterprise version:
global_remote_state = (known after apply)
.terraform plan
after that should result in a happy empty plan.global_remote_state
for both the workspaces should betrue
.global_remote_state = true
to one of the workspaces. Plan it. Should be an empty, no-op plan.global_remote_state = false
. Apply it. This will succeed, but be ignored - a plan afterward should again try to suggest to change it to true. This is expected behavior. You cannot change the behavior of this (faux) attribute in TFE < v20210401.Before continuing, "upgrade" your Terraform Enterprise installation to the v202104-1 release. (For external contributors: Note that as of this writing, this Terraform Enterprise version has not yet been released).
terraform plan
. This should result in an empty, happy plan.