-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
89 lines (84 loc) · 3.03 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
terraform {
required_version = ">= 0.13.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = "3.14.1"
}
}
}
provider "aws" {
region = var.region
profile = var.profile
}
locals {
nonprod_instance_ids = [for InstanceId in local.nonprod_disk_paths.Dimensions : InstanceId.InstanceId]
nonprod_disk_paths = jsondecode(file("ec2_alarm/nonprod_disk_paths.json"))
nonprod_disk_path = [for path in local.nonprod_disk_paths.Dimensions : path.path]
prod_instance_ids = [for InstanceId in local.prod_disk_paths.Dimensions : InstanceId.InstanceId]
prod_disk_paths = jsondecode(file("ec2_alarm/prod_disk_paths.json"))
prod_disk_path = [for path in local.prod_disk_paths.Dimensions : path.path]
# instance_id = [for InstanceId in data.external.disks.result.Dimensions : InstanceId.InstanceId]
# disk_path = [for path in data.external.disks.result.Dimensions : path.path]
# #change the keys on the instance list so we can find them by name
# nonprod_instance_sanitized = {
# for key, value in data.aws_instance.nonprod_instance :
# value.tags.Name => value
# }
# nonprod_instance_disks = distinct(flatten([
# for nonprod_instance in local.nonprod_instance_sanitized : [
# for disk_path in local.disk_paths : {
# nonprod_instance = nonprod_instance
# disk_path = disk_path
# }
# ]
# ]))
}
module "nonprod_ec2_alarms" {
count = length(local.nonprod_instance_ids)
source = "./ec2_alarm"
instance_id = local.nonprod_instance_ids[count.index]
region = var.region
profile = var.profile
# tag_name = var.tag_name
# tag_value = var.tag_value
disk_path = local.nonprod_disk_path[count.index]
threshold_ec2_disk = var.threshold_ec2_disk
threshold_ec2_cpu = var.threshold_ec2_cpu
threshold_ec2_mem = var.threshold_ec2_mem
alarm_actions = var.sns_topics_nonprod
ok_actions = var.sns_topics_nonprod
actions_enabled = true
depends_on = [null_resource.aws_temp_data_regenerate]
}
module "prod_ec2_alarms" {
count = length(local.prod_instance_ids)
source = "./ec2_alarm"
instance_id = local.prod_instance_ids[count.index]
region = var.region
profile = var.profile
# tag_name = var.tag_name
# tag_value = var.tag_value
disk_path = local.prod_disk_path[count.index]
threshold_ec2_disk = var.threshold_ec2_disk
threshold_ec2_cpu = var.threshold_ec2_cpu
threshold_ec2_mem = var.threshold_ec2_mem
alarm_actions = var.sns_topics_prod
ok_actions = var.sns_topics_prod
actions_enabled = true
depends_on = [null_resource.aws_temp_data_regenerate]
}
resource "null_resource" "aws_temp_data_regenerate" {
provisioner "local-exec" {
command = "bash instances.sh"
working_dir = "./ec2_alarm"
environment = {
PROFILE = var.profile
REGION = var.region
OUTPUT_FOLDER = "ec2_alarm"
}
}
triggers = {
always_run = timestamp()
}
}