gruntwork-io / terragrunt

Terragrunt is a flexible orchestration tool that allows Infrastructure as Code written in OpenTofu/Terraform to scale.
https://terragrunt.gruntwork.io/
MIT License
8.01k stars 971 forks source link

Terraform block required version #1298

Open moosahmed opened 4 years ago

moosahmed commented 4 years ago

when not using terragrunt we used to use a terraform block with required version defined, so tfswitch could automatically download and use the terraform to meet the requirement.

Something like this would exist in versions.tf in the directory where the module block is defined and where terraform apply is run.

versions.tf

terraform {
  required_version = "< 0.13"
}

tfswitch would then keep terraform updated for the newest 0.12.X that is available.

How can this be used with terragrunt?

yorinasub17 commented 4 years ago

Does it work if you have a before_hook that calls tfswitch?

mhvelplund commented 3 years ago

Does it work if you have a before_hook that calls tfswitch?

I've tried, but it looks like it tries to find the terraform_binary before it executes hooks. Do you have a working example?

yorinasub17 commented 3 years ago

What error are you seeing? Can you share the logs? Would also help if you can share the before_hook configuration.

Do you have a working example?

We don't use tfswitch so I'm kind of working off the docs here. If I understand how tfswitch works, there should always be a terraform in the PATH that resolves to some version, which may or may not be correct. This should pass the terraform_binary check.

The way the above proposal works is that it will call tfswitch in the before_hook and update that symlink before terragrunt calls it for the actual command. So in theory that should work.

I might be able to provide some more pointers if you can share your config and logs.