-
Notifications
You must be signed in to change notification settings - Fork 1
/
terragrunt.hcl
47 lines (41 loc) · 2.01 KB
/
terragrunt.hcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# ---------------------------------------------------------------------------------------------------------------------
# TERRAGRUNT CONFIGURATION
# Terragrunt is a thin wrapper for Terraform that provides extra tools for working with multiple Terraform modules,
# remote state, and locking: https://github.com/gruntwork-io/terragrunt
# ---------------------------------------------------------------------------------------------------------------------
locals {
remote_state_config_path = run_cmd("${get_repo_root()}/.tools/find-remote-state-config.sh", "${path_relative_to_include()}")
remote_state_config = yamldecode(file(local.remote_state_config_path))
workspace = replace(replace("${path_relative_to_include()}", "/[^A-Za-z0-9]/", "-"), "/(-[-]+)/", "-")
}
// Configure hook to validate the Terraform Cloud workspace is configured for local execution
terraform {
before_hook "validate_tfc_workspace" {
commands = ["import", "plan", "apply", "destroy"]
execute = ["/bin/bash", "${get_repo_root()}/.tools/verify-tfc-workspace.sh", "${local.remote_state_config.organization}", "${local.workspace}"]
}
}
// Generate the remote state backend config
generate "remote_state" {
path = "backend.tf"
if_exists = "overwrite_terragrunt"
contents = <<EOF
terraform {
backend "remote" {
hostname = "${local.remote_state_config.hostname}"
organization = "${local.remote_state_config.organization}"
workspaces {
name = "${local.workspace}"
}
}
}
EOF
}
# ---------------------------------------------------------------------------------------------------------------------
# GLOBAL PARAMETERS
# These variables apply to all configurations in this subfolder. These are automatically merged into the child
# `terragrunt.hcl` config via the include block.
# ---------------------------------------------------------------------------------------------------------------------
inputs = {
remote_state_config = merge(local.remote_state_config, { workspace = local.workspace })
}