terraform/examples/aws-asg/main.tf

85 lines
1.9 KiB
Terraform
Raw Normal View History

2015-06-08 01:28:46 +02:00
# Specify the provider and access details
provider "aws" {
region = "${var.aws_region}"
2015-06-08 01:28:46 +02:00
}
resource "aws_elb" "web-elb" {
name = "terraform-example-elb"
# The same availability zone as our instances
availability_zones = ["${split(",", var.availability_zones)}"]
listener {
instance_port = 80
instance_protocol = "http"
lb_port = 80
lb_protocol = "http"
}
health_check {
healthy_threshold = 2
unhealthy_threshold = 2
timeout = 3
target = "HTTP:80/"
interval = 30
}
}
resource "aws_autoscaling_group" "web-asg" {
availability_zones = ["${split(",", var.availability_zones)}"]
name = "terraform-example-asg"
max_size = "${var.asg_max}"
min_size = "${var.asg_min}"
desired_capacity = "${var.asg_desired}"
force_delete = true
launch_configuration = "${aws_launch_configuration.web-lc.name}"
load_balancers = ["${aws_elb.web-elb.name}"]
#vpc_zone_identifier = ["${split(",", var.availability_zones)}"]
tag {
key = "Name"
value = "web-asg"
propagate_at_launch = "true"
2015-06-08 01:28:46 +02:00
}
}
2015-06-08 01:28:46 +02:00
resource "aws_launch_configuration" "web-lc" {
name = "terraform-example-lc"
image_id = "${lookup(var.aws_amis, var.aws_region)}"
instance_type = "${var.instance_type}"
# Security group
security_groups = ["${aws_security_group.default.name}"]
user_data = "${file("userdata.sh")}"
key_name = "${var.key_name}"
2015-06-08 01:28:46 +02:00
}
# Our default security group to access
# the instances over SSH and HTTP
resource "aws_security_group" "default" {
name = "terraform_example_sg"
description = "Used in the terraform"
2015-06-08 01:28:46 +02:00
# SSH access from anywhere
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
2015-06-08 01:28:46 +02:00
# HTTP access from anywhere
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
2015-06-08 01:28:46 +02:00
# outbound internet access
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
2015-06-08 01:28:46 +02:00
}