Skip to content
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

feat: wildcard support for modules in usage file #2286

Merged
merged 2 commits into from
Feb 13, 2023
Merged

Conversation

hugorut
Copy link
Contributor

@hugorut hugorut commented Feb 8, 2023

This PR adds support for wildcard references in the Infracost usage file.

Users can now specify usage file references such as module.mod[*].aws_lambda_function.test[*].

This functionality is enabled by the introduction of schema.UsageMap into the application. This builds a regexp from the usage file name (escaping all regular expression metacharacters apart from *) if a direct match is not made. This means we can support many layers of wildcard references, e.g: module.mod[*].module.another[*].aws_lambda_function.test[*].

@hugorut hugorut requested a review from aliscott February 8, 2023 17:58
@hugorut
Copy link
Contributor Author

hugorut commented Feb 8, 2023

@aliscott I'm not sure what we're thinking of doing with the sync functionality and if these wildcard changes need to change that as well. For now I've not touched it.

internal/schema/usage_data.go Outdated Show resolved Hide resolved
internal/schema/usage_data.go Outdated Show resolved Hide resolved
This PR adds support for wildcard references in the Infracost usage file.

Users can now specify usage file references such as `module.mod[*].aws_lambda_function.test[*]`.

This functionality is enabled by the introduction of `schema.UsageMap` into the application. This builds a regexp from the usage file name (escaping all regular expression metacharacters apart from *) if a direct match is not made. This means we can support many layers of wildcard references, e.g: `module.mod[*].module.another[*].aws_lambda_function.test[*]`.
@hugorut hugorut force-pushed the feat/wildcard-modules branch 3 times, most recently from 4d651e4 to 2304330 Compare February 13, 2023 10:39
@@ -8,7 +8,7 @@ Project: infracost/infracost/cmd/infracost/testdata/breakdown_terraform_sync_usa
└─ Insights queries data scanned Monthly cost depends on usage: $0.005 per GB

aws_cloudwatch_log_group.production_logs["media"]
├─ Data ingested Monthly cost depends on usage: $0.50 per GB
├─ Data ingested 1,000 GB $500.00
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like this was a bug before that was fixed by this PR, the resource defaults are as follows:

resource_type_default_usage:
  aws_cloudwatch_log_group:
    monthly_data_ingested_gb: 1000.0

Copy link
Member

@aliscott aliscott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice tests!

@hugorut hugorut merged commit ca47294 into master Feb 13, 2023
@hugorut hugorut deleted the feat/wildcard-modules branch February 13, 2023 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants