Skip to content

Instantly share code, notes, and snippets.

@Burekasim
Created January 26, 2026 10:30
Show Gist options
  • Select an option

  • Save Burekasim/fcf37df2104375729d06d0d20b721c4f to your computer and use it in GitHub Desktop.

Select an option

Save Burekasim/fcf37df2104375729d06d0d20b721c4f to your computer and use it in GitHub Desktop.
tf to create CUR data export
provider "aws" {
profile = "default"
region = "us-east-1"
}
data "aws_region" "current" {}
resource "aws_s3_bucket" "cur" {
bucket = "cur-test-buckeet-ru98hr8"
force_destroy = true
}
resource "aws_s3_bucket_server_side_encryption_configuration" "cur" {
bucket = aws_s3_bucket.cur.id
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
resource "aws_s3_bucket_public_access_block" "cur" {
bucket = aws_s3_bucket.cur.id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
resource "aws_s3_bucket_policy" "cur_policy" {
bucket = aws_s3_bucket.cur.id
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Sid = "EnableAWSDataExportsToWriteToS3AndCheckPolicy"
Effect = "Allow"
Principal = {
Service = [
"billingreports.amazonaws.com",
"bcm-data-exports.amazonaws.com"
]
}
Action = [
"s3:PutObject",
"s3:GetBucketPolicy"
]
Resource = [
"arn:aws:s3:::${aws_s3_bucket.cur.id}",
"arn:aws:s3:::${aws_s3_bucket.cur.id}/*"
]
Condition = {
StringLike = {
"aws:SourceArn" = [
"arn:aws:cur:us-east-1:${data.aws_caller_identity.current.account_id}:definition/*",
"arn:aws:bcm-data-exports:us-east-1:${data.aws_caller_identity.current.account_id}:export/*"
]
"aws:SourceAccount" = data.aws_caller_identity.current.account_id
}
}
}
]
})
}
data "aws_caller_identity" "current" {}
data "aws_partition" "current" {}
resource "aws_bcmdataexports_export" "cur20" {
export {
name = "ze-oved"
data_query {
query_statement = "SELECT identity_line_item_id, identity_time_interval, line_item_product_code,line_item_unblended_cost FROM COST_AND_USAGE_REPORT"
table_configurations = {
COST_AND_USAGE_REPORT = {
BILLING_VIEW_ARN = "arn:${data.aws_partition.current.partition}:billing::${data.aws_caller_identity.current.account_id}:billingview/primary"
TIME_GRANULARITY = "HOURLY",
INCLUDE_RESOURCES = "FALSE",
INCLUDE_MANUAL_DISCOUNT_COMPATIBILITY = "FALSE",
INCLUDE_SPLIT_COST_ALLOCATION_DATA = "FALSE",
}
}
}
destination_configurations {
s3_destination {
s3_bucket = aws_s3_bucket.cur.bucket
s3_prefix = "cur-reports/"
s3_region = data.aws_region.current.region
s3_output_configurations {
overwrite = "OVERWRITE_REPORT"
format = "TEXT_OR_CSV"
compression = "GZIP"
output_type = "CUSTOM"
}
}
}
refresh_cadence {
frequency = "SYNCHRONOUS"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment