terraform-provider-aws icon indicating copy to clipboard operation
terraform-provider-aws copied to clipboard

Simplify configuration of DynamoDB Global Table Autoscaling

Open GREsau opened this issue 5 years ago • 1 comments

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

Thanks to #12342, it's now extremely easy to manage DynamoDB Global Tables through terraform. However, it gets much more complicated when you want to enable autoscaling on these tables. Currently, you need to specify an aws_appautoscaling_policy and an aws_appautoscaling_target for each table and index for each replica. Because each replica will be in a different region, you'll also need to do this using multiple AWS providers, which can be difficult due to terraform restrictions on dynamically configuring providers/aliases.

Fortunately, DynamoDB surfaces some APIs (DescribeTableReplicaAutoScaling + UpdateTableReplicaAutoScaling) that allow configuring a table's autoscaling across all replicas/regions at once. If a terraform resource used that API, it would make autoscaling configuration much easier.

New or Affected Resource(s)

  • new resource e.g. aws_dynamodb_table_replica_autoscaling

Potential Terraform Configuration

resource "aws_dynamodb_table_replica_autoscaling" "dynamodb-autoscaling" {
  table_name = "GameScores"
  
  write_capacity {
    policy_name = "optional autoscaling policy name"
    role_arn    = "optional autoscaling policy role ARN"

    min_units = 10
    max_units = 100

    target_value       = 50
    disable_scale_in   = false
    scale_in_cooldown  = 60
    scale_out_cooldown = 60
  }
  
  # this block can be specified multiple times for tables with multiple GSIs
  global_secondary_index {
    index_name = "GameTitleIndex"

    write_capacity {
      # same format as earlier write_capacity block...
    }
  }

  replica {
    region_name = "us-west-2"

    read_capacity {
      # same format as earlier write_capacity blocks...
    }

    global_secondary_index {
      index_name = "GameTitleIndex"

      read_capacity {
        # same format as earlier read_capacity/write_capacity blocks...
      }
    }
  }

  replica {
    region_name = "us-east-2"

    # etc...
  }
}

References

GREsau avatar May 07 '20 15:05 GREsau