Skip to content

Commit

Permalink
Add enabled flag to enable/disable creation of the resources (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
aknysh authored Mar 24, 2018
1 parent 5b75a93 commit 0d3d38a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ module "dynamodb_autoscaler" {
| `autoscale_max_read_capacity` | `20` | DynamoDB autoscaling max read capacity | No |
| `autoscale_min_write_capacity` | `5` | DynamoDB autoscaling min write capacity | No |
| `autoscale_max_write_capacity` | `20` | DynamoDB autoscaling max write capacity | No |
| `enabled` | `true` | Set to false to prevent the module from creating any resources | No |



Expand Down
8 changes: 8 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module "default_label" {
delimiter = "${var.delimiter}"
attributes = "${var.attributes}"
tags = "${var.tags}"
enabled = "${var.enabled}"
}

data "aws_iam_policy_document" "assume_role" {
Expand All @@ -26,6 +27,7 @@ data "aws_iam_policy_document" "assume_role" {
}

resource "aws_iam_role" "autoscaler" {
count = "${var.enabled == "true" ? 1 : 0}"
name = "${module.default_label.id}${var.delimiter}autoscaler"
assume_role_policy = "${data.aws_iam_policy_document.assume_role.json}"
}
Expand All @@ -46,6 +48,7 @@ data "aws_iam_policy_document" "autoscaler" {
}

resource "aws_iam_role_policy" "autoscaler" {
count = "${var.enabled == "true" ? 1 : 0}"
name = "${module.default_label.id}${var.delimiter}autoscaler${var.delimiter}dynamodb"
role = "${aws_iam_role.autoscaler.id}"
policy = "${data.aws_iam_policy_document.autoscaler.json}"
Expand All @@ -68,12 +71,14 @@ data "aws_iam_policy_document" "autoscaler_cloudwatch" {
}

resource "aws_iam_role_policy" "autoscaler_cloudwatch" {
count = "${var.enabled == "true" ? 1 : 0}"
name = "${module.default_label.id}${var.delimiter}autoscaler${var.delimiter}cloudwatch"
role = "${aws_iam_role.autoscaler.id}"
policy = "${data.aws_iam_policy_document.autoscaler_cloudwatch.json}"
}

resource "aws_appautoscaling_target" "read_target" {
count = "${var.enabled == "true" ? 1 : 0}"
max_capacity = "${var.autoscale_max_read_capacity}"
min_capacity = "${var.autoscale_min_read_capacity}"
resource_id = "table/${var.dynamodb_table_name}"
Expand All @@ -82,6 +87,7 @@ resource "aws_appautoscaling_target" "read_target" {
}

resource "aws_appautoscaling_policy" "read_policy" {
count = "${var.enabled == "true" ? 1 : 0}"
name = "DynamoDBReadCapacityUtilization:${aws_appautoscaling_target.read_target.resource_id}"
policy_type = "TargetTrackingScaling"
resource_id = "${aws_appautoscaling_target.read_target.resource_id}"
Expand All @@ -98,6 +104,7 @@ resource "aws_appautoscaling_policy" "read_policy" {
}

resource "aws_appautoscaling_target" "write_target" {
count = "${var.enabled == "true" ? 1 : 0}"
max_capacity = "${var.autoscale_max_write_capacity}"
min_capacity = "${var.autoscale_min_write_capacity}"
resource_id = "table/${var.dynamodb_table_name}"
Expand All @@ -106,6 +113,7 @@ resource "aws_appautoscaling_target" "write_target" {
}

resource "aws_appautoscaling_policy" "write_policy" {
count = "${var.enabled == "true" ? 1 : 0}"
name = "DynamoDBWriteCapacityUtilization:${aws_appautoscaling_target.write_target.resource_id}"
policy_type = "TargetTrackingScaling"
resource_id = "${aws_appautoscaling_target.write_target.resource_id}"
Expand Down
5 changes: 5 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,8 @@ variable "autoscale_max_write_capacity" {
default = 20
description = "DynamoDB autoscaling max write capacity"
}

variable "enabled" {
description = "Set to false to prevent the module from creating any resources"
default = "true"
}

0 comments on commit 0d3d38a

Please sign in to comment.