Moos3
Moos3

Reputation: 91

Terragrunt Global Variables

So I have a set of like 30 inputs that are shared between all projects. I'm wondering the best way to share them in all the terragrunt.hcl files with out having to copy them a million different places. I currently use yaml files for some overrides. I was wondering what the best practices are.

    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
   }

It would be nice to just include a module to include those or load them from a centralized path. As these thing won't change often.

Upvotes: 6

Views: 6082

Answers (1)

yorinasub17
yorinasub17

Reputation: 51

The current best practice with Terragrunt for this is to use the read_terragrunt_config function to import the variables into your child config for reuse.

See the child terragrunt.hcl for mysql in the terragrunt-infrastructure-live-example repo. Note how we use read_terragrunt_config to import the environment name and interpolate that in the inputs. You can also directly merge the vars to pass forward as inputs using inputs = merge(local.environment_vars.locals, { /* additional inputs here */ }).

Upvotes: 5

Related Questions