AWSTemplateFormatVersion: 2010-09-09
Description: ScaleOps CUR Data Export Stack

Parameters:
  dataExportName:
    Type: String
    Description: Name of the data export
    Default: scaleops-cost-report
  s3BucketName:
    Type: String
    Description: Name of the S3 bucket to receive CUR data
  s3Region:
    Type: String
    Description: Region of the S3 bucket to receive CUR data
    Default: us-east-1
  s3Prefix:
    Type: String
    Description: Path prefix of the CUR data in the S3 bucket
    Default: cur-reports

Resources:
  CostAndUsageReportDefinition:
    Type: AWS::BCMDataExports::Export
    Properties:
      Export:
        DataQuery:
          QueryStatement: "SELECT bill_payer_account_id, line_item_line_item_type, line_item_net_unblended_cost, line_item_net_unblended_rate, line_item_operation, line_item_product_code, line_item_resource_id, line_item_unblended_cost, line_item_unblended_rate, line_item_usage_account_id, line_item_usage_amount, line_item_usage_end_date, line_item_usage_start_date, line_item_usage_type, pricing_public_on_demand_cost, pricing_public_on_demand_rate, pricing_term, product_product_family, product_region_code, product_servicecode, product_sku, savings_plan_savings_plan_effective_cost, savings_plan_net_savings_plan_effective_cost, savings_plan_savings_plan_rate, savings_plan_savings_plan_a_r_n, savings_plan_start_time, savings_plan_end_time, savings_plan_offering_type, savings_plan_payment_option, savings_plan_purchase_term, savings_plan_total_commitment_to_date, savings_plan_amortized_upfront_commitment_for_billing_period, savings_plan_instance_type_family, savings_plan_net_amortized_upfront_commitment_for_billing_period, savings_plan_net_recurring_commitment_for_billing_period, savings_plan_recurring_commitment_for_billing_period, reservation_effective_cost, reservation_reservation_a_r_n, reservation_start_time, reservation_end_time, reservation_amortized_upfront_cost_for_usage, reservation_amortized_upfront_fee_for_billing_period, reservation_availability_zone, reservation_modification_status, reservation_subscription_id, reservation_number_of_reservations, reservation_upfront_value, reservation_recurring_fee_for_usage, pricing_rate_code, pricing_lease_contract_length, pricing_offering_class, pricing_purchase_option, line_item_currency_code, line_item_line_item_description, product_instance_type, line_item_availability_zone, resource_tags FROM COST_AND_USAGE_REPORT WHERE (product_product_family = 'Compute Instance' OR product_product_family = 'Compute') AND (product_servicecode = 'AmazonEC2' OR product_servicecode = 'AmazonEKS')"
          TableConfigurations:
            COST_AND_USAGE_REPORT:
              INCLUDE_MANUAL_DISCOUNT_COMPATIBILITY: "FALSE"
              INCLUDE_RESOURCES: "TRUE"
              INCLUDE_SPLIT_COST_ALLOCATION_DATA: "FALSE"
              TIME_GRANULARITY: "MONTHLY"
        DestinationConfigurations:
          S3Destination:
            S3Bucket: !Ref s3BucketName
            S3Region: !Ref s3Region
            S3Prefix: !Ref s3Prefix
            S3OutputConfigurations:
              Compression: "GZIP"
              Format: "TEXT_OR_CSV"
              OutputType: "CUSTOM"
              Overwrite: "OVERWRITE_REPORT"
        Name: !Ref dataExportName
        RefreshCadence:
          Frequency: "SYNCHRONOUS"
