This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| resource "aws_lb_target_group" "my-alb-tg" { | |
| health_check { | |
| interval = 30 | |
| path = "/" | |
| protocol = "HTTP" | |
| timeout = 5 | |
| healthy_threshold = 5 | |
| unhealthy_threshold = 2 | |
| matcher = "200-299" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| resource "aws_lb" "my-test-lb" { | |
| name = "my-test-lb" | |
| internal = false | |
| load_balancer_type = "application" | |
| ip_address_type = "ipv4" | |
| subnets = ["${var.subnet_id1}", "${var.subnet_id2}"] | |
| enable_deletion_protection = true | |
| tags { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module "ec2_instance" { | |
| source = "./ec2_instance" | |
| instance_count = "${var.instance_count}" | |
| my_public_key = "${var.my_public_key}" | |
| instance_type = "${var.instance_type}" | |
| subnet_id = "${module.vpc_networking.public_subnets}" | |
| security_group = "${module.vpc_networking.security_group}" | |
| alarm_actions = "${module.sns.sns_topic}" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| output "public_subnets" { | |
| value = "${aws_subnet.public_subnet.*.id}" | |
| } | |
| output "private_subnets" { | |
| value = "${aws_subnet.private_subnet.*.id}" | |
| } | |
| output "security_group" { | |
| value = "${aws_security_group.test_sg.id}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| provider "aws" { | |
| region = "us-west-2" | |
| } | |
| data "aws_availability_zones" "available" {} | |
| # To get the latest Centos7 AMI | |
| data "aws_ami" "centos" { | |
| owners = ["679593333241"] | |
| most_recent = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| resource "aws_cloudwatch_metric_alarm" "instance-health-check" { | |
| alarm_name = "instance-health-check" | |
| comparison_operator = "GreaterThanOrEqualToThreshold" | |
| evaluation_periods = "1" | |
| metric_name = "StatusCheckFailed" | |
| namespace = "AWS/EC2" | |
| period = "120" | |
| statistic = "Average" | |
| threshold = "1" | |
| alarm_description = "This metric monitors ec2 health status" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| resource "aws_cloudwatch_metric_alarm" "cpu-utilization" { | |
| alarm_name = "high-cpu-utilization-alarm" | |
| comparison_operator = "GreaterThanOrEqualToThreshold" | |
| evaluation_periods = "2" | |
| metric_name = "CPUUtilization" | |
| namespace = "AWS/EC2" | |
| period = "120" | |
| statistic = "Average" | |
| threshold = "80" | |
| alarm_description = "This metric monitors ec2 cpu utilization" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| resource "aws_sns_topic" "alarm" { | |
| name = "alarms-topic" | |
| delivery_policy = <<EOF | |
| { | |
| "http": { | |
| "defaultHealthyRetryPolicy": { | |
| "minDelayTarget": 20, | |
| "maxDelayTarget": 20, | |
| "numRetries": 3, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| provider "aws" { | |
| region = "us-west-2" | |
| } | |
| resource "aws_lb" "ec2cc8bcb4" { | |
| name = "my-test-lb" | |
| internal = false | |
| security_groups = [ | |
| "sg-08dafd1cf6d4ffbf3" | |
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| resource "aws_ebs_volume" "my-test-ebs" { | |
| count = 2 | |
| availability_zone = "${data.aws_availability_zones.available.names[count.index]}" | |
| size = 10 | |
| type = "gp2" | |
| } | |
| resource "aws_volume_attachment" "my-test-ebs-attachment" { | |
| count = 2 | |
| device_name = "/dev/xvdh" |