From 622ce1ed882249757ef80e38c17da5d93e69444c Mon Sep 17 00:00:00 2001 From: Tim Gatzemeier Date: Fri, 9 Oct 2020 17:19:54 +0200 Subject: [PATCH] allow to add additional attributes and tags to autoscaler (#52) * allow to add additional attributes and tags to autoscaler This is to avoid adding a region prefix to dynamodb tables because the autoscaler IAM role requires additional region indicator in its names * use map type for tags variable * remove markdown comments from diff * Updated README.md Co-authored-by: actions-bot <58130806+actions-bot@users.noreply.github.com> --- README.md | 2 ++ docs/terraform.md | 2 ++ main.tf | 4 ++-- variables.tf | 12 ++++++++++++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 73661d2..da41e1b 100644 --- a/README.md +++ b/README.md @@ -224,6 +224,8 @@ Available targets: | autoscale\_min\_write\_capacity | DynamoDB autoscaling min write capacity | `number` | `5` | no | | autoscale\_read\_target | The target value (in %) for DynamoDB read autoscaling | `number` | `50` | no | | autoscale\_write\_target | The target value (in %) for DynamoDB write autoscaling | `number` | `50` | no | +| autoscaler\_attributes | Additional attributes for the autoscaler module | `list(string)` | `[]` | no | +| autoscaler\_tags | Additional resource tags for the autoscaler module | `map(string)` | `{}` | no | | billing\_mode | DynamoDB Billing mode. Can be PROVISIONED or PAY\_PER\_REQUEST | `string` | `"PROVISIONED"` | no | | delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes` | `string` | `"-"` | no | | dynamodb\_attributes | Additional DynamoDB attributes in the form of a list of mapped values |
list(object({
name = string
type = string
}))
| `[]` | no | diff --git a/docs/terraform.md b/docs/terraform.md index 649ffe8..ad22c76 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -25,6 +25,8 @@ | autoscale\_min\_write\_capacity | DynamoDB autoscaling min write capacity | `number` | `5` | no | | autoscale\_read\_target | The target value (in %) for DynamoDB read autoscaling | `number` | `50` | no | | autoscale\_write\_target | The target value (in %) for DynamoDB write autoscaling | `number` | `50` | no | +| autoscaler\_attributes | Additional attributes for the autoscaler module | `list(string)` | `[]` | no | +| autoscaler\_tags | Additional resource tags for the autoscaler module | `map(string)` | `{}` | no | | billing\_mode | DynamoDB Billing mode. Can be PROVISIONED or PAY\_PER\_REQUEST | `string` | `"PROVISIONED"` | no | | delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes` | `string` | `"-"` | no | | dynamodb\_attributes | Additional DynamoDB attributes in the form of a list of mapped values |
list(object({
name = string
type = string
}))
| `[]` | no | diff --git a/main.tf b/main.tf index ca127ef..5d62918 100644 --- a/main.tf +++ b/main.tf @@ -127,8 +127,8 @@ module "dynamodb_autoscaler" { environment = var.environment name = var.name delimiter = var.delimiter - attributes = var.attributes - tags = module.dynamodb_label.tags + attributes = concat(var.attributes, var.autoscaler_attributes) + tags = merge(module.dynamodb_label.tags, var.autoscaler_tags) dynamodb_table_name = join("", aws_dynamodb_table.default.*.id) dynamodb_table_arn = join("", aws_dynamodb_table.default.*.arn) dynamodb_indexes = null_resource.global_secondary_index_names.*.triggers.name diff --git a/variables.tf b/variables.tf index 1f91d0d..1faebd1 100644 --- a/variables.tf +++ b/variables.tf @@ -147,6 +147,18 @@ variable "enable_autoscaler" { description = "Flag to enable/disable DynamoDB autoscaling" } +variable "autoscaler_attributes" { + type = list(string) + default = [] + description = "Additional attributes for the autoscaler module" +} + +variable "autoscaler_tags" { + type = map(string) + default = {} + description = "Additional resource tags for the autoscaler module" +} + variable "dynamodb_attributes" { type = list(object({ name = string