Search code examples
amazon-web-servicesterraformterraform-provider-aws

AWS Terraform aws_cur_report_definition is hanging for so long


Running Terraform, hangs when trying to run terraform apply and create aws_cur_report_definition. please see the code below:

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "5.42.0"
    }
  }
}

provider "aws" {
  profile = "xxxxxxxxx"
  region =  "eu-west-1"
}
    
resource "aws_cur_report_definition" "cost_and_usage_report" {
  report_name                = "my_cost_and_usage_report_test"
  time_unit                  = "HOURLY"
  format                     = "Parquet"
  compression                = "Parquet"
  additional_schema_elements = ["RESOURCES"]
  s3_bucket                  = "cur-grafana-test"
  s3_region                  = "us-east-1" 
  additional_artifacts       = ["ATHENA"]
  s3_prefix                  = "/test"
  report_versioning          = "OVERWRITE_REPORT"
}

Having the same issue when trying to create a data for an existing aws_cur_report_definition

It took more than 9 minutes and nothing is showing up, the terraform apply is just hanging

data.aws_cur_report_definition.report_definition: Still reading... [6m31s elapsed] data.aws_cur_report_definition.report_definition: Still reading... [6m41s elapsed] data.aws_cur_report_definition.report_definition: Still reading... [6m51s elapsed] data.aws_cur_report_definition.report_definition: Still reading... [7m1s elapsed] data.aws_cur_report_definition.report_definition: Still reading... [7m11s elapsed] data.aws_cur_report_definition.report_definition: Still reading... [7m21s elapsed] data.aws_cur_report_definition.report_definition: Still reading... [7m31s elapsed] data.aws_cur_report_definition.report_definition: Still reading... [7m41s elapsed] data.aws_cur_report_definition.report_definition: Still reading... [7m51s elapsed] data.aws_cur_report_definition.report_definition: Still reading... [8m1s elapsed] data.aws_cur_report_definition.report_definition: Still reading... [8m11s elapsed] data.aws_cur_report_definition.report_definition: Still reading... [8m21s elapsed] data.aws_cur_report_definition.report_definition: Still reading... [8m31s elapsed] data.aws_cur_report_definition.report_definition: Still reading... [8m41s elapsed] data.aws_cur_report_definition.report_definition: Still reading... [8m51s elapsed] data.aws_cur_report_definition.report_definition: Still reading... [9m1s elapsed] data.aws_cur_report_definition.report_definition: Still reading... [9m11s elapsed]


Solution

  • There are two things that are important to note here:

    1. Your provider configuration is using eu-west-1, meaning that any resource created without specifying a provider alias is created using the existing provider configuration
    2. If you take a closer look at the resource documentation (the note at the top of the documentation) it says the following:

    NOTE: The AWS Cost and Usage Report service is only available in us-east-1 currently.

    This further means that you need to create a provider alias for the us-east-1 region and use it with the resource, something like the following:

    provider "aws" {
      profile = "xxxxxxxxx"
      region  = "eu-west-1"
    }
    
    provider "aws" {
      alias   = "us-east-1"
      profile = "xxxxxxxxx"
      region  = "us-east-1"
    }
    
    resource "aws_cur_report_definition" "cost_and_usage_report" {
      provider                   = aws.us-east-1
      report_name                = "my_cost_and_usage_report_test"
      time_unit                  = "HOURLY"
      format                     = "Parquet"
      compression                = "Parquet"
      additional_schema_elements = ["RESOURCES"]
      s3_bucket                  = "cur-grafana-test"
      s3_region                  = "us-east-1" 
      additional_artifacts       = ["ATHENA"]
      s3_prefix                  = "/test"
      report_versioning          = "OVERWRITE_REPORT"
    }