Reputation: 21
I am trying to get the backend.tf created for all sub-folders included in the current project. I have installed terragrunt on my local system
$ which terragrunt
/usr/local/bin/terragrunt
$ terragrunt -version
terragrunt version v0.28.18
Here is my terragrunt.hcl from my parent folder
$ cat /user_folder/user-x/terragrunt.hcl
remote_state {
backend = "gcs"
generate = {
path = "backend.tf"
if_exists = "overwrite_terragrunt"
}
config = {
bucket = "terraform-bucket"
prefix = "${path_relative_to_include()}/user_folder/user-x/terraform.tfstate"
}
}
In my sub-folder /user_folder/user-x/permissions/, I have terragrunt.hcl
$ cat /user_folder/user-x/permissions/terragrunt.hcl
include {
path = find_in_parent_folders()
}
Also I have exported GOOGLE_APPLICATION_CREDENTIALS
with the appropriate JSON.
Now when I execute
$ terragrunt plan --terragrunt-log-level debug --terragrunt-debug
DEBU[0000] Did not find any locals block: skipping evaluation.
DEBU[0000] Running command: terraform --version prefix=[/mylocalpc/git_test_repo/user-x]
DEBU[0000] Terraform version: 0.13.5
DEBU[0000] Reading Terragrunt config file at /mylocalpc/git_test_repo/user-x/terragrunt.hcl
DEBU[0000] Did not find any locals block: skipping evaluation.
DEBU[0000] The file path /mylocalpc/git_test_repo/user-x/backend.tf already exists, but was a previously generated file by terragrunt. Since if_exists for code generation is set to "overwrite_terragrunt", regenerating file.
DEBU[0000] Generated file /mylocalpc/git_test_repo/user-x/backend.tf.
INFO[0000] Debug mode requested: generating debug file terragrunt-debug.tfvars.json in working dir /mylocalpc/git_test_repo/user-x
DEBU[0000] The following variables were detected in the terraform module:
DEBU[0000] [project_name project_owner contact_group project_expiration organization_id location billing_account_id vpc_project_id folder_id gcs_location sa_role shared_vpcs]
DEBU[0000] Variables passed to terraform are located in "/mylocalpc/git_test_repo/user-x/terragrunt-debug.tfvars.json"
DEBU[0000] Run this command to replicate how terraform was invoked:
DEBU[0000] terraform plan -var-file="/mylocalpc/git_test_repo/user-x/terragrunt-debug.tfvars.json" "/mylocalpc/git_test_repo/user-x/"
DEBU[0002] Initializing remote state for the gcs backend prefix=[/mylocalpc/git_test_repo/user-x/]
DEBU[0003] Remote state GCS bucket terraform-bucket does not exist. Attempting to create it prefix=[/mylocalpc/git_test_repo/user-x/]
ERRO[0003] Missing required GCS remote state configuration project
ERRO[0003] Unable to determine underlying exit code, so Terragrunt will exit with error code 1
And the GCS bucket terraform-bucket does exists. Unsure what I'm missing here... looking for kind help
Upvotes: 2
Views: 2217
Reputation: 3227
In my case, I had the cloud storage created. So had to specify skip_bucket_creation
to true
. Check out terragrunt doc for details (search for skip_bucket_creation
).
remote_state {
backend = "gcs"
generate = {
path = "backend.tf"
if_exists = "overwrite_terragrunt"
}
config = {
bucket = "some-bucket"
prefix = "some-prefix"
skip_bucket_creation = true
}
}
Upvotes: 1
Reputation: 546
Because of this:
ERRO[0003] Missing required GCS remote state configuration project
I think you need to run these before you run terragrunt?
gcloud config set project <your project>
gcloud auth application-default login
Upvotes: 3