diff --git a/docs/features/terraform_modules.md b/docs/features/terraform_modules.md index 5de78f8f..409d91e5 100644 --- a/docs/features/terraform_modules.md +++ b/docs/features/terraform_modules.md @@ -60,7 +60,7 @@ module "my-module" { #### Option 2: Provide HTTPS credentials -If you cannot use Option 1, you need to provide HTTPS credentials that can be used to download the private module repos. Infracost GitHub and GitLab App users can provide these in Infracost Cloud. +If you cannot use Option 1, you need to provide HTTPS credentials that can be used to download the private module repos. Infracost GitHub and GitLab App users can provide these in Infracost Cloud. Other CI/CD users can add their HTTPS credentials into the `~/.git-credentials` file. ```bash @@ -110,19 +110,30 @@ If you store your private modules in an S3 bucket, you need to provide readonly The `INFRACOST_TERRAFORM_SOURCE_MAP` environment variable accepts a comma separated list of `source=dest` pairs, and replaces any matched source URL value found in Terraform `module` or Terragrunt `terraform` blocks. This is useful when you have module URLs that are referenced in your infra-as-code repos one way (e.g. using a private URL), but they should use a different URL when Infracost runs them (e.g. using a public URL). -This works similarly to the [`TERRAGRUNT_SOURCE_MAP` environment variable](https://terragrunt.gruntwork.io/docs/reference/cli-options/#terragrunt-source-map). +For Terragrunt `terraform` blocks, this has the exact same functionality as the [`TERRAGRUNT_SOURCE_MAP` environment variable](https://terragrunt.gruntwork.io/docs/reference/cli-options/#terragrunt-source-map). + +For `module` blocks in Terraform, the functionality is similar but supports matching on prefixes as well as the full source URL. For example, to map remote git modules to local module specify: ``` INFRACOST_TERRAFORM_SOURCE_MAP=git::https://github.com/my-org/my-first-module.git=./local/my-first-module,git::https://github.com/my-org/my-second-module.git=./local/my-second-module ``` -To map remote git SSH modules to git HTTPS modules specify: +To map a single remote git SSH modules to a git HTTPS module specify: ``` INFRACOST_TERRAFORM_SOURCE_MAP=git::ssh://github.com/my-org/my-first-module.git=git::https://github.com/my-org/my-first-module.git,git::ssh://github.com/my-org/my-second-module.git=git::https://github.com/my-org/my-second-module.git ``` -When replacing sources using the source map, any entry with a matching `?ref=` takes precedence. If that is not found then it falls back any entry without a `?ref=` specified. +To map all git SSH modules to git HTTPS modules for a single GitHub org, you can specify a prefix to match: +``` +INFRACOST_TERRAFORM_SOURCE_MAP=git::ssh://github.com/my-org/=git::https://github.com/my-org/ +``` + +:::note +This only works for module URLs, not Terragrunt `terraform` blocks. +::: + +When replacing module sources using the source map, the most specific match takes precedence. For example, given this source map: ```