spacelift-io / terraform-provider-spacelift

Terraform provider to interact with Spacelift
MIT License
76 stars 29 forks source link

Terragrunt OpenTofu: reset terraform_version when changing tool #552

Closed truszkowski closed 5 months ago

truszkowski commented 6 months ago

Description of the change

Let's reset the version when we're changing the terragrunt tool.

Step 1 - now we have computed the latest for terraform (1.5.7)

resource spacelift_stack this {
  ...
  terragrunt {
    tool = "TERRAGRUNT_FOSS"
  }
}

Step 2 - we expect the latest for opentofu (1.7.1)

resource spacelift_stack this {
  ...
  terragrunt {
    tool = "OPEN_TOFU"
  }
}

Let's reset terraform_version when we're changing tool and terraform_version is not specified in the config.

Let's also take care of terraform_workflow_tool. It's the same situation. We should reset terraform_version in the case of the tool change.

resource spacelift_stack this {
  ...
  terraform_workflow_tool = "TERRAFORM_FOSS"
  ...
}

into:

resource spacelift_stack this {
  ...
  terraform_workflow_tool = "CUSTOM"
  ...
}

Type of change

Related issues

Fix [#1]()

Checklists

Development

Code review

lorengordon commented 6 months ago

Some interesting overlap here with the issue I opened recently, https://github.com/spacelift-io/terraform-provider-spacelift/issues/540

truszkowski commented 6 months ago

When I changing TERRAFORM_FOSS -> OPEN_TOFU: Screenshot 2024-05-09 at 15 24 27

And it works but produces a warning: Screenshot 2024-05-09 at 15 22 51

I've tried to convince Terraform to ignore/handle that but it didn't work.

truszkowski commented 6 months ago

I've tried to convince Terraform to ignore/handle that but it didn't work.

I thought CustomizeDiff should help, but no. At the stack level, I can't: Screenshot 2024-05-10 at 13 49 05

I could SetNewComputed("terragrunt") but then showed the plan is more misleading Screenshot 2024-05-10 at 13 51 51

So, I'll keep it as is: Screenshot 2024-05-10 at 13 53 46

If we turn on warnings (TF_LOG=warn), we can see the provider silently replaced terraform_version: Screenshot 2024-05-10 at 13 55 08 Screenshot 2024-05-10 at 13 58 25

truszkowski commented 6 months ago

I've also fixed tests ("terraform-default-" prefix).

marcinwyszynski commented 6 months ago

Will it make sense to extend this PR to also fix #547 ? Looks like it's almost the same issue, just with plain Terraform.

peterdeme commented 6 months ago

@truszkowski we merged a fix to the unit tests, can you rebase this? 🙏

truszkowski commented 6 months ago

Will it make sense to extend this PR to also fix #547 ? Looks like it's almost the same issue, just with plain Terraform.

I've made it. So, now, we'll reset terraform_version (if not specified) during terraform_workflow_tool change.