Commit 1fbe90ae authored by Felix Edelsten's avatar Felix Edelsten

terraform version 0.12.29

parent 4727a83a
variable "availability_zones" { variable "availability_zones" {
description = "List of availability zone in which the ECS cluster should reside" description = "List of availability zone in which the ECS cluster should reside"
type = "list" type = list(string)
} }
variable "vpc_id" { variable "vpc_id" {
...@@ -9,7 +9,7 @@ variable "vpc_id" { ...@@ -9,7 +9,7 @@ variable "vpc_id" {
variable "subnet_ids" { variable "subnet_ids" {
description = "List of subnets in which the ECS cluster should reside" description = "List of subnets in which the ECS cluster should reside"
type = "list" type = list(string)
} }
variable "image_id" { variable "image_id" {
...@@ -34,7 +34,7 @@ variable "bastion_instances" { ...@@ -34,7 +34,7 @@ variable "bastion_instances" {
resource "aws_security_group" "bastion" { resource "aws_security_group" "bastion" {
name = "Bastion" name = "Bastion"
vpc_id = "${var.vpc_id}" vpc_id = var.vpc_id
description = "Allows traffic from and to the Bastion EC2 instance" description = "Allows traffic from and to the Bastion EC2 instance"
ingress { ingress {
...@@ -51,7 +51,6 @@ resource "aws_security_group" "bastion" { ...@@ -51,7 +51,6 @@ resource "aws_security_group" "bastion" {
cidr_blocks = ["0.0.0.0/0"] cidr_blocks = ["0.0.0.0/0"]
} }
egress { egress {
from_port = 0 from_port = 0
to_port = 0 to_port = 0
...@@ -59,61 +58,70 @@ resource "aws_security_group" "bastion" { ...@@ -59,61 +58,70 @@ resource "aws_security_group" "bastion" {
cidr_blocks = ["0.0.0.0/0"] cidr_blocks = ["0.0.0.0/0"]
} }
tags = { tags = [
Name = "Bastion" {
} key = "Name"
value = "Bastion"
propagate_at_launch = true
}
]
lifecycle { create_before_destroy = true } lifecycle {
create_before_destroy = true
}
} }
data "template_file" "userdata" { data "template_file" "userdata" {
template = "${file("${path.module}/userdata.yml")}" template = file("${path.module}/userdata.yml")
vars {} vars = {}
} }
resource "aws_launch_configuration" "bastion" { resource "aws_launch_configuration" "bastion" {
name_prefix = "${format("%s-", "Bastion")}" name_prefix = format("%s-", "Bastion")
image_id = var.image_id
image_id = "${var.image_id}" instance_type = var.instance_type
instance_type = "${var.instance_type}" key_name = var.key_name
key_name = "${var.key_name}" security_groups = [aws_security_group.bastion.id]
security_groups = ["${aws_security_group.bastion.id}"] user_data = data.template_file.userdata.rendered
user_data = "${data.template_file.userdata.rendered}"
lifecycle { lifecycle {
create_before_destroy = true create_before_destroy = true
ignore_changes = [ ignore_changes = [
"image_id", image_id,
] ]
} }
} }
resource "aws_autoscaling_group" "bastion" { resource "aws_autoscaling_group" "bastion" {
name = "Bastion - ${aws_launch_configuration.bastion.name}" name = "Bastion - ${aws_launch_configuration.bastion.name}"
availability_zones = ["${var.availability_zones}"] availability_zones = var.availability_zones
vpc_zone_identifier = ["${var.subnet_ids}"] vpc_zone_identifier = flatten([var.subnet_ids])
launch_configuration = "${aws_launch_configuration.bastion.id}" launch_configuration = aws_launch_configuration.bastion.id
min_size = "${var.bastion_instances}" min_size = var.bastion_instances
max_size = "${var.bastion_instances}" max_size = var.bastion_instances
desired_capacity = "${var.bastion_instances}" desired_capacity = var.bastion_instances
tag { tags = [
{
key = "Name" key = "Name"
value = "Bastion" value = "Bastion"
propagate_at_launch = true propagate_at_launch = true
} },
tag { {
key = "service" key = "service"
value = "bastion" value = "bastion"
propagate_at_launch = true propagate_at_launch = true
} }
]
lifecycle { create_before_destroy = true } lifecycle {
create_before_destroy = true
}
} }
############################################################################################################# #############################################################################################################
# Outputs # Outputs
############################################################################################################# #############################################################################################################
output "security_group" { output "security_group" {
value = "${aws_security_group.bastion.id}" value = aws_security_group.bastion.id
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment