Skip to main content
Knowledge Base

How do I use the modules in terraform-aws-service-catalog if there is no example?

Answer

Some modules in `terraform-aws-service-catalog` like [s3-bucket](https://github.com/gruntwork-io/terraform-aws-service-catalog/tree/master/modules/data-stores/s3-bucket) have no Terragrunt example defined in the `for-production` folder. Does that mean it is not designed for use with Terragrunt?

There are a handful of modules in the Service Catalog that were developed for different use cases that are difficult to integrate into our Reference Architecture, and thus are omitted from the `for-production` example. This doesn't mean that it is not designed for use with the Reference Architecture - it just means that it's hard for us to come up with a generic use case that is adaptable to a wide variety of customers, and thus we omit it from the example. However, any and every module in the `terraform-aws-service-catalog` is designed to be deployed with terragrunt. You can take any of the modules in the Service Catalog and create a `terragrunt.hcl` that works well with the Reference Architecture by using the following general template: ```hcl terraform { source = "git::git@github.com:gruntwork-io/terraform-aws-security.git//modules/${local.path_to_module}?ref=${local.latest_version}" } include { path = find_in_parent_folders() } # --------------------------------------------------------------------------------------------------------------------- # Locals are named constants that are reusable within the configuration. # --------------------------------------------------------------------------------------------------------------------- locals { # TODO: Set to specific module you are deploying, and its version. path_to_module = "" latest_version = "" # Automatically load common variables that are useful in most configurations common_vars = read_terragrunt_config(find_in_parent_folders("common.hcl")) name_prefix = local.common_vars.locals.name_prefix account_vars = read_terragrunt_config(find_in_parent_folders("account.hcl")) account_name = local.account_vars.locals.account_name account_role = local.account_vars.locals.account_role region_vars = read_terragrunt_config(find_in_parent_folders("region.hcl")) aws_region = local.region_vars.locals.aws_region path_to_account_root = dirname(find_in_parent_folders("account.hcl")) path_to_region_root = dirname(find_in_parent_folders("region.hcl")) } # TODO: Add any dependency blocks that you need for deploying this module, like VPC. # Example: # dependency "vpc" { # config_path = "${local.path_to_region_root}/${local.account_name}/networking/vpc" # } # --------------------------------------------------------------------------------------------------------------------- # MODULE PARAMETERS # These are the variables we have to pass in to use the module specified in the terragrunt configuration above. # --------------------------------------------------------------------------------------------------------------------- inputs = { # TODO: Go to the corresponding documentation for the module on # https://docs.gruntwork.io/reference/services/intro/overview # and find the module reference containing the input variables. # For example, here is the page for the s3 bucket variables: # https://docs.gruntwork.io/reference/services/data-storage/s-3-bucket#reference # Using the reference page, go through the variables you want to configure and enter # them in this map. You can reference any of the locals, and dependencies you defined above. # # Example (for s3): # primary_bucket = "${local.name_prefix}-generic-s3-bucket-for-${local.account_name}" # access_logging_bucket = "${local.name_prefix}-generic-access-logging" } ``` --- If instead you would like to deploy the component in every environment, you will want to follow the `_envcommon` pattern. In this pattern, you would place the common configurations in an `hcl` file in the `_envcommon` folder, and then inherit that config in each environment. Here is a template: _envcommon HCL_ ```hcl terraform { source = "${local.source_url}?ref=${local.latest_version}" } # --------------------------------------------------------------------------------------------------------------------- # Locals are named constants that are reusable within the configuration. # --------------------------------------------------------------------------------------------------------------------- locals { # TODO: Set to specific module you are deploying, and its version. path_to_module = "" latest_version = "" source_url = "git::git@github.com:gruntwork-io/terraform-aws-security.git//modules/${local.path_to_module}" # Automatically load common variables that are useful in most configurations common_vars = read_terragrunt_config(find_in_parent_folders("common.hcl")) name_prefix = local.common_vars.locals.name_prefix account_vars = read_terragrunt_config(find_in_parent_folders("account.hcl")) account_name = local.account_vars.locals.account_name account_role = local.account_vars.locals.account_role region_vars = read_terragrunt_config(find_in_parent_folders("region.hcl")) aws_region = local.region_vars.locals.aws_region path_to_account_root = dirname(find_in_parent_folders("account.hcl")) path_to_region_root = dirname(find_in_parent_folders("region.hcl")) } # TODO: Add any dependency blocks that you need for deploying this module, like VPC. # Example: # dependency "vpc" { # config_path = "${local.path_to_region_root}/${local.account_name}/networking/vpc" # } # --------------------------------------------------------------------------------------------------------------------- # MODULE PARAMETERS # These are the variables we have to pass in to use the module specified in the terragrunt configuration above. # --------------------------------------------------------------------------------------------------------------------- inputs = { # TODO: Go to the corresponding documentation for the module on # https://docs.gruntwork.io/reference/services/intro/overview # and find the module reference containing the input variables. # For example, here is the page for the s3 bucket variables: # https://docs.gruntwork.io/reference/services/data-storage/s-3-bucket#reference # Using the reference page, go through the variables you want to configure and enter # them in this map. You can reference any of the locals, and dependencies you defined above. # # Example (for s3): # primary_bucket = "${local.name_prefix}-generic-s3-bucket-for-${local.account_name}" # access_logging_bucket = "${local.name_prefix}-generic-access-logging" } ``` _child terragrunt.hcl config in each environment_ ```hcl include "root" { path = find_in_parent_folders() } include "envcommon" { path = "${dirname(find_in_parent_folders())}/_envcommon/path/to/hclfile" } ```