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

[FEATURE] Add OpenTofu support to Terramate Cloud synchronization #1647

Closed
athak opened this issue Apr 17, 2024 · 4 comments
Closed

[FEATURE] Add OpenTofu support to Terramate Cloud synchronization #1647

athak opened this issue Apr 17, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@athak
Copy link

athak commented Apr 17, 2024

Describe the bug
The Terramate Cloud sync preview in the CLI is always using terraform to show the plan files. When using OpenTofu and there is a version discrepancy between the binaries in the path (e.g. OpenTofu 1.6.x and Terraform 1.5.x) or when there is no Terraform installed, it results in error.

To Reproduce
Run:

terramate run --continue-on-error \
                    --cloud-sync-preview \
                    --cloud-sync-terraform-plan-file=out.tfplan \
                    --debug-preview-url preview_url.txt \
                    -- \
                    tofu plan -out out.tfplan -lock=false

without a terraform binary in the path or with a terraform binary that it is a different version.

Expected behavior
It should use OpenTofu to show the plan files and not result in error.

Log Output
With different versions installed:

2024-04-16T20:07:49-03:00 ERR command stderr action=runTerraformShow command="terraform show -no-color drift.tfplan" planfile=drift.tfplan stack=/x/y/z stderr="\nError: Failed to read the given file as a state or plan file\n\nState read error: Error reading drift.tfplan as a statefile: 2 problems:\n\n- Unsupported state file format: The state file could not be parsed as JSON:\nsyntax error at byte offset 1.\n- Unsupported state file format: The state file does not have a \"version\"\nattribute, which is required to identify the format version.\n\nPlan read error: plan file was created by Terraform 1.6.2, but this is 1.5.7;\nplan files cannot be transferred between different Terraform versions\n"

Without Terraform installed:

024-04-17T18:39:37Z ERR command stderr action=runTerraformShow command="terraform show -no-color out.tfplan" planfile=out.tfplan stack=/x/y/z stderr=
2024-04-17T18:39:37Z WRN failed to synchronize the ASCII plan output error="failed to gather details from plan file: executing: terraform show -no-color out.tfplan" action=getTerraformChangeset planfile=out.tfplan stack=/x/y/z

Environment (please complete the following information):

  • OS: all
  • OS: any
  • Terramate Version: 0.6.2
@athak athak added the bug Something isn't working label Apr 17, 2024
@athak athak changed the title [BUG] Terramate Cloud sync preview is always using Terraform binary Apr 17, 2024
@soerenmartius
Copy link
Contributor

turns out that we always call terraform under the hood when syncing plans to Terramate Cloud. We'll provide a fix soon that will allow you to switch to opentofu using the --opentofu flag to switch to tofu similar to what we've done for terragrunt

@athak
Copy link
Author

athak commented Apr 18, 2024

@soerenmartius sounds great, thanks! Any chance that Terramate can autodetect what binary to use based on the command used for run? You could always override with a flag but from UX point of view it would better IMHO.

@mariux mariux changed the title Terramate Cloud sync preview is always using Terraform binary [FEATURE] Add OpenTofu support to Terramate Cloud synchronization Apr 19, 2024
@soerenmartius
Copy link
Contributor

@soerenmartius sounds great, thanks! Any chance that Terramate can autodetect what binary to use based on the command used for run? You could always override with a flag but from UX point of view it would better IMHO.

good idea, let me discuss this with the team and see what we can come up with

@i4ki
Copy link
Contributor

i4ki commented May 2, 2024

Hey @athak

We released Terramate v0.8.0 last week with support for --tofu-plan-file.

Now your command should be:

terramate run --continue-on-error \
                    --sync-preview \
                    --tofu-plan-file=out.tfplan \
                    --debug-preview-url preview_url.txt \
                    -- \
                    tofu plan -out out.tfplan -lock=false

Let us know if it works for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants