AWS Cost and Usage Reports
The AWS Cost and Usage Reports (CUR) integration reads AWS billing data and attributes cost to instances.
Prerequisites​
- An AWS account with billing access
- Permission to create IAM users, S3 buckets, and CUR report definitions
- OpenTofu or Terraform, and AWS provider 5.16 or later
Setup​
Step 1: Apply the module​
git clone https://github.com/massdriver-cloud/integrations.git
cd integrations/aws-cost-and-usage-reports
tofu init
tofu apply
CUR report definitions exist only in us-east-1, so run the module with the AWS provider in us-east-1. The bucket is created in the provider's region. Set bucket_region to that region; it defaults to us-west-2.
| Variable | Default | Description |
|---|---|---|
name_prefix | massdriver-costs | Prefix for the bucket, report, and IAM user names |
bucket_region | us-west-2 | Region of the S3 bucket |
cost_allocation_tags | [] | Tag keys to activate as cost allocation tags: md-package, md-instance, or both. See cost attribution. |
cur_report_additional_artifacts | [] | Extra CUR artifacts: REDSHIFT, QUICKSIGHT, ATHENA |
tags | {} | Tags for the created resources. managed-by = massdriver is always set. |
Step 2: Read the outputs​
tofu output -json massdriver_integration_config
{
"access_key_id": "AKIAIOSFODNN7EXAMPLE",
"secret_access_key": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
"bucket_name": "massdriver-costs-a1b2c3d4",
"bucket_region": "us-west-2"
}
Step 3: Create the integration​
Under Organization settings → Integrations, click Integrate on AWS Cost and Usage Reports, or call createIntegration with id: "aws-cost-and-usage-reports".
| Field | Key | Source |
|---|---|---|
| Access Key ID | auth.access_key_id | access_key_id output |
| Secret Access Key | auth.secret_access_key | secret_access_key output |
| S3 Bucket Name | config.bucket_name | bucket_name output |
| AWS Region | config.region | bucket_region output |
| Report Format | config.format | zip (default) for ZIP-compressed CSV, or parquet. Must match the report's format in AWS. |
Resources created​
| Resource | Name | Purpose |
|---|---|---|
| S3 bucket | {name_prefix}-{8 hex characters of md5(account id)} | Stores the reports |
| S3 bucket policy | — | Lets AWS billing (billingreports.amazonaws.com) write reports |
| CUR report definition | {name_prefix} | Daily report with resource IDs |
| IAM user | {name_prefix} | Identity Massdriver uses |
| IAM user policy | {name_prefix}-policy | Read access to the bucket, and tag:GetResources |
| Access key | — | Credentials for the IAM user |
| Cost allocation tags | the cost_allocation_tags keys | Only when cost_allocation_tags is set |
IAM permissions​
| Action | Resource |
|---|---|
s3:HeadBucket, s3:ListBucket | The bucket |
s3:GetObject | Objects in the bucket |
tag:GetResources | * |
Report configuration​
The module's report is:
- Time unit: daily
- Format: ZIP-compressed CSV, under the
reportsprefix - Additional schema elements:
RESOURCES - Versioning:
OVERWRITE_REPORT
Massdriver also reads Parquet reports. If you change the report to Parquet in AWS, set Report Format to parquet. Parquet column names are snake_case; Massdriver maps them to the same fields it reads from CSV.
Data collection​
Every 24 hours, Massdriver:
- Reads the report manifest from the bucket and downloads the current report.
- Keeps only
Usageline items. Credits, fees, Reserved Instance, and Savings Plans line items are not counted, so costs show what usage costs without credits. - Attributes each line item to an instance and totals the cost per instance.
Cost attribution modes​
Massdriver attributes each line item to an instance by its md-instance tag, which holds the instance id. Resources without md-instance are attributed by the legacy md-package tag. Massdriver chooses the mode from the report.
Resource Groups Tagging API (default)​
Massdriver looks up each resource's current tags with the Resource Groups Tagging API, using the IAM user's tag:GetResources permission. It needs no access to the billing account.
Cost allocation tag column​
When md-instance or md-package is an active cost allocation tag, AWS adds a resourceTags/user:md-instance or resourceTags/user:md-package column to the report. If the report has either column, Massdriver reads the tag from each line item and does not call the Tagging API. The column records the tag at the time of usage, so resources that were deleted or retagged since are still attributed.
To activate tags, list them in cost_allocation_tags on the OpenTofu module. Organizations on the legacy default tags activate md-package:
module "massdriver_cur" {
source = "github.com/massdriver-cloud/integrations//aws-cost-and-usage-reports?ref=v2.0.0"
cost_allocation_tags = ["md-package"]
}
Version v1.0.0 of the module uses activate_cost_allocation_tag = true for md-package. In v2.0.0, use cost_allocation_tags = ["md-package"]. The upgrade keeps the existing activation.
Activating a cost allocation tag is a billing setting that must be applied in the AWS management (payer) account. It applies going forward only and can take up to 24 hours to appear in reports. Until the column appears, Massdriver uses the Tagging API.
Switching to custom default tags​
Organizations that use the legacy default tags send md-package on every resource. When an organization switches to a custom list of default tags, Massdriver stops sending md-package and sends md-instance instead. Each resource gets the new tags at the next deployment of its instance.
Tagging API mode: no change is necessary. Massdriver reads md-instance from each resource.
Cost allocation tag mode: activate md-instance as a cost allocation tag before you switch. When the report has a cost allocation tag column, Massdriver reads the instance tag only from the report columns. Line items for resources that have only md-instance are not attributed until md-instance is active.
Activate md-instance in the AWS management (payer) account. Add md-instance to cost_allocation_tags on the OpenTofu module, or use the Billing and Cost Management console under Cost allocation tags. Keep md-package in the list while resources still carry it.
module "massdriver_cur" {
source = "github.com/massdriver-cloud/integrations//aws-cost-and-usage-reports?ref=v2.0.0"
cost_allocation_tags = ["md-package", "md-instance"]
}
AWS can only activate a tag key after a resource in the account has that tag, and the key can take up to 24 hours to appear. Until then, tofu apply fails when cost_allocation_tags includes md-instance. To activate md-instance before you switch, add an md-instance tag to one resource manually, then activate the key. If you switch first, costs for line items between the deployment and the activation are not attributed, because the resources no longer have md-package and the report has no md-instance column yet. Activation does not apply to costs from before it.
Troubleshooting​
Enable fails with access_denied​
S3 returned 403. Check that the module applied and the IAM user policy is attached, and that AWS Region is the bucket's region.
Enable fails with bucket_not_found​
S3 returned 404. Check S3 Bucket Name and AWS Region.
No cost data appears​
- Check that resources have the
md-instanceormd-packagetag. - If the report has a cost allocation tag column, check that the tag your resources carry is activated.
- The first report can take up to 24 hours to appear.
- Check that AWS is writing the report to the bucket.
Cleanup​
cd integrations/aws-cost-and-usage-reports
tofu destroy
This deletes the S3 bucket and its reports. Cost data Massdriver already collected is kept.