Skip to content

Commit a6aa54d

Browse files
author
sressier
committed
add CUR report, use modern expression
1 parent c906d29 commit a6aa54d

2 files changed

Lines changed: 63 additions & 1 deletion

File tree

  • lambdas/functions/iroco2-client-side-scanner
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
resource "aws_bcmdataexports_export" "CUR" {
2+
export {
3+
name = "IROCO2-REPORT"
4+
data_query {
5+
query_statement = "SELECT identity_line_item_id, identity_time_interval, line_item_product_code,line_item_unblended_cost FROM COST_AND_USAGE_REPORT"
6+
table_configurations = {
7+
COST_AND_USAGE_REPORT = {
8+
BILLING_VIEW_ARN = "arn:aws:billing::${data.aws_caller_identity.current.account_id}:billingview/primary"
9+
TIME_GRANULARITY = "HOURLY",
10+
INCLUDE_RESOURCES = "FALSE",
11+
INCLUDE_MANUAL_DISCOUNT_COMPATIBILITY = "FALSE",
12+
INCLUDE_SPLIT_COST_ALLOCATION_DATA = "FALSE",
13+
}
14+
}
15+
}
16+
destination_configurations {
17+
s3_destination {
18+
s3_bucket = aws_s3_bucket.cur_output.bucket
19+
s3_prefix = "iroco"
20+
s3_region = data.aws_region.current.region
21+
s3_output_configurations {
22+
overwrite = "CREATE_NEW_REPORT"
23+
format = "TEXT_OR_CSV"
24+
compression = "GZIP"
25+
output_type = "CUSTOM"
26+
}
27+
}
28+
}
29+
30+
refresh_cadence {
31+
frequency = "SYNCHRONOUS"
32+
}
33+
}
34+
}

lambdas/functions/iroco2-client-side-scanner/s3.tf

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ resource "aws_s3_bucket_policy" "cur_output" {
4545
{
4646
Effect = "Allow"
4747
Principal = {
48-
AWS = data.aws_caller_identity.current.account_id
48+
AWS = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"
4949
}
5050
Action = "s3:*"
5151
Resource = [
@@ -61,6 +61,34 @@ resource "aws_s3_bucket_policy" "cur_output" {
6161
}
6262
}
6363
},
64+
{
65+
Effect = "Allow"
66+
Principal = {
67+
Service = [
68+
"bcm-data-exports.amazonaws.com",
69+
"billingreports.amazonaws.com"
70+
]
71+
}
72+
Action = [
73+
"s3:GetBucketPolicy",
74+
"s3:PutObject"
75+
]
76+
Resource = [
77+
"arn:aws:s3:::${var.cur_output_bucket_name}",
78+
"arn:aws:s3:::${var.cur_output_bucket_name}/*"
79+
]
80+
Condition = {
81+
StringEquals = {
82+
"aws:SourceAccount" = data.aws_caller_identity.current.account_id,
83+
},
84+
StringLike = {
85+
"aws:SourceArn" = [
86+
"arn:aws:bcm-data-exports:us-east-1:${data.aws_caller_identity.current.account_id}:export/*",
87+
"arn:aws:cur:us-east-1:${data.aws_caller_identity.current.account_id}:definition/*"
88+
]
89+
}
90+
}
91+
},
6492
{
6593
Effect = "Deny"
6694
Principal = {

0 commit comments

Comments
 (0)