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
Improve support for Terragrunt projects #807
Comments
We can detect a Terragrunt project based on the We need to work out how we handle Terragrunt projects that contain multiple modules. These contain the Options for detecting Terragrunt projects with multiple modules:
If we do support these and can detect them then we also need to work out how to handle them:
cc @alikhajeh1 and @tim775 if you have any thoughts on the options above. |
When supporting the As an initial version we could apply the matching usage file values to all resources that match, but I would like to be able to set different values for my different terragrunt modules. |
Currently for Terragrunt projects with a hierarchy we require each Terragrunt module to be specified in the Infracost config file. Using this method you can pass in a different usage file for each module. version: 0.1
projects:
- path: my/terragrunt/project/dev
terraform_binary: terragrunt
usage_file: usage-dev.yml
- path: my/terragrunt/project/prod
terraform_binary: terragrunt
usage_file: usage-dev.yml When we support Terragrunt as first-class, we will allow the root Terragrunt directory to be passed in, like: version: 0.1
projects:
- path: my/terragrunt/project The issue with this is that we now cannot specify a different usage file for each module. Multiple Terragrunt modules may have the same resources, so we have no way of uniquely identifying them in the usage file. To solve this we could: Option 1: Update the config file to allow multiple usage files and specify which module they are for For example: version: 0.2
projects:
- path: my/terragrunt/project
usage_files:
- match_path: 'dev/base'
file: infracost-usage-dev-base.yml
- match_path: 'prod/base'
file: infracost-usage-prod-base.yml
- match_path: 'dev/api'
file: infracost-usage-dev-api.yml
- match_path: 'prod/api'
file: infracost-usage-prod-api.yml Option 2: Update the config file to support multiple projects: Both below examples are additive only so wouldn't break existing usage files. Example A: version: 0.1
# This contains the default resource usage
resource_usage:
aws_lambda_function.my_lambda_function:
monthly_requests: 20000
request_duration_ms: 600
# This contains any overrides for the dev/base project
resource_usage[dev/base]:
aws_lambda_function.my_lambda_function:
monthly_requests: 100
request_duration_ms: 600 Example B: version: 0.1
# This contains the default
resource_usage:
aws_lambda_function.my_lambda_function:
monthly_requests: 20000
request_duration_ms: 600
# This has any overrides/per-project usage
projects:
- path: my/terragrunt/project/dev/base
resource_usage:
aws_lambda_function.my_lambda_function:
monthly_requests: 100
request_duration_ms: 600 Option X: Any other suggestions / comments on the above options? We will also need to consider how this would work if we support auto-detecting Terraform workspaces or if we support Terraform monorepos (as per #490 and #188). |
@ljhurst, @Ian-T-Price and @mikejk8s just FYI that we shipped improved support for Terragrunt in v0.9.7, see docs here: https://www.infracost.io/docs/iac_tools/terragrunt We'd love to hear your feedback on it, and also #934 if you use the usage-file. |
Currently our CI/CD integrations ask users to read https://www.infracost.io/docs/iac_tools/terragrunt, which doesn't mention how the user should use Infracost with Terragrunt in those integrations. For example, for GitLab, they could currently do the following.
However, could we detect a Terragrunt project from
--path
and support this natively without the user having to create a config file? That would make it easier to run Infracost with Terragrunt projects that have many modules, as currently the user has to update the config file.Create an infracost config file, called
infracost.yaml
, with:Test the above works locally, by running
infracost breakdown --config-file infracost.yaml
Add a GitLab CI stage for infracost - the same can be done with other CI/CD integrations by setting the config file param:
The text was updated successfully, but these errors were encountered: