AWS provider version 4.0.0 issues: How do I lock the version in the Reference Architecture (or Terragrunt for that matter)?
When using `terragrunt` with the Service Catalog, I can't lock the provider version because injecting a `terraform` block with `required_providers` (e.g., via `generate`) results in an error: ``` ╷ │ Error: Duplicate required providers configuration │ │ on provider_version.tf line 3, in terraform: │ 3: required_providers { │ │ A module may have only one required providers configuration. The required │ providers were previously configured at main.tf:11,3-21. ╵ ``` This is especially problematic now that AWS provider version 4.0 is released and it is breaking all the modules. How do I work around this and lock my provider version to 3.x series?
You can work around this by using an [override file](https://www.terraform.io/language/files/override) in the `generate` block. The following `generate` block is confirmed to properly lock the version and work around this error. You can add this to the root `terragrunt.hcl` file to ensure all your modules use the 3.x series of the `aws` provider. ```hcl # Use an override file to lock the provider version, regardless of if required_providers is defined in the modules. generate "provider_version" { path = "provider_version_override.tf" if_exists = "overwrite_terragrunt" contents = <<EOF terraform { required_providers { aws = { source = "hashicorp/aws" version = "~> 3.0" } } } EOF } ``` Note that you may have to remove the `.terraform.lock.hcl` file to ensure `terraform` downloads the proper provider version.