From 173a458d48d76004ea646588ec1ecf0ad4d06495 Mon Sep 17 00:00:00 2001 From: nitrocode Date: Tue, 26 Oct 2021 11:27:30 -0500 Subject: [PATCH] Feat: Add Index Read/Write Values for Capacity and Target (#43) * Add index values vars * Add index value vars * Auto Format Co-authored-by: cloudpossebot <11232728+cloudpossebot@users.noreply.github.com> --- README.md | 6 ++++++ docs/terraform.md | 6 ++++++ main.tf | 12 ++++++------ variables.tf | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index bd0d095..d6c7712 100644 --- a/README.md +++ b/README.md @@ -173,11 +173,17 @@ Available targets: | [additional\_tag\_map](#input\_additional\_tag\_map) | Additional key-value pairs to add to each map in `tags_as_list_of_maps`. Not added to `tags` or `id`.
This is for some rare cases where resources want additional configuration of tags
and therefore take a list of maps with tag key, value, and additional configuration. | `map(string)` | `{}` | no | | [attributes](#input\_attributes) | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,
in the order they appear in the list. New attributes are appended to the
end of the list. The elements of the list are joined by the `delimiter`
and treated as a single ID element. | `list(string)` | `[]` | no | | [autoscale\_max\_read\_capacity](#input\_autoscale\_max\_read\_capacity) | DynamoDB autoscaling max read capacity | `number` | `20` | no | +| [autoscale\_max\_read\_capacity\_index](#input\_autoscale\_max\_read\_capacity\_index) | DynamoDB autoscaling max read capacity of the index | `number` | `null` | no | | [autoscale\_max\_write\_capacity](#input\_autoscale\_max\_write\_capacity) | DynamoDB autoscaling max write capacity | `number` | `20` | no | +| [autoscale\_max\_write\_capacity\_index](#input\_autoscale\_max\_write\_capacity\_index) | DynamoDB autoscaling max write capacity of the index | `number` | `null` | no | | [autoscale\_min\_read\_capacity](#input\_autoscale\_min\_read\_capacity) | DynamoDB autoscaling min read capacity | `number` | `5` | no | +| [autoscale\_min\_read\_capacity\_index](#input\_autoscale\_min\_read\_capacity\_index) | DynamoDB autoscaling min read capacity of the index | `number` | `null` | no | | [autoscale\_min\_write\_capacity](#input\_autoscale\_min\_write\_capacity) | DynamoDB autoscaling min write capacity | `number` | `5` | no | +| [autoscale\_min\_write\_capacity\_index](#input\_autoscale\_min\_write\_capacity\_index) | DynamoDB autoscaling min write capacity of the index | `number` | `null` | no | | [autoscale\_read\_target](#input\_autoscale\_read\_target) | The target value for DynamoDB read autoscaling | `number` | `50` | no | +| [autoscale\_read\_target\_index](#input\_autoscale\_read\_target\_index) | The target value for DynamoDB read autoscaling of the index | `number` | `null` | no | | [autoscale\_write\_target](#input\_autoscale\_write\_target) | The target value for DynamoDB write autoscaling | `number` | `50` | no | +| [autoscale\_write\_target\_index](#input\_autoscale\_write\_target\_index) | The target value for DynamoDB write autoscaling of the index | `number` | `null` | no | | [context](#input\_context) | Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional\_tag\_map, which are merged. | `any` |
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"descriptor_formats": {},
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_key_case": null,
"label_order": [],
"label_value_case": null,
"labels_as_tags": [
"unset"
],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {},
"tenant": null
}
| no | | [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no | | [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.
Map of maps. Keys are names of descriptors. Values are maps of the form
`{
format = string
labels = list(string)
}`
(Type is `any` so the map values can later be enhanced to provide additional options.)
`format` is a Terraform format string to be passed to the `format()` function.
`labels` is a list of labels, in order, to pass to `format()` function.
Label values will be normalized before being passed to `format()` so they will be
identical to how they appear in `id`.
Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no | diff --git a/docs/terraform.md b/docs/terraform.md index 14ba779..4a01320 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -39,11 +39,17 @@ | [additional\_tag\_map](#input\_additional\_tag\_map) | Additional key-value pairs to add to each map in `tags_as_list_of_maps`. Not added to `tags` or `id`.
This is for some rare cases where resources want additional configuration of tags
and therefore take a list of maps with tag key, value, and additional configuration. | `map(string)` | `{}` | no | | [attributes](#input\_attributes) | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,
in the order they appear in the list. New attributes are appended to the
end of the list. The elements of the list are joined by the `delimiter`
and treated as a single ID element. | `list(string)` | `[]` | no | | [autoscale\_max\_read\_capacity](#input\_autoscale\_max\_read\_capacity) | DynamoDB autoscaling max read capacity | `number` | `20` | no | +| [autoscale\_max\_read\_capacity\_index](#input\_autoscale\_max\_read\_capacity\_index) | DynamoDB autoscaling max read capacity of the index | `number` | `null` | no | | [autoscale\_max\_write\_capacity](#input\_autoscale\_max\_write\_capacity) | DynamoDB autoscaling max write capacity | `number` | `20` | no | +| [autoscale\_max\_write\_capacity\_index](#input\_autoscale\_max\_write\_capacity\_index) | DynamoDB autoscaling max write capacity of the index | `number` | `null` | no | | [autoscale\_min\_read\_capacity](#input\_autoscale\_min\_read\_capacity) | DynamoDB autoscaling min read capacity | `number` | `5` | no | +| [autoscale\_min\_read\_capacity\_index](#input\_autoscale\_min\_read\_capacity\_index) | DynamoDB autoscaling min read capacity of the index | `number` | `null` | no | | [autoscale\_min\_write\_capacity](#input\_autoscale\_min\_write\_capacity) | DynamoDB autoscaling min write capacity | `number` | `5` | no | +| [autoscale\_min\_write\_capacity\_index](#input\_autoscale\_min\_write\_capacity\_index) | DynamoDB autoscaling min write capacity of the index | `number` | `null` | no | | [autoscale\_read\_target](#input\_autoscale\_read\_target) | The target value for DynamoDB read autoscaling | `number` | `50` | no | +| [autoscale\_read\_target\_index](#input\_autoscale\_read\_target\_index) | The target value for DynamoDB read autoscaling of the index | `number` | `null` | no | | [autoscale\_write\_target](#input\_autoscale\_write\_target) | The target value for DynamoDB write autoscaling | `number` | `50` | no | +| [autoscale\_write\_target\_index](#input\_autoscale\_write\_target\_index) | The target value for DynamoDB write autoscaling of the index | `number` | `null` | no | | [context](#input\_context) | Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional\_tag\_map, which are merged. | `any` |
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"descriptor_formats": {},
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_key_case": null,
"label_order": [],
"label_value_case": null,
"labels_as_tags": [
"unset"
],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {},
"tenant": null
}
| no | | [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no | | [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.
Map of maps. Keys are names of descriptors. Values are maps of the form
`{
format = string
labels = list(string)
}`
(Type is `any` so the map values can later be enhanced to provide additional options.)
`format` is a Terraform format string to be passed to the `format()` function.
`labels` is a list of labels, in order, to pass to `format()` function.
Label values will be normalized before being passed to `format()` so they will be
identical to how they appear in `id`.
Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no | diff --git a/main.tf b/main.tf index 98b9610..64b039b 100644 --- a/main.tf +++ b/main.tf @@ -9,8 +9,8 @@ resource "aws_appautoscaling_target" "read_target" { resource "aws_appautoscaling_target" "read_target_index" { for_each = module.this.enabled ? toset(var.dynamodb_indexes) : toset([]) - max_capacity = var.autoscale_max_read_capacity - min_capacity = var.autoscale_min_read_capacity + max_capacity = coalesce(var.autoscale_max_read_capacity_index, var.autoscale_max_read_capacity) + min_capacity = coalesce(var.autoscale_min_read_capacity_index, var.autoscale_min_read_capacity) resource_id = "table/${var.dynamodb_table_name}/index/${each.key}" scalable_dimension = "dynamodb:index:ReadCapacityUnits" service_namespace = "dynamodb" @@ -49,7 +49,7 @@ resource "aws_appautoscaling_policy" "read_policy_index" { predefined_metric_type = "DynamoDBReadCapacityUtilization" } - target_value = var.autoscale_read_target + target_value = coalesce(var.autoscale_read_target_index, var.autoscale_read_target) } } @@ -64,8 +64,8 @@ resource "aws_appautoscaling_target" "write_target" { resource "aws_appautoscaling_target" "write_target_index" { for_each = module.this.enabled ? toset(var.dynamodb_indexes) : toset([]) - max_capacity = var.autoscale_max_write_capacity - min_capacity = var.autoscale_min_write_capacity + max_capacity = coalesce(var.autoscale_max_write_capacity_index, var.autoscale_max_write_capacity) + min_capacity = coalesce(var.autoscale_min_write_capacity_index, var.autoscale_min_write_capacity) resource_id = "table/${var.dynamodb_table_name}/index/${each.key}" scalable_dimension = "dynamodb:index:WriteCapacityUnits" service_namespace = "dynamodb" @@ -104,6 +104,6 @@ resource "aws_appautoscaling_policy" "write_policy_index" { predefined_metric_type = "DynamoDBWriteCapacityUtilization" } - target_value = var.autoscale_write_target + target_value = coalesce(var.autoscale_write_target_index, var.autoscale_write_target) } } diff --git a/variables.tf b/variables.tf index 3139de4..64fcdd6 100644 --- a/variables.tf +++ b/variables.tf @@ -49,3 +49,39 @@ variable "autoscale_max_write_capacity" { default = 20 description = "DynamoDB autoscaling max write capacity" } + +variable "autoscale_write_target_index" { + type = number + default = null + description = "The target value for DynamoDB write autoscaling of the index" +} + +variable "autoscale_read_target_index" { + type = number + default = null + description = "The target value for DynamoDB read autoscaling of the index" +} + +variable "autoscale_min_read_capacity_index" { + type = number + default = null + description = "DynamoDB autoscaling min read capacity of the index" +} + +variable "autoscale_max_read_capacity_index" { + type = number + default = null + description = "DynamoDB autoscaling max read capacity of the index" +} + +variable "autoscale_min_write_capacity_index" { + type = number + default = null + description = "DynamoDB autoscaling min write capacity of the index" +} + +variable "autoscale_max_write_capacity_index" { + type = number + default = null + description = "DynamoDB autoscaling max write capacity of the index" +}