Skip to content

Commit

Permalink
add name output (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
osterman authored Mar 8, 2018
1 parent a15d85d commit 95653fc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
12 changes: 8 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ data "aws_iam_policy_document" "autoscaler" {
"dynamodb:UpdateTable",
]

resources = ["arn:aws:dynamodb:${var.region}:${data.aws_caller_identity.current.account_id}:table/${module.default.id}"]
resources = ["${aws_dynamodb_table.default.arn}"]

effect = "Allow"
}
}

resource "aws_iam_role_policy" "autoscaler" {
name = "${module.default.id}-autoscaler-dynamo"
name = "${module.default.id}-autoscaler-dynamodb"
role = "${aws_iam_role.autoscaler.id}"
policy = "${data.aws_iam_policy_document.autoscaler.json}"
}
Expand All @@ -105,11 +105,15 @@ resource "aws_iam_role_policy" "autoscaler_cloudwatch" {
policy = "${data.aws_iam_policy_document.autoscaler_cloudwatch.json}"
}

data "aws_iam_role" "autoscale_service" {
name = "AWSServiceRoleForApplicationAutoScaling_DynamoDBTable"
}

resource "aws_appautoscaling_target" "read_target" {
max_capacity = "${var.autoscale_max_read_capacity}"
min_capacity = "${var.autoscale_min_read_capacity}"
resource_id = "table/${module.default.id}"
role_arn = "${aws_iam_role.autoscaler.arn}"
role_arn = "${data.aws_iam_role.autoscale_service.arn}"
scalable_dimension = "dynamodb:table:ReadCapacityUnits"
service_namespace = "dynamodb"
}
Expand All @@ -134,7 +138,7 @@ resource "aws_appautoscaling_target" "write_target" {
max_capacity = "${var.autoscale_max_write_capacity}"
min_capacity = "${var.autoscale_min_write_capacity}"
resource_id = "table/${module.default.id}"
role_arn = "${aws_iam_role.autoscaler.arn}"
role_arn = "${data.aws_iam_role.autoscale_service.arn}"
scalable_dimension = "dynamodb:table:WriteCapacityUnits"
service_namespace = "dynamodb"
}
Expand Down
4 changes: 4 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
output "table_name" {
value = "${aws_dynamodb_table.default.name}"
}

output "table_id" {
value = "${aws_dynamodb_table.default.id}"
}
Expand Down
4 changes: 0 additions & 4 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
variable "region" {
type = "string"
}

variable "name" {
type = "string"
}
Expand Down

0 comments on commit 95653fc

Please sign in to comment.