From c9017580aaff512daa28f8e2953907d972a07099 Mon Sep 17 00:00:00 2001 From: Chris Long Date: Thu, 23 May 2019 23:40:12 -0700 Subject: [PATCH] Terraform: Update logger to use AWS data source for AMI resolution --- Terraform/locals.tf | 1 + Terraform/main.tf | 14 +++++++------- Terraform/outputs.tf | 12 ++---------- Terraform/variables.tf | 18 +++++++++++++++++- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/Terraform/locals.tf b/Terraform/locals.tf index 70f9603..9e99bfd 100644 --- a/Terraform/locals.tf +++ b/Terraform/locals.tf @@ -1,4 +1,5 @@ locals { fleet_url = "https://${aws_instance.logger.public_ip}:8412" splunk_url = "https://${aws_instance.logger.public_ip}:8000" + ata_url = "https://${aws_instance.wef.public_ip}" } diff --git a/Terraform/main.tf b/Terraform/main.tf index 353f90d..1054f3a 100644 --- a/Terraform/main.tf +++ b/Terraform/main.tf @@ -142,7 +142,7 @@ resource "aws_key_pair" "auth" { resource "aws_instance" "logger" { instance_type = "t2.medium" - ami = "ami-0ad16744583f21877" + ami = "${coalesce(data.aws_ami.logger_ami.image_id, var.logger_ami)}" tags { Name = "logger" @@ -187,8 +187,8 @@ resource "aws_instance" "logger" { resource "aws_instance" "dc" { instance_type = "t2.medium" - # Change the below variable to "${var.dc_ami}" if using hardcoded AMIs - ami = "${data.aws_ami.dc_ami.image_id}" + # Uses the local variable if external data source resolution fails + ami = "${coalesce(data.aws_ami.dc_ami.image_id, var.dc_ami)}" tags { Name = "dc.windomain.local" @@ -206,8 +206,8 @@ resource "aws_instance" "dc" { resource "aws_instance" "wef" { instance_type = "t2.medium" - # Change the below variable to "${var.wef_ami}" if using hardcoded AMIs - ami = "${data.aws_ami.wef_ami.image_id}" + # Uses the local variable if external data source resolution fails + ami = "${coalesce(data.aws_ami.wef_ami.image_id, var.wef_ami)}" tags { Name = "wef.windomain.local" @@ -225,8 +225,8 @@ resource "aws_instance" "wef" { resource "aws_instance" "win10" { instance_type = "t2.medium" - # Change the below variable to "${var.win10_ami}" if using hardcoded AMIs - ami = "${data.aws_ami.win10_ami.image_id}" + # Uses the local variable if external data source resolution fails + ami = "${coalesce(data.aws_ami.win10_ami.image_id, var.win10_ami)}" tags { Name = "win10.windomain.local" diff --git a/Terraform/outputs.tf b/Terraform/outputs.tf index c2336ae..30afa81 100644 --- a/Terraform/outputs.tf +++ b/Terraform/outputs.tf @@ -18,16 +18,8 @@ output "win10_public_ip" { value = "${aws_instance.win10.public_ip}" } -output "latest_dc_ami_id" { - value = "${data.aws_ami.dc_ami.image_id}" -} - -output "latest_wef_ami_id" { - value = "${data.aws_ami.wef_ami.image_id}" -} - -output "latest_win10_ami_id" { - value = "${data.aws_ami.wef_ami.image_id}" +output "ata_url" { + value = "${local.ata_url}" } output "fleet_url" { diff --git a/Terraform/variables.tf b/Terraform/variables.tf index c90fac8..fda5ba1 100644 --- a/Terraform/variables.tf +++ b/Terraform/variables.tf @@ -46,6 +46,16 @@ variable "external_dns_servers" { default = ["8.8.8.8"] } +# Use Data Sources to resolve the AMI-ID for the Ubuntu 16.04 AMI +data "aws_ami" "logger_ami" { + owners = ["099720109477"] + + filter { + name = "name" + values = ["ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-20180912"] + } +} + # Use Data Sources to resolve the AMI-ID for the pre-built DC host data "aws_ami" "dc_ami" { owners = ["505638924199"] @@ -78,9 +88,15 @@ data "aws_ami" "win10_ami" { } } -# The logger host uses the Amazon Ubuntu 16.04 image # If you are building your own AMIs, replace the default values below with # the AMI IDs +# The default values for us-west-1 have been provied for you +# You will have to change the default values if you use a different region +variable "logger_ami" { + type = "string" + default = "ami-0ad16744583f21877" +} + variable "dc_ami" { type = "string" default = "ami-03e2df055c632a0dd"