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.03k stars 972 forks source link

Error Provider already exist #3505

Open mohammed-rahib opened 2 days ago

mohammed-rahib commented 2 days ago

While using public modules (specifically, https://github.com/RaJiska/terraform-aws-fck-nat.git), I'm encountering an error stating that provider.tf already exists and was not generated by Terragrunt.

include "root" {
  path = find_in_parent_folders()
}

terraform {
  source = "tfr:///RaJiska/fck-nat/aws?version=1.3.0"
// source = "https://github.com/RaJiska/terraform-aws-fck-nat.git" 
}

Error recieved

terragrunt init 13:23:43.101 INFO Downloading Terraform configurations from tfr:///RaJiska/fck-nat/aws?version=1.3.0 into ./.terragrunt-cache/7PDGbKpQSS1k8QdM8xNxSXrieYo/8N-KqRI-VyYh5gnNmgyJJ-dzYx4 13:23:44.855 ERROR ERROR: The file path ./.terragrunt-cache/7PDGbKpQSS1k8QdM8xNxSXrieYo/8N-KqRI-VyYh5gnNmgyJJ-dzYx4/provider.tf already exists and was not generated by terragrunt. 13:23:44.857 ERROR Can not generate terraform file: ./.terragrunt-cache/7PDGbKpQSS1k8QdM8xNxSXrieYo/8N-KqRI-VyYh5gnNmgyJJ-dzYx4/provider.tf already exists 13:23:44.858 ERROR Unable to determine underlying exit code, so Terragrunt will exit with error code 1

Versions

Additional context

If I delete the specified provider file from the cache and then run terragrunt init, it works fine, but it doesn't function correctly the first time.

denis256 commented 1 day ago

Hello, the issue you're encountering is most likely due to a conflict between the provider.tf file generated by Terragrunt and the one already present in the source module (RaJiska/terraform-aws-fck-nat). When Terragrunt runs, it attempts to generate its own provider.tf file, but since the module you’re using already includes a provider.tf file, this results in a file conflict.

So change the generated file name or set the disable = true flag for some cases