Terraform: Add support for dynamo table autoscaling

Created on 4 Jul 2017  路  3Comments  路  Source: hashicorp/terraform

AWS recently added autoscaling functionality to dynamoDB tables, with target utilization, minimum and maximum provisioned capacity. I would like to control this through terraform.

Affected resources

aws_dynamodb_table

References

https://aws.amazon.com/blogs/aws/new-auto-scaling-for-amazon-dynamodb/

enhancement provideaws

Most helpful comment

The AWS provider for Terraform supports DynamoDB Global Secondary Index autoscaling with the existing aws_appautoscaling_target resource: https://www.terraform.io/docs/providers/aws/r/appautoscaling_target.html

While we don't list this specific example, it can be accomplished with a configuration such as:

resource "aws_appautoscaling_target" "dynamodb_index_read_target" {
  max_capacity       = 100
  min_capacity       = 5
  resource_id        = "table/${aws_dynamodb_table.example.name}/index/YourIndexName"
  role_arn           = "${data.aws_iam_role.DynamoDBAutoscaleRole.arn}"
  scalable_dimension = "dynamodb:index:ReadCapacityUnits"
  service_namespace  = "dynamodb"
}

The same works for dynamodb:index:WriteCapacityUnits. To achieve the functionality in the web console that is "Apply same settings to global secondary indexes", I would suggest creating variables that can be used for min/max_capacity or you can pull the attribute from a table target if you have one defined. e.g.

resource "aws_appautoscaling_target" "dynamodb_table_read_target" {
  max_capacity       = 100
  min_capacity       = 5
  resource_id        = "table/${aws_dynamodb_table.example.name}"
  role_arn           = "${data.aws_iam_role.DynamoDBAutoscaleRole.arn}"
  scalable_dimension = "dynamodb:table:ReadCapacityUnits"
  service_namespace  = "dynamodb"
}

resource "aws_appautoscaling_target" "dynamodb_index_read_target" {
  max_capacity       = "${aws_appautoscaling_target.dynamodb_table_read_target.max_capacity}"
  min_capacity       = "${aws_appautoscaling_target.dynamodb_table_read_target.min_capacity}"
  resource_id        = "table/${aws_dynamodb_table.example.name}/index/YourIndexName"
  role_arn           = "${data.aws_iam_role.DynamoDBAutoscaleRole.arn}"
  scalable_dimension = "dynamodb:index:ReadCapacityUnits"
  service_namespace  = "dynamodb"
}

All 3 comments

This issue has been automatically migrated to terraform-providers/terraform-provider-aws#1049 because it looks like an issue with that provider. If you believe this is _not_ an issue with the provider, please reply to this issue and let us know.

Is there a terraform aws_appautoscaling_target for Global Secondary Index? or
Does Terraform support for the ability to 'Apply same settings to global secondary indexes' in DynamoDB ?

The AWS provider for Terraform supports DynamoDB Global Secondary Index autoscaling with the existing aws_appautoscaling_target resource: https://www.terraform.io/docs/providers/aws/r/appautoscaling_target.html

While we don't list this specific example, it can be accomplished with a configuration such as:

resource "aws_appautoscaling_target" "dynamodb_index_read_target" {
  max_capacity       = 100
  min_capacity       = 5
  resource_id        = "table/${aws_dynamodb_table.example.name}/index/YourIndexName"
  role_arn           = "${data.aws_iam_role.DynamoDBAutoscaleRole.arn}"
  scalable_dimension = "dynamodb:index:ReadCapacityUnits"
  service_namespace  = "dynamodb"
}

The same works for dynamodb:index:WriteCapacityUnits. To achieve the functionality in the web console that is "Apply same settings to global secondary indexes", I would suggest creating variables that can be used for min/max_capacity or you can pull the attribute from a table target if you have one defined. e.g.

resource "aws_appautoscaling_target" "dynamodb_table_read_target" {
  max_capacity       = 100
  min_capacity       = 5
  resource_id        = "table/${aws_dynamodb_table.example.name}"
  role_arn           = "${data.aws_iam_role.DynamoDBAutoscaleRole.arn}"
  scalable_dimension = "dynamodb:table:ReadCapacityUnits"
  service_namespace  = "dynamodb"
}

resource "aws_appautoscaling_target" "dynamodb_index_read_target" {
  max_capacity       = "${aws_appautoscaling_target.dynamodb_table_read_target.max_capacity}"
  min_capacity       = "${aws_appautoscaling_target.dynamodb_table_read_target.min_capacity}"
  resource_id        = "table/${aws_dynamodb_table.example.name}/index/YourIndexName"
  role_arn           = "${data.aws_iam_role.DynamoDBAutoscaleRole.arn}"
  scalable_dimension = "dynamodb:index:ReadCapacityUnits"
  service_namespace  = "dynamodb"
}
Was this page helpful?
0 / 5 - 0 ratings