From 35cc157bbe69722d292fc3811f59eaa91fb6d3f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Jazgar?= Date: Tue, 22 Oct 2019 11:10:57 +0200 Subject: [PATCH] Change to Terraform 0.12. --- Makefile | 1 + alarms.tf | 144 ++++++++++++++++++++++++++++++--------------------- main.tf | 6 ++- outputs.tf | 1 - variables.tf | 61 +++++++++++----------- versions.tf | 4 ++ 6 files changed, 124 insertions(+), 93 deletions(-) delete mode 100644 outputs.tf create mode 100644 versions.tf diff --git a/Makefile b/Makefile index 655f630..1a5f5b5 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ SHELL := /bin/bash # List of targets the `readme` target should call before generating the readme export README_DEPS ?= docs/targets.md docs/terraform.md +export TERRAFORM_VERSION=0.12.10 -include $(shell curl -sSL -o .build-harness "https://git.io/build-harness"; echo .build-harness) diff --git a/alarms.tf b/alarms.tf index 4eeebdc..319221e 100644 --- a/alarms.tf +++ b/alarms.tf @@ -1,119 +1,143 @@ module "cpu_utilization_high_alarm_label" { source = "git::https://github.com/cloudposse/terraform-terraform-label.git?ref=tags/0.1.3" - name = "${var.name}" - namespace = "${var.namespace}" - stage = "${var.stage}" - attributes = "${compact(concat(var.attributes, list("cpu", "utilization", "high")))}" + name = var.name + namespace = var.namespace + stage = var.stage + attributes = compact(concat(var.attributes, ["cpu", "utilization", "high"])) } module "cpu_utilization_low_alarm_label" { source = "git::https://github.com/cloudposse/terraform-terraform-label.git?ref=tags/0.1.3" - name = "${var.name}" - namespace = "${var.namespace}" - stage = "${var.stage}" - attributes = "${compact(concat(var.attributes, list("cpu", "utilization", "low")))}" + name = var.name + namespace = var.namespace + stage = var.stage + attributes = compact(concat(var.attributes, ["cpu", "utilization", "low"])) } module "memory_utilization_high_alarm_label" { source = "git::https://github.com/cloudposse/terraform-terraform-label.git?ref=tags/0.1.3" - name = "${var.name}" - namespace = "${var.namespace}" - stage = "${var.stage}" - attributes = "${compact(concat(var.attributes, list("memory", "utilization", "high")))}" + name = var.name + namespace = var.namespace + stage = var.stage + attributes = compact(concat(var.attributes, ["memory", "utilization", "high"])) } module "memory_utilization_low_alarm_label" { source = "git::https://github.com/cloudposse/terraform-terraform-label.git?ref=tags/0.1.3" - name = "${var.name}" - namespace = "${var.namespace}" - stage = "${var.stage}" - attributes = "${compact(concat(var.attributes, list("memory", "utilization", "low")))}" + name = var.name + namespace = var.namespace + stage = var.stage + attributes = compact(concat(var.attributes, ["memory", "utilization", "low"])) } locals { thresholds = { - CPUUtilizationHighThreshold = "${min(max(var.cpu_utilization_high_threshold, 0), 100)}" - CPUUtilizationLowThreshold = "${min(max(var.cpu_utilization_low_threshold, 0), 100)}" - MemoryUtilizationHighThreshold = "${min(max(var.memory_utilization_high_threshold, 0), 100)}" - MemoryUtilizationLowThreshold = "${min(max(var.memory_utilization_low_threshold, 0), 100)}" + CPUUtilizationHighThreshold = min(max(var.cpu_utilization_high_threshold, 0), 100) + CPUUtilizationLowThreshold = min(max(var.cpu_utilization_low_threshold, 0), 100) + MemoryUtilizationHighThreshold = min(max(var.memory_utilization_high_threshold, 0), 100) + MemoryUtilizationLowThreshold = min(max(var.memory_utilization_low_threshold, 0), 100) } dimensions_map = { "service" = { - "ClusterName" = "${var.cluster_name}" - "ServiceName" = "${var.service_name}" + "ClusterName" = var.cluster_name + "ServiceName" = var.service_name } - "cluster" = { - "ClusterName" = "${var.cluster_name}" + "ClusterName" = var.cluster_name } } } resource "aws_cloudwatch_metric_alarm" "cpu_utilization_high" { - count = "${local.enabled}" - alarm_name = "${module.cpu_utilization_high_alarm_label.id}" + count = local.enabled + alarm_name = module.cpu_utilization_high_alarm_label.id comparison_operator = "GreaterThanThreshold" - evaluation_periods = "${var.cpu_utilization_high_evaluation_periods}" + evaluation_periods = var.cpu_utilization_high_evaluation_periods metric_name = "CPUUtilization" namespace = "AWS/ECS" - period = "${var.cpu_utilization_high_period}" + period = var.cpu_utilization_high_period statistic = "Average" - threshold = "${local.thresholds["CPUUtilizationHighThreshold"]}" - alarm_description = "${format(var.alarm_description, "CPU", "High", var.cpu_utilization_high_period/60, var.cpu_utilization_high_evaluation_periods)}" - alarm_actions = ["${compact(var.cpu_utilization_high_alarm_actions)}"] - ok_actions = ["${compact(var.cpu_utilization_high_ok_actions)}"] + threshold = local.thresholds["CPUUtilizationHighThreshold"] + alarm_description = format( + var.alarm_description, + "CPU", + "High", + var.cpu_utilization_high_period / 60, + var.cpu_utilization_high_evaluation_periods, + ) + alarm_actions = compact(var.cpu_utilization_high_alarm_actions) + ok_actions = compact(var.cpu_utilization_high_ok_actions) - dimensions = "${local.dimensions_map[var.service_name == "" ? "cluster" : "service"]}" + dimensions = local.dimensions_map[var.service_name == "" ? "cluster" : "service"] } resource "aws_cloudwatch_metric_alarm" "cpu_utilization_low" { - count = "${local.enabled}" - alarm_name = "${module.cpu_utilization_low_alarm_label.id}" + count = local.enabled + alarm_name = module.cpu_utilization_low_alarm_label.id comparison_operator = "LessThanThreshold" - evaluation_periods = "${var.cpu_utilization_low_evaluation_periods}" + evaluation_periods = var.cpu_utilization_low_evaluation_periods metric_name = "CPUUtilization" namespace = "AWS/ECS" - period = "${var.cpu_utilization_low_period}" + period = var.cpu_utilization_low_period statistic = "Average" - threshold = "${local.thresholds["CPUUtilizationLowThreshold"]}" - alarm_description = "${format(var.alarm_description, "CPU", "Low", var.cpu_utilization_low_period/60, var.cpu_utilization_low_evaluation_periods)}" - alarm_actions = ["${compact(var.cpu_utilization_low_alarm_actions)}"] - ok_actions = ["${compact(var.cpu_utilization_low_ok_actions)}"] + threshold = local.thresholds["CPUUtilizationLowThreshold"] + alarm_description = format( + var.alarm_description, + "CPU", + "Low", + var.cpu_utilization_low_period / 60, + var.cpu_utilization_low_evaluation_periods, + ) + alarm_actions = compact(var.cpu_utilization_low_alarm_actions) + ok_actions = compact(var.cpu_utilization_low_ok_actions) - dimensions = "${local.dimensions_map[var.service_name == "" ? "cluster" : "service"]}" + dimensions = local.dimensions_map[var.service_name == "" ? "cluster" : "service"] } resource "aws_cloudwatch_metric_alarm" "memory_utilization_high" { - count = "${local.enabled}" - alarm_name = "${module.memory_utilization_high_alarm_label.id}" + count = local.enabled + alarm_name = module.memory_utilization_high_alarm_label.id comparison_operator = "GreaterThanThreshold" - evaluation_periods = "${var.memory_utilization_high_evaluation_periods}" + evaluation_periods = var.memory_utilization_high_evaluation_periods metric_name = "MemoryUtilization" namespace = "AWS/ECS" - period = "${var.memory_utilization_high_period}" + period = var.memory_utilization_high_period statistic = "Average" - threshold = "${local.thresholds["MemoryUtilizationHighThreshold"]}" - alarm_description = "${format(var.alarm_description, "Memory", "Hight", var.memory_utilization_high_period/60, var.memory_utilization_high_evaluation_periods)}" - alarm_actions = ["${compact(var.memory_utilization_high_alarm_actions)}"] - ok_actions = ["${compact(var.memory_utilization_high_ok_actions)}"] + threshold = local.thresholds["MemoryUtilizationHighThreshold"] + alarm_description = format( + var.alarm_description, + "Memory", + "Hight", + var.memory_utilization_high_period / 60, + var.memory_utilization_high_evaluation_periods, + ) + alarm_actions = compact(var.memory_utilization_high_alarm_actions) + ok_actions = compact(var.memory_utilization_high_ok_actions) - dimensions = "${local.dimensions_map[var.service_name == "" ? "cluster" : "service"]}" + dimensions = local.dimensions_map[var.service_name == "" ? "cluster" : "service"] } resource "aws_cloudwatch_metric_alarm" "memory_utilization_low" { - count = "${local.enabled}" - alarm_name = "${module.memory_utilization_low_alarm_label.id}" + count = local.enabled + alarm_name = module.memory_utilization_low_alarm_label.id comparison_operator = "LessThanThreshold" - evaluation_periods = "${var.memory_utilization_low_evaluation_periods}" + evaluation_periods = var.memory_utilization_low_evaluation_periods metric_name = "MemoryUtilization" namespace = "AWS/ECS" - period = "${var.memory_utilization_low_period}" + period = var.memory_utilization_low_period statistic = "Average" - threshold = "${local.thresholds["MemoryUtilizationLowThreshold"]}" - alarm_description = "${format(var.alarm_description, "Memory", "Low", var.memory_utilization_low_period/60, var.memory_utilization_low_evaluation_periods)}" - alarm_actions = ["${compact(var.memory_utilization_low_alarm_actions)}"] - ok_actions = ["${compact(var.memory_utilization_low_ok_actions)}"] + threshold = local.thresholds["MemoryUtilizationLowThreshold"] + alarm_description = format( + var.alarm_description, + "Memory", + "Low", + var.memory_utilization_low_period / 60, + var.memory_utilization_low_evaluation_periods, + ) + alarm_actions = compact(var.memory_utilization_low_alarm_actions) + ok_actions = compact(var.memory_utilization_low_ok_actions) - dimensions = "${local.dimensions_map[var.service_name == "" ? "cluster" : "service"]}" + dimensions = local.dimensions_map[var.service_name == "" ? "cluster" : "service"] } + diff --git a/main.tf b/main.tf index 7f8d372..7de5948 100644 --- a/main.tf +++ b/main.tf @@ -1,5 +1,7 @@ -data "aws_caller_identity" "default" {} +data "aws_caller_identity" "default" { +} locals { - enabled = "${var.enabled == "true" ? 1 : 0}" + enabled = var.enabled == "true" ? 1 : 0 } + diff --git a/outputs.tf b/outputs.tf deleted file mode 100644 index 8b13789..0000000 --- a/outputs.tf +++ /dev/null @@ -1 +0,0 @@ - diff --git a/variables.tf b/variables.tf index 940c81d..080ee13 100644 --- a/variables.tf +++ b/variables.tf @@ -1,175 +1,176 @@ variable "name" { - type = "string" + type = string description = "Name (unique identifier for app or service)" } variable "namespace" { - type = "string" + type = string description = "Namespace (e.g. `cp` or `cloudposse`)" } variable "delimiter" { - type = "string" + type = string description = "The delimiter to be used in labels." default = "-" } variable "stage" { - type = "string" + type = string description = "Stage (e.g. `prod`, `dev`, `staging`)" } variable "attributes" { - type = "list" + type = list(string) description = "List of attributes to add to label." default = [] } variable "tags" { - type = "map" + type = map(string) description = "Map of key-value pairs to use for tags." default = {} } variable "enabled" { - type = "string" + type = string description = "Whether to create all resources" default = "true" } variable "cluster_name" { - type = "string" + type = string description = "The name of the ECS cluster to monitor." } variable "service_name" { - type = "string" + type = string description = "The name of the ECS Service in the ECS cluster to monitor." default = "" } variable "alarm_description" { - type = "string" + type = string description = "The string to format and use as the alarm description." default = "Average service %v utilization %v last %d minute(s) over %v period(s)" } variable "cpu_utilization_high_threshold" { - type = "string" + type = string description = "The maximum percentage of CPU utilization average." default = "80" } variable "cpu_utilization_high_evaluation_periods" { - type = "string" + type = string description = "Number of periods to evaluate for the alarm." default = "1" } variable "cpu_utilization_high_period" { - type = "string" + type = string description = "Duration in seconds to evaluate for the alarm." default = "300" } variable "cpu_utilization_high_alarm_actions" { - type = "list" + type = list(string) description = "A list of ARNs (i.e. SNS Topic ARN) to notify on CPU Utilization High Alarm action." default = [] } variable "cpu_utilization_high_ok_actions" { - type = "list" + type = list(string) description = "A list of ARNs (i.e. SNS Topic ARN) to notify on CPU Utilization High OK action." default = [] } variable "cpu_utilization_low_threshold" { - type = "string" + type = string description = "The minimum percentage of CPU utilization average." default = "20" } variable "cpu_utilization_low_evaluation_periods" { - type = "string" + type = string description = "Number of periods to evaluate for the alarm." default = "1" } variable "cpu_utilization_low_period" { - type = "string" + type = string description = "Duration in seconds to evaluate for the alarm." default = "300" } variable "cpu_utilization_low_alarm_actions" { - type = "list" + type = list(string) description = "A list of ARNs (i.e. SNS Topic ARN) to notify on CPU Utilization Low Alarm action." default = [] } variable "cpu_utilization_low_ok_actions" { - type = "list" + type = list(string) description = "A list of ARNs (i.e. SNS Topic ARN) to notify on CPU Utilization Low OK action." default = [] } variable "memory_utilization_high_threshold" { - type = "string" + type = string description = "The maximum percentage of Memory utilization average." default = "80" } variable "memory_utilization_high_evaluation_periods" { - type = "string" + type = string description = "Number of periods to evaluate for the alarm." default = "1" } variable "memory_utilization_high_period" { - type = "string" + type = string description = "Duration in seconds to evaluate for the alarm." default = "300" } variable "memory_utilization_high_alarm_actions" { - type = "list" + type = list(string) description = "A list of ARNs (i.e. SNS Topic ARN) to notify on Memory Utilization High Alarm action." default = [] } variable "memory_utilization_high_ok_actions" { - type = "list" + type = list(string) description = "A list of ARNs (i.e. SNS Topic ARN) to notify on Memory Utilization High OK action." default = [] } variable "memory_utilization_low_threshold" { - type = "string" + type = string description = "The minimum percentage of Memory utilization average." default = "20" } variable "memory_utilization_low_evaluation_periods" { - type = "string" + type = string description = "Number of periods to evaluate for the alarm." default = "1" } variable "memory_utilization_low_period" { - type = "string" + type = string description = "Duration in seconds to evaluate for the alarm." default = "300" } variable "memory_utilization_low_alarm_actions" { - type = "list" + type = list(string) description = "A list of ARNs (i.e. SNS Topic ARN) to notify on Memory Utilization Low Alarm action." default = [] } variable "memory_utilization_low_ok_actions" { - type = "list" + type = list(string) description = "A list of ARNs (i.e. SNS Topic ARN) to notify on Memory Utilization Low OK action." default = [] } + diff --git a/versions.tf b/versions.tf new file mode 100644 index 0000000..ac97c6a --- /dev/null +++ b/versions.tf @@ -0,0 +1,4 @@ + +terraform { + required_version = ">= 0.12" +}