Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add schedule scaling possibility (#47) #48

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ Available targets:

| Name | Source | Version |
|------|--------|---------|
| <a name="module_read_label"></a> [read\_label](#module\_read\_label) | cloudposse/label/null | 0.25.0 |
| <a name="module_read_schedule_index"></a> [read\_schedule\_index](#module\_read\_schedule\_index) | ./schedule-index | n/a |
| <a name="module_this"></a> [this](#module\_this) | cloudposse/label/null | 0.25.0 |
| <a name="module_write_label"></a> [write\_label](#module\_write\_label) | cloudposse/label/null | 0.25.0 |
| <a name="module_write_schedule_index"></a> [write\_schedule\_index](#module\_write\_schedule\_index) | ./schedule-index | n/a |

## Resources

Expand All @@ -161,6 +165,8 @@ Available targets:
| [aws_appautoscaling_policy.read_policy_index](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/appautoscaling_policy) | resource |
| [aws_appautoscaling_policy.write_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/appautoscaling_policy) | resource |
| [aws_appautoscaling_policy.write_policy_index](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/appautoscaling_policy) | resource |
| [aws_appautoscaling_scheduled_action.read_schedule](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/appautoscaling_scheduled_action) | resource |
| [aws_appautoscaling_scheduled_action.write_schedule](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/appautoscaling_scheduled_action) | resource |
| [aws_appautoscaling_target.read_target](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/appautoscaling_target) | resource |
| [aws_appautoscaling_target.read_target_index](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/appautoscaling_target) | resource |
| [aws_appautoscaling_target.write_target](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/appautoscaling_target) | resource |
Expand All @@ -180,8 +186,12 @@ Available targets:
| <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 |
| <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 |
| <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 |
| <a name="input_autoscale_read_schedule"></a> [autoscale\_read\_schedule](#input\_autoscale\_read\_schedule) | Provides an DynamoDB autoscaling scheduled action resource | <pre>list(object({<br> schedule = string<br> min_capacity = number<br> max_capacity = number<br> }))</pre> | `[]` | no |
| <a name="input_autoscale_read_schedule_index"></a> [autoscale\_read\_schedule\_index](#input\_autoscale\_read\_schedule\_index) | Provides an DynamoDB autoscaling scheduled action resource for the index | <pre>list(object({<br> schedule = string<br> min_capacity = number<br> max_capacity = number<br> }))</pre> | `[]` | no |
| <a name="input_autoscale_read_target"></a> [autoscale\_read\_target](#input\_autoscale\_read\_target) | The target value for DynamoDB read autoscaling | `number` | `50` | no |
| <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 |
| <a name="input_autoscale_write_schedule"></a> [autoscale\_write\_schedule](#input\_autoscale\_write\_schedule) | Provides an DynamoDB autoscaling scheduled action resource | <pre>list(object({<br> schedule = string<br> min_capacity = number<br> max_capacity = number<br> }))</pre> | `[]` | no |
| <a name="input_autoscale_write_schedule_index"></a> [autoscale\_write\_schedule\_index](#input\_autoscale\_write\_schedule\_index) | Provides an DynamoDB autoscaling scheduled action resource for the index | <pre>list(object({<br> schedule = string<br> min_capacity = number<br> max_capacity = number<br> }))</pre> | `[]` | no |
| <a name="input_autoscale_write_target"></a> [autoscale\_write\_target](#input\_autoscale\_write\_target) | The target value for DynamoDB write autoscaling | `number` | `50` | no |
| <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 |
| <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 |
Expand Down
10 changes: 10 additions & 0 deletions docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@

| Name | Source | Version |
|------|--------|---------|
| <a name="module_read_label"></a> [read\_label](#module\_read\_label) | cloudposse/label/null | 0.25.0 |
| <a name="module_read_schedule_index"></a> [read\_schedule\_index](#module\_read\_schedule\_index) | ./schedule-index | n/a |
| <a name="module_this"></a> [this](#module\_this) | cloudposse/label/null | 0.25.0 |
| <a name="module_write_label"></a> [write\_label](#module\_write\_label) | cloudposse/label/null | 0.25.0 |
| <a name="module_write_schedule_index"></a> [write\_schedule\_index](#module\_write\_schedule\_index) | ./schedule-index | n/a |

## Resources

Expand All @@ -27,6 +31,8 @@
| [aws_appautoscaling_policy.read_policy_index](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/appautoscaling_policy) | resource |
| [aws_appautoscaling_policy.write_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/appautoscaling_policy) | resource |
| [aws_appautoscaling_policy.write_policy_index](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/appautoscaling_policy) | resource |
| [aws_appautoscaling_scheduled_action.read_schedule](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/appautoscaling_scheduled_action) | resource |
| [aws_appautoscaling_scheduled_action.write_schedule](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/appautoscaling_scheduled_action) | resource |
| [aws_appautoscaling_target.read_target](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/appautoscaling_target) | resource |
| [aws_appautoscaling_target.read_target_index](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/appautoscaling_target) | resource |
| [aws_appautoscaling_target.write_target](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/appautoscaling_target) | resource |
Expand All @@ -46,8 +52,12 @@
| <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 |
| <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 |
| <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 |
| <a name="input_autoscale_read_schedule"></a> [autoscale\_read\_schedule](#input\_autoscale\_read\_schedule) | Provides an DynamoDB autoscaling scheduled action resource | <pre>list(object({<br> schedule = string<br> min_capacity = number<br> max_capacity = number<br> }))</pre> | `[]` | no |
| <a name="input_autoscale_read_schedule_index"></a> [autoscale\_read\_schedule\_index](#input\_autoscale\_read\_schedule\_index) | Provides an DynamoDB autoscaling scheduled action resource for the index | <pre>list(object({<br> schedule = string<br> min_capacity = number<br> max_capacity = number<br> }))</pre> | `[]` | no |
| <a name="input_autoscale_read_target"></a> [autoscale\_read\_target](#input\_autoscale\_read\_target) | The target value for DynamoDB read autoscaling | `number` | `50` | no |
| <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 |
| <a name="input_autoscale_write_schedule"></a> [autoscale\_write\_schedule](#input\_autoscale\_write\_schedule) | Provides an DynamoDB autoscaling scheduled action resource | <pre>list(object({<br> schedule = string<br> min_capacity = number<br> max_capacity = number<br> }))</pre> | `[]` | no |
| <a name="input_autoscale_write_schedule_index"></a> [autoscale\_write\_schedule\_index](#input\_autoscale\_write\_schedule\_index) | Provides an DynamoDB autoscaling scheduled action resource for the index | <pre>list(object({<br> schedule = string<br> min_capacity = number<br> max_capacity = number<br> }))</pre> | `[]` | no |
| <a name="input_autoscale_write_target"></a> [autoscale\_write\_target](#input\_autoscale\_write\_target) | The target value for DynamoDB write autoscaling | `number` | `50` | no |
| <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 |
| <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 |
Expand Down
16 changes: 16 additions & 0 deletions schedule-index/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
resource "aws_appautoscaling_scheduled_action" "default" {
for_each = { for index, read in var.autoscale_schedule_index : index => read }

name = "${var.name}-${each.key}"

resource_id = var.resource_id
scalable_dimension = var.scalable_dimension
service_namespace = var.service_namespace

schedule = each.value.schedule

scalable_target_action {
min_capacity = each.value.min_capacity
max_capacity = each.value.max_capacity
}
}
33 changes: 33 additions & 0 deletions schedule-index/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
variable "name" {
type = string
description = "The name of the scheduled action"
default = ""
}

variable "service_namespace" {
type = string
description = "The namespace of the AWS service"
default = ""
}

variable "resource_id" {
type = string
description = "The identifier of the resource associated with the scheduled action"
default = ""
}

variable "scalable_dimension" {
type = string
description = "The scalable dimension"
default = ""
}

variable "autoscale_schedule_index" {
type = list(object({
schedule = string
min_capacity = number
max_capacity = number
}))
description = "Provides an DynamoDB autoscaling scheduled action resource"
default = []
}
77 changes: 77 additions & 0 deletions schedule.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
module "read_label" {
source = "cloudposse/label/null"
version = "0.25.0"

attributes = ["read"]

context = module.this.context
}

module "write_label" {
source = "cloudposse/label/null"
version = "0.25.0"

attributes = ["write"]

context = module.this.context
}

resource "aws_appautoscaling_scheduled_action" "read_schedule" {
count = module.this.enabled && length(var.autoscale_read_schedule) > 0 ? length(var.autoscale_read_schedule) : 0

name = "${module.read_label.id}-${count.index}"

service_namespace = join("", aws_appautoscaling_target.read_target.*.service_namespace)

Check warning on line 24 in schedule.tf

View workflow job for this annotation

GitHub Actions / terraform-module / ci-terraform / lint (.)

[tflint] reported by reviewdog 🐶 List items should be accessed using square brackets Raw Output: schedule.tf:24:70: warning: List items should be accessed using square brackets ()
resource_id = join("", aws_appautoscaling_target.read_target.*.resource_id)

Check warning on line 25 in schedule.tf

View workflow job for this annotation

GitHub Actions / terraform-module / ci-terraform / lint (.)

[tflint] reported by reviewdog 🐶 List items should be accessed using square brackets Raw Output: schedule.tf:25:70: warning: List items should be accessed using square brackets ()
scalable_dimension = join("", aws_appautoscaling_target.read_target.*.scalable_dimension)

Check warning on line 26 in schedule.tf

View workflow job for this annotation

GitHub Actions / terraform-module / ci-terraform / lint (.)

[tflint] reported by reviewdog 🐶 List items should be accessed using square brackets Raw Output: schedule.tf:26:70: warning: List items should be accessed using square brackets ()

schedule = lookup(var.autoscale_read_schedule[count.index], "schedule")

Check warning on line 28 in schedule.tf

View workflow job for this annotation

GitHub Actions / terraform-module / ci-terraform / lint (.)

[tflint] reported by reviewdog 🐶 Lookup with 2 arguments is deprecated Raw Output: schedule.tf:28:14: warning: Lookup with 2 arguments is deprecated ()

scalable_target_action {
min_capacity = lookup(var.autoscale_read_schedule[count.index], "min_capacity")

Check warning on line 31 in schedule.tf

View workflow job for this annotation

GitHub Actions / terraform-module / ci-terraform / lint (.)

[tflint] reported by reviewdog 🐶 Lookup with 2 arguments is deprecated Raw Output: schedule.tf:31:20: warning: Lookup with 2 arguments is deprecated ()
max_capacity = lookup(var.autoscale_read_schedule[count.index], "max_capacity")

Check warning on line 32 in schedule.tf

View workflow job for this annotation

GitHub Actions / terraform-module / ci-terraform / lint (.)

[tflint] reported by reviewdog 🐶 Lookup with 2 arguments is deprecated Raw Output: schedule.tf:32:20: warning: Lookup with 2 arguments is deprecated ()
}
}

module "read_schedule_index" {
for_each = module.this.enabled && length(var.autoscale_read_schedule_index) > 0 ? toset(var.dynamodb_indexes) : toset([])
source = "./schedule-index"

name = "${module.read_label.id}-${each.key}"

resource_id = aws_appautoscaling_target.read_target_index[each.key].resource_id
scalable_dimension = aws_appautoscaling_target.read_target_index[each.key].scalable_dimension
service_namespace = aws_appautoscaling_target.read_target_index[each.key].service_namespace

autoscale_schedule_index = var.autoscale_read_schedule_index
}

resource "aws_appautoscaling_scheduled_action" "write_schedule" {
count = module.this.enabled && length(var.autoscale_write_schedule) > 0 ? length(var.autoscale_write_schedule) : 0

name = "${module.write_label.id}-${count.index}"

service_namespace = join("", aws_appautoscaling_target.write_target.*.service_namespace)

Check warning on line 54 in schedule.tf

View workflow job for this annotation

GitHub Actions / terraform-module / ci-terraform / lint (.)

[tflint] reported by reviewdog 🐶 List items should be accessed using square brackets Raw Output: schedule.tf:54:71: warning: List items should be accessed using square brackets ()
resource_id = join("", aws_appautoscaling_target.write_target.*.resource_id)

Check warning on line 55 in schedule.tf

View workflow job for this annotation

GitHub Actions / terraform-module / ci-terraform / lint (.)

[tflint] reported by reviewdog 🐶 List items should be accessed using square brackets Raw Output: schedule.tf:55:71: warning: List items should be accessed using square brackets ()
scalable_dimension = join("", aws_appautoscaling_target.write_target.*.scalable_dimension)

Check warning on line 56 in schedule.tf

View workflow job for this annotation

GitHub Actions / terraform-module / ci-terraform / lint (.)

[tflint] reported by reviewdog 🐶 List items should be accessed using square brackets Raw Output: schedule.tf:56:71: warning: List items should be accessed using square brackets ()

schedule = lookup(var.autoscale_write_schedule[count.index], "schedule")

Check warning on line 58 in schedule.tf

View workflow job for this annotation

GitHub Actions / terraform-module / ci-terraform / lint (.)

[tflint] reported by reviewdog 🐶 Lookup with 2 arguments is deprecated Raw Output: schedule.tf:58:14: warning: Lookup with 2 arguments is deprecated ()

scalable_target_action {
min_capacity = lookup(var.autoscale_write_schedule[count.index], "min_capacity")
max_capacity = lookup(var.autoscale_write_schedule[count.index], "max_capacity")
}
}

module "write_schedule_index" {
for_each = module.this.enabled && length(var.autoscale_write_schedule_index) > 0 ? toset(var.dynamodb_indexes) : toset([])
source = "./schedule-index"

name = "${module.write_label.id}-${each.key}"

resource_id = aws_appautoscaling_target.write_target_index[each.key].resource_id
scalable_dimension = aws_appautoscaling_target.write_target_index[each.key].scalable_dimension
service_namespace = aws_appautoscaling_target.write_target_index[each.key].service_namespace

autoscale_schedule_index = var.autoscale_write_schedule_index
}
40 changes: 40 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,43 @@ variable "autoscale_max_write_capacity_index" {
default = null
description = "DynamoDB autoscaling max write capacity of the index"
}

variable "autoscale_read_schedule" {
type = list(object({
schedule = string
min_capacity = number
max_capacity = number
}))
description = "Provides an DynamoDB autoscaling scheduled action resource"
default = []
}

variable "autoscale_read_schedule_index" {
type = list(object({
schedule = string
min_capacity = number
max_capacity = number
}))
description = "Provides an DynamoDB autoscaling scheduled action resource for the index"
default = []
}

variable "autoscale_write_schedule" {
type = list(object({
schedule = string
min_capacity = number
max_capacity = number
}))
description = "Provides an DynamoDB autoscaling scheduled action resource"
default = []
}

variable "autoscale_write_schedule_index" {
type = list(object({
schedule = string
min_capacity = number
max_capacity = number
}))
description = "Provides an DynamoDB autoscaling scheduled action resource for the index"
default = []
}
Loading