配置 terragrunt 的挑战

时间:2021-04-06 21:20:00

标签: terraform terragrunt

我正在尝试为当前项目中包含的所有子文件夹创建 backend.tf。 我已经在本地系统上安装了 terragrunt

   $ which terragrunt
   /usr/local/bin/terragrunt
   $ terragrunt -version
   terragrunt version v0.28.18

这是我的父文件夹中的 terragrunt.hcl

 $ 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"
  }
}

在我的子文件夹 /user_folder/user-x/permissions/ 中,我有 terragrunt.hcl

$ cat  /user_folder/user-x/permissions/terragrunt.hcl
include {
  path = find_in_parent_folders()
}

我还使用适当的 JSON 导出了 GOOGLE_APPLICATION_CREDENTIALS

现在当我执行

$ 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

并且 GCS 存储桶 terraform-b​​ucket 确实存在。 不确定我在这里缺少什么......寻求帮助

1 个答案:

答案 0 :(得分:1)

因此:

  ERRO[0003] Missing required GCS remote state configuration project

我认为你需要在运行 terragrunt 之前运行这些?

  gcloud config set project <your project>
  gcloud auth application-default login