mirror of
https://codeberg.org/scottslowe/learning-tools.git
synced 2026-03-11 09:04:37 +00:00
First attempt at a "static" ASG-ELB config
Add files for creating a "static" (not heavily parameterized) config with an Auto Scaling group and an Elastic Load Balancer. Functional, but doesn't work as expected. More testing needed. Signed-off-by: Scott Lowe <scott.lowe@scottlowe.org>
This commit is contained in:
parent
a9d816d7a9
commit
d1c1f6c306
4 changed files with 85 additions and 0 deletions
16
terraform/aws/asg-elb/data.tf
Normal file
16
terraform/aws/asg-elb/data.tf
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
data "aws_ami" "atomic_ami" {
|
||||
most_recent = true
|
||||
owners = ["410186602215"]
|
||||
filter {
|
||||
name = "name"
|
||||
values = ["CentOS Atomic Host 7*"]
|
||||
}
|
||||
filter {
|
||||
name = "virtualization-type"
|
||||
values = ["hvm"]
|
||||
}
|
||||
}
|
||||
|
||||
data "aws_vpc" "default_vpc" {
|
||||
default = true
|
||||
}
|
||||
47
terraform/aws/asg-elb/main.tf
Normal file
47
terraform/aws/asg-elb/main.tf
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
# Create an ELB
|
||||
resource "aws_elb" "elb" {
|
||||
name = "elb-test"
|
||||
subnets = ["subnet-69e39630","subnet-e0702d97","subnet-c4e9d6a1"]
|
||||
cross_zone_load_balancing = true
|
||||
connection_draining = true
|
||||
security_groups = ["${var.secgrp}"]
|
||||
|
||||
listener {
|
||||
instance_port = "22"
|
||||
instance_protocol = "tcp"
|
||||
lb_port = "22"
|
||||
lb_protocol = "tcp"
|
||||
}
|
||||
|
||||
tags {
|
||||
Name = "elb-test"
|
||||
}
|
||||
}
|
||||
|
||||
# Create a launch configuration
|
||||
resource "aws_launch_configuration" "lc" {
|
||||
name = "lc-test"
|
||||
image_id = "${data.aws_ami.atomic_ami.id}"
|
||||
instance_type = "${var.flavor}"
|
||||
security_groups = ["${var.secgrp}"]
|
||||
key_name = "${var.keypair}"
|
||||
|
||||
lifecycle {
|
||||
create_before_destroy = true
|
||||
}
|
||||
}
|
||||
|
||||
# Create an Auto Scaling group
|
||||
resource "aws_autoscaling_group" "asg" {
|
||||
name = "asg-test"
|
||||
availability_zones = ["us-west-2a","us-west-2b","us-west-2c"]
|
||||
min_size = "2"
|
||||
max_size = "2"
|
||||
desired_capacity = "2"
|
||||
launch_configuration = "${aws_launch_configuration.lc.name}"
|
||||
load_balancers = ["elb-test"]
|
||||
|
||||
lifecycle {
|
||||
create_before_destroy = true
|
||||
}
|
||||
}
|
||||
3
terraform/aws/asg-elb/provider.tf
Normal file
3
terraform/aws/asg-elb/provider.tf
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
provider "aws" {
|
||||
region = "${var.user_region}"
|
||||
}
|
||||
19
terraform/aws/asg-elb/variables.tf
Normal file
19
terraform/aws/asg-elb/variables.tf
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
variable "user_region" {
|
||||
type = "string"
|
||||
description = "AWS region in which all resources will be created"
|
||||
}
|
||||
|
||||
variable "keypair" {
|
||||
type = "string"
|
||||
description = "AWS SSH keypair to use to connect to instances"
|
||||
}
|
||||
|
||||
variable "flavor" {
|
||||
type = "string"
|
||||
description = "AWS type to use when creating instances"
|
||||
}
|
||||
|
||||
variable "secgrp" {
|
||||
type = "string"
|
||||
description = "ID of VPC security group to use"
|
||||
}
|
||||
Loading…
Reference in a new issue