Skip to content

Commit

Permalink
docs: update INFRACOST_TERRAFORM_SOURCE_MAP docs with new functiona…
Browse files Browse the repository at this point in the history
…lity
  • Loading branch information
aliscott committed Oct 2, 2023
1 parent 8e7ec16 commit f3c1ba5
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions docs/features/terraform_modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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=<version>` takes precedence. If that is not found then it falls back any entry without a `?ref=<version>` 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:
```
Expand Down

0 comments on commit f3c1ba5

Please sign in to comment.