Skip to content

Commit 61565b9

Browse files
committed
terraformscaffold v1.1.4 - Global and Region scoped variables files
1 parent 3602593 commit 61565b9

File tree

8 files changed

+58
-5
lines changed

8 files changed

+58
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.1.4 (16/05/2017)
2+
3+
* Global and Region scoped variables files
4+
15
## 1.1.3 (12/04/2017)
26

37
* Support the use of .terraform-version file in components when in the presence of [tfenv](https://github.com/kamatama41/tfenv)

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,15 @@ Scaffold uses AWS S3 for storage of tfstate files. The bucket and location are s
3131

3232
### Variables Files: Environment & Versions
3333

34-
Scaffold provides a logical separation of two types of environment variable. Standard static variables and frequently-changing versions variables. This seperation is purely logical, not functional. It makes no functional difference in which file a variable lives, or even whether a versions variables file exists; but it provides the capacity to seperate out mostly static variables that define the construction of the environment from variables that could change on each apply providing new AMI IDs, or dockerised application versions or database snapshot IDs when recreating development and testing databases.
34+
Scaffold provides a logical separation of several types of environment variable:
35+
* Global variables
36+
* Region-scoped global variables
37+
* Static environment variables
38+
* Frequently-changing versions variables
39+
* Dynamic (S3 stored) variables
40+
* Secret (S3 stored, KMS encrypted variables - available but not recommended)
41+
42+
This seperation is purely logical, not functional. It makes no functional difference in which file a variable lives, or even whether a versions variables file exists; but it provides the capacity to seperate out mostly static variables that define the construction of the environment from variables that could change on each apply providing new AMI IDs, or dockerised application versions or database snapshot IDs when recreating development and testing databases.
3543

3644
### AWS Credentials
3745

bin/terraform.sh

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
##
99
# Set Script Version
1010
##
11-
readonly script_ver="1.1.3";
11+
readonly script_ver="1.1.4";
1212

1313
##
1414
# Standardised failure function
@@ -363,11 +363,29 @@ if [ ! -f "${env_file_path}" ]; then
363363
error_and_die "Unknown environment. ${env_file_path} does not exist.";
364364
fi;
365365

366+
# Check for presence of a global variables file, and use it if readable
367+
readonly global_vars_file_name="global.tfvars";
368+
readonly global_vars_file_path="${base_path}/etc/${global_vars_file_name}";
369+
370+
# Check for presence of a region variables file, and use it if readable
371+
readonly region_vars_file_name="${region}.tfvars";
372+
readonly region_vars_file_path="${base_path}/etc/${region_vars_file_name}";
373+
366374
# Collect the paths of the variables files to use
367375
declare tf_var_files;
368376
declare -a tf_var_file_paths;
369377

370-
tf_var_file_paths=("${env_file_path}");
378+
# Use Global and Region first, to allow potential for terraform to do the
379+
# honourable thing and override global and region settings with environment
380+
# specific ones; however we do not officially support the same variable
381+
# being declared in multiple locations, and we warn when we find any duplicates
382+
[ -f "${global_vars_file_path}" ] && tf_var_file_paths+=("${global_vars_file_path}");
383+
[ -f "${region_vars_file_path}" ] && tf_var_file_paths+=("${region_vars_file_path}");
384+
385+
# We've already checked this is readable and its presence is mandatory
386+
tf_var_file_paths+=("${env_file_path}");
387+
388+
# If present and readable, use versions and dynamic variables too
371389
[ -f "${versions_file_path}" ] && tf_var_file_paths+=("${versions_file_path}");
372390
[ -f "${dynamic_file_path}" ] && tf_var_file_paths+=("${dynamic_file_path}");
373391

@@ -379,9 +397,16 @@ duplicate_variables="$(cat "${tf_var_file_paths[@]}" | sed -n -e 's/\(^[a-zA-Z0-
379397
# WARNING #
380398
###########
381399
The following input variables appear to be duplicated:
400+
382401
${duplicate_variables}
383402
384-
This could lead to unexpected behaviour.
403+
This could lead to unexpected behaviour. Overriding of variables has
404+
previously been unpredictable and is not currently supported, but it
405+
may work.
406+
407+
Recent changes to terraform might give you useful overriding and
408+
map-merging functionality, please use with caution and report back
409+
on your successes & failures.
385410
###########";
386411

387412
# Build up the tfvars arguments for terraform command line

etc/env_eg-region-1_exampleenv.tfvars

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Define variable values to be fed into components in the components directory that will each form a part of the examplenv environment...
2+
3+
environment = "exampleenv"
4+
5+
default_tags = {
6+
"Project" = "myproject"
7+
"Environment" = "exampleenv"
8+
"Owner" = "My Project Manager"
9+
"Client" = "My Client"
10+
}

etc/eu-west-1.tfvars

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Specific to region within project/AWS Account
2+
terraform_state_bucket = "myproject-terraformscaffold-012345678901-eu-west-1"
3+
region = "eu-west-1"

etc/global.tfvars

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Specific to whole project / AWS Account
2+
project = "myproject"
3+
aws_account_id = "012345678901"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
# Define variable values to be fed into components in the components directory that will each form a part of the examplenv environment...
2+
my_example_docker_app_version="0.0.1"

0 commit comments

Comments
 (0)