Skip to content

Commit 173a458

Browse files
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>
1 parent b9a49c0 commit 173a458

File tree

4 files changed

+54
-6
lines changed

4 files changed

+54
-6
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,17 @@ Available targets:
173173
| <a name="input_additional_tag_map"></a> [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`.<br>This is for some rare cases where resources want additional configuration of tags<br>and therefore take a list of maps with tag key, value, and additional configuration. | `map(string)` | `{}` | no |
174174
| <a name="input_attributes"></a> [attributes](#input\_attributes) | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,<br>in the order they appear in the list. New attributes are appended to the<br>end of the list. The elements of the list are joined by the `delimiter`<br>and treated as a single ID element. | `list(string)` | `[]` | no |
175175
| <a name="input_autoscale_max_read_capacity"></a> [autoscale\_max\_read\_capacity](#input\_autoscale\_max\_read\_capacity) | DynamoDB autoscaling max read capacity | `number` | `20` | no |
176+
| <a name="input_autoscale_max_read_capacity_index"></a> [autoscale\_max\_read\_capacity\_index](#input\_autoscale\_max\_read\_capacity\_index) | DynamoDB autoscaling max read capacity of the index | `number` | `null` | no |
176177
| <a name="input_autoscale_max_write_capacity"></a> [autoscale\_max\_write\_capacity](#input\_autoscale\_max\_write\_capacity) | DynamoDB autoscaling max write capacity | `number` | `20` | no |
178+
| <a name="input_autoscale_max_write_capacity_index"></a> [autoscale\_max\_write\_capacity\_index](#input\_autoscale\_max\_write\_capacity\_index) | DynamoDB autoscaling max write capacity of the index | `number` | `null` | no |
177179
| <a name="input_autoscale_min_read_capacity"></a> [autoscale\_min\_read\_capacity](#input\_autoscale\_min\_read\_capacity) | DynamoDB autoscaling min read capacity | `number` | `5` | no |
180+
| <a name="input_autoscale_min_read_capacity_index"></a> [autoscale\_min\_read\_capacity\_index](#input\_autoscale\_min\_read\_capacity\_index) | DynamoDB autoscaling min read capacity of the index | `number` | `null` | no |
178181
| <a name="input_autoscale_min_write_capacity"></a> [autoscale\_min\_write\_capacity](#input\_autoscale\_min\_write\_capacity) | DynamoDB autoscaling min write capacity | `number` | `5` | no |
182+
| <a name="input_autoscale_min_write_capacity_index"></a> [autoscale\_min\_write\_capacity\_index](#input\_autoscale\_min\_write\_capacity\_index) | DynamoDB autoscaling min write capacity of the index | `number` | `null` | no |
179183
| <a name="input_autoscale_read_target"></a> [autoscale\_read\_target](#input\_autoscale\_read\_target) | The target value for DynamoDB read autoscaling | `number` | `50` | no |
184+
| <a name="input_autoscale_read_target_index"></a> [autoscale\_read\_target\_index](#input\_autoscale\_read\_target\_index) | The target value for DynamoDB read autoscaling of the index | `number` | `null` | no |
180185
| <a name="input_autoscale_write_target"></a> [autoscale\_write\_target](#input\_autoscale\_write\_target) | The target value for DynamoDB write autoscaling | `number` | `50` | no |
186+
| <a name="input_autoscale_write_target_index"></a> [autoscale\_write\_target\_index](#input\_autoscale\_write\_target\_index) | The target value for DynamoDB write autoscaling of the index | `number` | `null` | no |
181187
| <a name="input_context"></a> [context](#input\_context) | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "descriptor_formats": {},<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_key_case": null,<br> "label_order": [],<br> "label_value_case": null,<br> "labels_as_tags": [<br> "unset"<br> ],<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {},<br> "tenant": null<br>}</pre> | no |
182188
| <a name="input_delimiter"></a> [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.<br>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
183189
| <a name="input_descriptor_formats"></a> [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.<br>Map of maps. Keys are names of descriptors. Values are maps of the form<br>`{<br> format = string<br> labels = list(string)<br>}`<br>(Type is `any` so the map values can later be enhanced to provide additional options.)<br>`format` is a Terraform format string to be passed to the `format()` function.<br>`labels` is a list of labels, in order, to pass to `format()` function.<br>Label values will be normalized before being passed to `format()` so they will be<br>identical to how they appear in `id`.<br>Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no |

docs/terraform.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,17 @@
3939
| <a name="input_additional_tag_map"></a> [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`.<br>This is for some rare cases where resources want additional configuration of tags<br>and therefore take a list of maps with tag key, value, and additional configuration. | `map(string)` | `{}` | no |
4040
| <a name="input_attributes"></a> [attributes](#input\_attributes) | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,<br>in the order they appear in the list. New attributes are appended to the<br>end of the list. The elements of the list are joined by the `delimiter`<br>and treated as a single ID element. | `list(string)` | `[]` | no |
4141
| <a name="input_autoscale_max_read_capacity"></a> [autoscale\_max\_read\_capacity](#input\_autoscale\_max\_read\_capacity) | DynamoDB autoscaling max read capacity | `number` | `20` | no |
42+
| <a name="input_autoscale_max_read_capacity_index"></a> [autoscale\_max\_read\_capacity\_index](#input\_autoscale\_max\_read\_capacity\_index) | DynamoDB autoscaling max read capacity of the index | `number` | `null` | no |
4243
| <a name="input_autoscale_max_write_capacity"></a> [autoscale\_max\_write\_capacity](#input\_autoscale\_max\_write\_capacity) | DynamoDB autoscaling max write capacity | `number` | `20` | no |
44+
| <a name="input_autoscale_max_write_capacity_index"></a> [autoscale\_max\_write\_capacity\_index](#input\_autoscale\_max\_write\_capacity\_index) | DynamoDB autoscaling max write capacity of the index | `number` | `null` | no |
4345
| <a name="input_autoscale_min_read_capacity"></a> [autoscale\_min\_read\_capacity](#input\_autoscale\_min\_read\_capacity) | DynamoDB autoscaling min read capacity | `number` | `5` | no |
46+
| <a name="input_autoscale_min_read_capacity_index"></a> [autoscale\_min\_read\_capacity\_index](#input\_autoscale\_min\_read\_capacity\_index) | DynamoDB autoscaling min read capacity of the index | `number` | `null` | no |
4447
| <a name="input_autoscale_min_write_capacity"></a> [autoscale\_min\_write\_capacity](#input\_autoscale\_min\_write\_capacity) | DynamoDB autoscaling min write capacity | `number` | `5` | no |
48+
| <a name="input_autoscale_min_write_capacity_index"></a> [autoscale\_min\_write\_capacity\_index](#input\_autoscale\_min\_write\_capacity\_index) | DynamoDB autoscaling min write capacity of the index | `number` | `null` | no |
4549
| <a name="input_autoscale_read_target"></a> [autoscale\_read\_target](#input\_autoscale\_read\_target) | The target value for DynamoDB read autoscaling | `number` | `50` | no |
50+
| <a name="input_autoscale_read_target_index"></a> [autoscale\_read\_target\_index](#input\_autoscale\_read\_target\_index) | The target value for DynamoDB read autoscaling of the index | `number` | `null` | no |
4651
| <a name="input_autoscale_write_target"></a> [autoscale\_write\_target](#input\_autoscale\_write\_target) | The target value for DynamoDB write autoscaling | `number` | `50` | no |
52+
| <a name="input_autoscale_write_target_index"></a> [autoscale\_write\_target\_index](#input\_autoscale\_write\_target\_index) | The target value for DynamoDB write autoscaling of the index | `number` | `null` | no |
4753
| <a name="input_context"></a> [context](#input\_context) | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "descriptor_formats": {},<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_key_case": null,<br> "label_order": [],<br> "label_value_case": null,<br> "labels_as_tags": [<br> "unset"<br> ],<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {},<br> "tenant": null<br>}</pre> | no |
4854
| <a name="input_delimiter"></a> [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.<br>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
4955
| <a name="input_descriptor_formats"></a> [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.<br>Map of maps. Keys are names of descriptors. Values are maps of the form<br>`{<br> format = string<br> labels = list(string)<br>}`<br>(Type is `any` so the map values can later be enhanced to provide additional options.)<br>`format` is a Terraform format string to be passed to the `format()` function.<br>`labels` is a list of labels, in order, to pass to `format()` function.<br>Label values will be normalized before being passed to `format()` so they will be<br>identical to how they appear in `id`.<br>Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no |

main.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ resource "aws_appautoscaling_target" "read_target" {
99

1010
resource "aws_appautoscaling_target" "read_target_index" {
1111
for_each = module.this.enabled ? toset(var.dynamodb_indexes) : toset([])
12-
max_capacity = var.autoscale_max_read_capacity
13-
min_capacity = var.autoscale_min_read_capacity
12+
max_capacity = coalesce(var.autoscale_max_read_capacity_index, var.autoscale_max_read_capacity)
13+
min_capacity = coalesce(var.autoscale_min_read_capacity_index, var.autoscale_min_read_capacity)
1414
resource_id = "table/${var.dynamodb_table_name}/index/${each.key}"
1515
scalable_dimension = "dynamodb:index:ReadCapacityUnits"
1616
service_namespace = "dynamodb"
@@ -49,7 +49,7 @@ resource "aws_appautoscaling_policy" "read_policy_index" {
4949
predefined_metric_type = "DynamoDBReadCapacityUtilization"
5050
}
5151

52-
target_value = var.autoscale_read_target
52+
target_value = coalesce(var.autoscale_read_target_index, var.autoscale_read_target)
5353
}
5454
}
5555

@@ -64,8 +64,8 @@ resource "aws_appautoscaling_target" "write_target" {
6464

6565
resource "aws_appautoscaling_target" "write_target_index" {
6666
for_each = module.this.enabled ? toset(var.dynamodb_indexes) : toset([])
67-
max_capacity = var.autoscale_max_write_capacity
68-
min_capacity = var.autoscale_min_write_capacity
67+
max_capacity = coalesce(var.autoscale_max_write_capacity_index, var.autoscale_max_write_capacity)
68+
min_capacity = coalesce(var.autoscale_min_write_capacity_index, var.autoscale_min_write_capacity)
6969
resource_id = "table/${var.dynamodb_table_name}/index/${each.key}"
7070
scalable_dimension = "dynamodb:index:WriteCapacityUnits"
7171
service_namespace = "dynamodb"
@@ -104,6 +104,6 @@ resource "aws_appautoscaling_policy" "write_policy_index" {
104104
predefined_metric_type = "DynamoDBWriteCapacityUtilization"
105105
}
106106

107-
target_value = var.autoscale_write_target
107+
target_value = coalesce(var.autoscale_write_target_index, var.autoscale_write_target)
108108
}
109109
}

variables.tf

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,39 @@ variable "autoscale_max_write_capacity" {
4949
default = 20
5050
description = "DynamoDB autoscaling max write capacity"
5151
}
52+
53+
variable "autoscale_write_target_index" {
54+
type = number
55+
default = null
56+
description = "The target value for DynamoDB write autoscaling of the index"
57+
}
58+
59+
variable "autoscale_read_target_index" {
60+
type = number
61+
default = null
62+
description = "The target value for DynamoDB read autoscaling of the index"
63+
}
64+
65+
variable "autoscale_min_read_capacity_index" {
66+
type = number
67+
default = null
68+
description = "DynamoDB autoscaling min read capacity of the index"
69+
}
70+
71+
variable "autoscale_max_read_capacity_index" {
72+
type = number
73+
default = null
74+
description = "DynamoDB autoscaling max read capacity of the index"
75+
}
76+
77+
variable "autoscale_min_write_capacity_index" {
78+
type = number
79+
default = null
80+
description = "DynamoDB autoscaling min write capacity of the index"
81+
}
82+
83+
variable "autoscale_max_write_capacity_index" {
84+
type = number
85+
default = null
86+
description = "DynamoDB autoscaling max write capacity of the index"
87+
}

0 commit comments

Comments
 (0)