Skip to content

Commit e81dbb8

Browse files
author
Sol Rosenberg
authored
Add hook to create partial backend configuration (#2)
* Add hook to create partial backend configuration * Remove old line
1 parent d6f6212 commit e81dbb8

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

live/global/terraform-remote-state/terragrunt.hcl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ terraform {
33
}
44

55
inputs = {
6-
bucket = chomp(run_cmd("../../../config/config.sh", "BUCKET"))
7-
dynamodb_table = chomp(run_cmd("../../../config/config.sh", "DYNAMODB_TABLE"))
6+
bucket = chomp(run_cmd("../../../scripts/config.sh", "BUCKET"))
7+
dynamodb_table = chomp(run_cmd("../../../scripts/config.sh", "DYNAMODB_TABLE"))
88
}

live/terragrunt.hcl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@ remote_state {
33
backend = "s3"
44

55
config = {
6-
bucket = chomp(run_cmd("${path_relative_from_include()}/../config/config.sh", "BUCKET"))
7-
region = chomp(run_cmd("${path_relative_from_include()}/../config/config.sh", "REGION"))
8-
dynamodb_table = chomp(run_cmd("${path_relative_from_include()}/../config/config.sh", "DYNAMODB_TABLE"))
6+
bucket = chomp(run_cmd("${path_relative_from_include()}/../scripts/config.sh", "BUCKET"))
7+
region = chomp(run_cmd("${path_relative_from_include()}/../scripts/config.sh", "REGION"))
8+
dynamodb_table = chomp(run_cmd("${path_relative_from_include()}/../scripts/config.sh", "DYNAMODB_TABLE"))
99
key = "${path_relative_to_include()}/terraform.tfstate"
1010
encrypt = true
1111
}
1212
}
1313

1414
terraform {
15+
after_hook "init_from_module" {
16+
commands = ["init-from-module"]
17+
execute = ["ln", "-sf", "../../backend.tf", "."]
18+
}
19+
1520
extra_arguments "env_vars" {
1621
commands = [
1722
"init",
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
if [ ! -f "backend.tf" ]; then
4+
ln -s ../../backend.tf .
5+
fi

config/config.sh renamed to scripts/config.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ syntax() {
88
print_config() {
99
cd "$(dirname "${BASH_SOURCE[0]}")" || exit
1010

11-
x="$(grep ^"$1" ./remote_state.config)"
11+
x="$(grep ^"$1" ../config/remote_state.config)"
1212
if [ "$x" ]; then
1313
echo "$x" | cut -d'=' -f2
1414
else

0 commit comments

Comments
 (0)