diff --git a/README.md b/README.md index b724cbb..3c754c5 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ bin/terraform.sh \ -b/--bucket-prefix `bucket_prefix` \ -c/--component `component_name` \ -e/--environment `environment` \ - -g/--group `group` (optional) \ + -g/--group/--groups `group` (optional) \ -i/--build-id `build_id` (optional) \ -p/--project `project` \ -r/--region `region` \ @@ -133,7 +133,7 @@ Where: * It is usual to provide, for example, the Jenkins _$BUILD_ID_ parameter to Plan jobs, and then manually reference that particular Job ID when running a corresponding apply job. * `component_name`: The name of the terraform component in the components directory to run the `action` against. * `environment`: The name of the environment the component is to be actioned against, therefore implying the variables file(s) to be included -* `group` (optional): The name of the group to which the environment belongs, permitting the use of a group tfvars file as a "meta-environment" shared by more than one environment +* `group(s)` (optional): The names of the groups to which the environment belongs, permitting the use of a group tfvars file as a "meta-environment" shared by more than one environment. Comma delimited string, eg `group1,group2`. Do not specify var.group more than once. * `project`: The name of the project being deployed, as per the default bucket-prefix and state file keyspace * `region` (optional): The AWS region name unique to all components and terraform processes. Defaults to the value of the _AWS_DEFAULT_REGION_ environment variable. * `detailed-exitcode` (optional): Passes detailed exit code flag to terraform. diff --git a/bin/terraform.sh b/bin/terraform.sh index 36d2a56..6d5b418 100755 --- a/bin/terraform.sh +++ b/bin/terraform.sh @@ -8,7 +8,7 @@ ## # Set Script Version ## -readonly script_ver="1.7.0"; +readonly script_ver="1.7.1"; ## # Standardised failure function @@ -134,7 +134,7 @@ declare bootstrap="false"; declare component_arg; declare region_arg; declare environment_arg; -declare group; +declare groups; declare action; declare bucket_prefix; declare build_id; @@ -174,10 +174,10 @@ while true; do shift; fi; ;; - -g|--group) + -g|--group|--groups) shift; if [ -n "${1}" ]; then - group="${1}"; + groups="${1}"; shift; fi; ;; @@ -480,12 +480,6 @@ readonly global_vars_file_path="${base_path}/etc/${global_vars_file_name}"; readonly region_vars_file_name="${region}.tfvars"; readonly region_vars_file_path="${base_path}/etc/${region_vars_file_name}"; -# Check for presence of a group variables file if specified, and use it if readable -if [ -n "${group}" ]; then - readonly group_vars_file_name="group_${group}.tfvars"; - readonly group_vars_file_path="${base_path}/etc/${group_vars_file_name}"; -fi; - # Collect the paths of the variables files to use declare -a tf_var_file_paths; @@ -501,13 +495,16 @@ declare -a tf_var_file_paths; # the warning about duplicate variables below) we add this to the list after # global and region-global variables, but before the environment variables # so that the environment can explicitly override variables defined in the group. -if [ -n "${group}" ]; then +for group in ${groups//,/"${IFS}"}; do + group_vars_file_name="group_${group}.tfvars"; + group_vars_file_path="${base_path}/etc/${group_vars_file_name}"; + if [ -f "${group_vars_file_path}" ]; then tf_var_file_paths+=("${group_vars_file_path}"); else echo -e "[WARNING] Group \"${group}\" has been specified, but no group variables file is available at ${group_vars_file_path}"; fi; -fi; +done; # Environment is normally expected, but in bootstrapping it may not be provided if [ -n "${environment}" ]; then