echomike80 / terraform-aws-cloudwatch-alarms

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AWS Cloudwatch alarms Terraform module

Terraform module which creates an AWS Cloudwatch alarms for EC2 on AWS.

Terraform versions

Terraform 0.12 and newer.

Usage

resource "aws_sns_topic" "cloudwatch_alarms" {
  name         = "Cloudwatch_Alarms"
  display_name = "Cloudwatch_Alarms"
}

module "cloudwatch_alarms" {
  source            = "/path/to/terraform-aws-cloudwatch-alarms"

  name              = var.name
  region            = var.region

  ec2_instances_list                    = ["i-1234567890", "i-2345678901", "i-3456789012"]
  cloudwatch_autorecover_enabled        = true
  cloudwatch_cpu_utilization_enabled    = true
  cloudwatch_sns_topic_arn              = aws_sns_topic.cloudwatch_alarms_all_nodes.arn
}

Issue

Error: Invalid count argument

  on .terraform/modules/cloudwatch_alarms_all_nodes/main.tf line 19, in resource "aws_cloudwatch_metric_alarm" "ec2_cpu_utilization":
  19:   count                     = var.cloudwatch_cpu_utilization_enabled && var.cloudwatch_sns_topic_arn != null ? length(var.ec2_instances_list) : 0

The "count" value depends on resource attributes that cannot be determined until apply, so Terraform cannot predict how many instances will be created. To work around this, use the -target argument to first apply only the resources that the count depends on.

Workaround: Create SNS Topic first and then provision Cloudwatch alarms

Requirements

Name Version
terraform >= 0.12.6
aws >= 2.65

Providers

Name Version
aws >= 2.65

Modules

No modules.

Resources

Name Type
aws_cloudwatch_metric_alarm.ec2_autorecover resource
aws_cloudwatch_metric_alarm.ec2_cpu_utilization resource

Inputs

Name Description Type Default Required
cloudwatch_autorecover_enabled Enable or disable CloudWatch alarm EC2 autorecover bool true no
cloudwatch_cpu_utilization_enabled Enable or disable CloudWatch alarm CPU utilization bool false no
cloudwatch_sns_topic_arn SNS Topic ARN for CloudWatch alarms string null no
ec2_autorecover_evaluation_periods The number of periods over which data is compared to the specified threshold. string "2" no
ec2_autorecover_period The period in seconds over which the specified statistic is applied. string "60" no
ec2_cpu_utilization_evaluation_periods The number of periods over which data is compared to the specified threshold. string "2" no
ec2_cpu_utilization_period The period in seconds over which the specified statistic is applied. string "120" no
ec2_cpu_utilization_threshold The value against which the specified statistic is compared. This parameter is required for alarms based on static thresholds, but should not be used for alarms based on anomaly detection models. string "80" no
ec2_instances_list List of EC2 instances for all Cloudwatch alarms list(string) null no
name Name to be used on all resources as prefix string n/a yes
region Name of region string n/a yes

Outputs

No outputs.

Authors

Module managed by Marcel Emmert.

License

Apache 2 Licensed. See LICENSE for full details.

About


Languages

Language:HCL 100.0%