description="Map of default values which will be used for each item."
type= any
default={}
}
variable "items"{
description="Maps of items to create a wrapper from. Values are passed through to the module."
type= any
default={}
}'
readonlyCONTENT_OUTPUTS_TF='output "wrapper"{
description="Map of outputs of a wrapper."
value= module.wrapper
WRAPPER_OUTPUT_SENSITIVE
}'
readonlyCONTENT_VERSIONS_TF='terraform {
required_version=">= 0.13.1"
}'
# shellcheck disable=SC2016 # False positive
readonlyCONTENT_README='# WRAPPER_TITLE
The configuration in this directory contains an implementation of a single module wrapper pattern, which allows managing several copies of a module in places where using the native Terraform 0.13+ `for_each` feature is not feasible (e.g., with Terragrunt).
You may want to use a single Terragrunt configuration file to manage multiple resources without duplicating `terragrunt.hcl` files for each copy of the same module.
This wrapper does not implement any extra functionality.
--module-repo-shortname=... - Short name of the repository (e.g., for'terraform-aws-s3-bucket' it should be 's3-bucket'). (Optional)
--module-repo-provider=... - Name of the repository provider (e.g., for'terraform-aws-s3-bucket' it should be 'aws'). (Optional)
--dry-run - Whether to run in dry mode. If not specified, wrapper files will be overwritten.
--verbose - Show verbose output.
Example:
--module-dir=modules/object - Generate wrapper for one specific submodule.
--module-dir=. - Generate wrapper for the root module.
--module-repo-org=terraform-google-modules --module-repo-shortname=network --module-repo-provider=google - Generate wrappers for repository available by name "terraform-google-modules/network/google" in the Terraform registry and it includes all modules (root and in "modules/*").
EOF
exit1
;;
esac
done
if[[ ! $root_dir]];then
echo"--root-dir can't be empty. Remove it to use default value."
exit1
fi
if[[ ! $wrapper_dir]];then
echo"--wrapper-dir can't be empty. Remove it to use default value."
exit1
fi
if[[ ! $module_repo_org]];then
echo"--module-repo-org can't be empty. Remove it to use default value."
exit1
fi
if[[ ! $module_repo_shortname]];then
echo"--module-repo-shortname can't be empty. It should be part of full repo name (eg, s3-bucket)."
exit1
fi
if[[ ! $module_repo_provider]];then
echo"--module-repo-provider can't be empty. It should be name of the provider used by the module (eg, aws)."
exit1
fi
if[[ ! -d "$root_dir"]];then
echo"Root directory $root_dir does not exist!"
exit1
fi
OLD_IFS="$IFS"
IFS=$'\n'
all_module_dirs=("./")
# Find all modules directories if nothing was provided via "--module-dir" argument
if[[ ! $module_dir]];then
# shellcheck disable=SC2207
all_module_dirs+=($(cd"${root_dir}"&& find . -maxdepth 2 -path '**/modules/*' -type d -print))
else
all_module_dirs=("$module_dir")
fi
IFS="$OLD_IFS"
for module_dir in "${all_module_dirs[@]}";do
# Remove "./" from the "./modules/iam-user" or "./"
module_dir="${module_dir/.\//}"
full_module_dir="${root_dir}/${module_dir}"
# echo "FULL=${full_module_dir}"
if[[ ! -d "$full_module_dir"]];then
echo"Module directory \"$full_module_dir\" does not exist!"
exit1
fi
# Remove "modules/" from "modules/iam-user"
# module_name="${module_dir//modules\//}"
module_name="${module_dir#modules/}"
if[[ ! $module_name]];then
wrapper_title="Wrapper for the root module"
wrapper_path="${wrapper_dir}"
else
wrapper_title="Wrapper for module: \`${module_dir}\`"
wrapper_path="${wrapper_dir}/${module_name}"
fi
# Wrappers will be stored in "wrappers/{module_name}"
common::colorify "yellow""Skipping ${full_module_dir} because it is a legacy module which contains its own local provider configurations and so calls to it may not use the for_each argument."