3

所以我有一组大约 30 个输入,在所有项目之间共享。我想知道在所有 terragrunt.hcl 文件中共享它们的最佳方式,而不必将它们复制到一百万个不同的地方。我目前使用 yaml 文件进行一些覆盖。我想知道最佳实践是什么。

    locals {
      manager           = "devops"                             # default contact
      company_id        = "moos3"                                 # any string to identify the company for better resources naming. Keep max size of five chars.
      default_yaml_path = find_in_parent_folders("empty.yaml") # terragrunt function. read the file content for better explanation.
      enabled_api_services = [                                 # APIs enabled by default for all projects when created
        "compute.googleapis.com",
        "cloudkms.googleapis.com",
        "cloudresourcemanager.googleapis.com",
        "logging.googleapis.com",
        "monitoring.googleapis.com",
        "serviceusage.googleapis.com",
        "storage-api.googleapis.com",
      ]
      gcp_billing_account    = "*****************" # gcp billing account where projects will be created
      gcp_org_id             = "*****************"         # gcp organization id where resources will be created
      gcp_seed_project_id    = "my-seed"               # initial seed project where terraform state bucket will be created
      region                 = "us-east1"              # default region for shared services
      stack                  = "global"                # architectural stack name
   }

最好只包含一个模块来包含这些或从集中路径加载它们。因为这些东西不会经常改变。

4

1 回答 1

4

目前使用 Terragrunt 的最佳实践是使用该read_terragrunt_config函数将变量导入您的子配置以供重用。

repo中查看mysql 的子 terragrunt.hcl。请注意我们如何使用导入环境名称并将其插入到输入中。您还可以使用 直接合并变量以作为输入传递。terragrunt-infrastructure-live-exampleread_terragrunt_configinputs = merge(local.environment_vars.locals, { /* additional inputs here */ })

于 2020-03-09T18:24:13.673 回答