Last active
March 19, 2018 18:08
-
-
Save santiagopoli/5bb4591cad4fddd80c9fc0df10637054 to your computer and use it in GitHub Desktop.
Terraform Blue Green / Instances V2
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
locals { | |
subnets = ["${aws_subnet.terraform-blue-green.*.id}"] | |
user_data = <<EOF | |
#cloud-config | |
runcmd: | |
- docker run -d -p 80:80 nginx:latest | |
EOF | |
} | |
resource "aws_instance" "terraform-blue-green" { | |
count = 3 | |
ami = "ami-baa236c2" | |
instance_type = "t2.medium" | |
subnet_id = "${element(local.subnets, count.index)}" | |
vpc_security_group_ids = ["${aws_security_group.terraform-blue-green.id}"] | |
key_name = "${aws_key_pair.terraform-blue-green.key_name}" | |
user_data = "${local.user_data}" | |
tags { | |
Name = "Terraform Blue/Green ${count.index + 1} (v${var.infrastructure_version})" | |
InfrastructureVersion = "${var.infrastructure_version}" | |
} | |
} | |
output "instance_public_ips" { | |
value = "${aws_instance.terraform-blue-green.*.public_ip}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment