Recently I took over a terraform & terragrunt project a previous person worked on, and unfortunately I can not get it to work properly, meaning that the terragrunt inputs are totally ignored by terraform.
TERRAFORM_VERSION: 1.2.8
TERRAGRUNT_VERSION: 0.38.8
Here is the folder structure:
tf
├── terraform
│ └── aws
│ ├── modules
│ │ └── testapp
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ └── provider.tf
│ └── resources
│ └── testapp
│ ├── main.tf
│ └── variables.tf
└── terragrunt
├── env
│ └── test
│ ├── env.yaml
│ └── testapp
│ └── terragrunt.hcl
└── terragrunt.hcl
Content of files:
terragrunt testapp terragrunt.hcl:
terraform {
source = "/tf/terraform/aws//modules/testapp"
}
include "root" {
path = find_in_parent_folders()
}
locals {
env = yamldecode(file(find_in_parent_folders("env.yaml")))
}
inputs = {
name = "whatever-test"
}
modules testapp main.tf:
module "test" {
source = "/tf/terraform/aws/resources/testapp"
}
resources testapp main.tf:
resource "aws_iam_policy" "test_policy" {
name = "test-${var.name}-policy"
...etc...
}
resources testapp variables.tf:
variable "name" {
type = string
}
When running the apply command, I get the following error, and cant figure out why the variable is ignored:
terragrunt apply --terragrunt-source-update --terragrunt-config /tf/terragrunt/env/test/testapp/terragrunt.hcl
│ Error: Missing required argument
│
│ on main.tf line 1, in module "test":
│ 1: module "test" {
│
│ The argument "name" is required, but no definition was found.
╵
ERRO[0030] Terraform invocation failed in /tf/.terragrunt-cache/EsgHHSh0qo-NO_uijOaMYnlcMZI/bmBahUj5mD_HVKsk-dPyhY4f1cA/modules/testapp prefix=[terragrunt/env/test/testapp]
ERRO[0030] 1 error occurred:
* exit status 1
I dont get why terragrunt source points towards a module file, instead of pointing to the resources, but unfortunately the whole project is done this way, and refactoring it would take a long time and its not on the priority list right now. In this case, what can I do to make terraform see my inputs from terragrunt?
Here is also the content of some of the other files:
terragrunt test env.yaml:
environment: "test-env"
region: "eu-west-1"
terragrunt root terragrunt.hcl:
remote_state {
backend = "s3"
config = {
encrypt = true
region = "eu-west-1"
key = "${path_relative_to_include()}/terraform.tfstate"
bucket = "tf-state"
dynamodb_table = "test-table"
skip_bucket_accesslogging = true
disable_aws_client_checksums = true
s3_bucket_tags = {
name = "test"
}
}
}
A help would be really appreciated with this. Thank you!