-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
terraform: bugfix: init command when default workspace doesn't exists #5735
terraform: bugfix: init command when default workspace doesn't exists #5735
Conversation
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.
Thanks for your contribution! Can you please add a changelog fragment and update the module's documentation accordingly? Thanks.
This comment was marked as outdated.
This comment was marked as outdated.
Docs Build 📝Thank you for contribution!✨ The docsite for this PR is available for download as an artifact from this run: File changes:
Click to see the diff comparison.NOTE: only file modifications are shown here. New and deleted files are excluded. diff --git a/home/runner/work/community.general/community.general/docsbuild/base/collections/community/general/terraform_module.html b/home/runner/work/community.general/community.general/docsbuild/head/collections/community/general/terraform_module.html
index e7b5a7e..9018185 100644
--- a/home/runner/work/community.general/community.general/docsbuild/base/collections/community/general/terraform_module.html
+++ b/home/runner/work/community.general/community.general/docsbuild/head/collections/community/general/terraform_module.html
@@ -401,7 +401,7 @@ see <a class="reference internal" href="#ansible-collections-community-general-t
<div class="ansibleOptionAnchor" id="parameter-workspace"></div><p class="ansible-option-title" id="ansible-collections-community-general-terraform-module-parameter-workspace"><strong>workspace</strong></p>
<a class="ansibleOptionLink" href="#parameter-workspace" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">string</span></p>
</div></td>
-<td><div class="ansible-option-cell"><p>The terraform workspace to work with.</p>
+<td><div class="ansible-option-cell"><p>The terraform workspace to work with. This sets the <code class="docutils literal notranslate"><span class="pre">TF_WORKSPACE</span></code> environmental variable that is used to override workspace selection. For more information about workspaces have a look at <a class="reference external" href="https://developer.hashicorp.com/terraform/language/state/workspaces">https://developer.hashicorp.com/terraform/language/state/workspaces</a>.</p>
<p class="ansible-option-line"><span class="ansible-option-default-bold">Default:</span> <code class="ansible-option-default docutils literal notranslate"><span class="pre">"default"</span></code></p>
</div></td>
</tr>
|
Thanks, @felixfontein for the feedback. Feel free to let me know if there's anything else I should do. |
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've added two formatting comments. I hope that the module maintainers can take a look at the actual change, as I don't use terraform and are not familiar with the module's logic.
changelogs/fragments/5735-terraform-init-fix-when-default-workspace-doesnt-exists.yaml
Outdated
Show resolved
Hide resolved
changelogs/fragments/5735-terraform-init-fix-when-default-workspace-doesnt-exists.yaml
Outdated
Show resolved
Hide resolved
One question: the changelog claims this is a bugfix, while you write here it is a feature. What exactly is it now? |
I fixed it to Bugfix. Thanks for noticing. |
@dorkamotorka did you maybe forgot to push an update? |
@felixfontein I don't understand what you mean. This PR is ready to get merged, but as far as I understood I should wait for the maintaners approval? |
@dorkamotorka I left several comments on the changelog fragment and documentation above, which you marked as resolved without applying any change. |
This comment was marked as outdated.
This comment was marked as outdated.
@felixfontein hey, sorry for missing that. I think now it should be fine. |
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.
LGTM
Backport to stable-5: 💚 backport PR created✅ Backport PR branch: Backported as #5776 🤖 @patchback |
Backport to stable-6: 💚 backport PR created✅ Backport PR branch: Backported as #5777 🤖 @patchback |
@dorkamotorka thanks for fixing this! |
…d when default workspace doesn't exists (#5777) terraform: bugfix: init command when default workspace doesn't exists (#5735) * feat: init when default workspace doesn't exists * doc: add changelogs fragment and docs update * fix: changelog formating fix (cherry picked from commit fc2b1aa) Co-authored-by: Teodor Janez Podobnik <48418580+dorkamotorka@users.noreply.github.com>
…d when default workspace doesn't exists (#5776) terraform: bugfix: init command when default workspace doesn't exists (#5735) * feat: init when default workspace doesn't exists * doc: add changelogs fragment and docs update * fix: changelog formating fix (cherry picked from commit fc2b1aa) Co-authored-by: Teodor Janez Podobnik <48418580+dorkamotorka@users.noreply.github.com>
Hi lads :) I recently upgraded community.general in one of our project, and I believe this PR didn't solve a bug but actually introduced one: the terraform module is now unable to create workspaces when they do not exist. Initialisation happens on line 498, and this PR includes the workspace right in it, but creation of said workspace only happens on line 503. Hence for our playbooks to work, we now have to manually create workspaces before initialisation. I believe this is both a breaking change and something that is quite contrary to the way Terraform actually works. |
@dorkamotorka could you please take a look at the above message? |
I created a new issue for this: #6101 |
SUMMARY
If the terraform config stores its state on a remote backend, it's possible that there are multiple workspaces to choose from. At the same time, remote backends (e.g. Terraform Cloud) are not required to store a
default
workspace, but one can name and create workspaces as s:he wishes. This is where the Ansible Terraform module has a problem.Line 331: The
terraform init
is called but expects thedefault
workspace to exist. Consequently, it should ask you which of the available workspaces you want to choose (which happens if you doterraform init
from the CLI) - but that obviously doesn't happen in the Ansible (non-interactive) workflow since the-input=false
flag is appended to theterraform init
command.To "avoid" being prompted to choose the workspace and a consequent error, one can choose the Terraform workspace by setting the
TF_WORKSPACE
environmental variable. Since the Ansible Terraform module already has aworkspace
variable I just used it to set theTF_WORKSPACE
.Additionally, my opinion is that we should avoid setting the
TF_WORKSPACE
environmental variable directly in the ansible playbook since it causes confusion about what has precedence in comparison to theworkspace
variable.Line 346:
"current"
workspace gets NEVER appended to the ¨"all"¨ in theworkspace_ctx
which then causes issues on line 493.ISSUE TYPE
COMPONENT NAME
plugins/modules/terraform.py