Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multivalue function to group #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` \
Expand All @@ -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.
Expand Down
21 changes: 9 additions & 12 deletions bin/terraform.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
##
# Set Script Version
##
readonly script_ver="1.7.0";
readonly script_ver="1.7.1";

##
# Standardised failure function
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
;;
Expand Down Expand Up @@ -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;

Expand All @@ -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
Expand Down