Add outputs and run terraform fmt

This commit is contained in:
Andrew Svoboda
2019-05-23 16:17:40 -07:00
parent 0f74025d44
commit 3866c64a9f
4 changed files with 83 additions and 40 deletions

4
Terraform/locals.tf Normal file
View File

@@ -0,0 +1,4 @@
locals {
fleet_url = "https://${aws_instance.logger.public_ip}:8412"
splunk_url = "https://${aws_instance.logger.public_ip}:8000"
}

View File

@@ -36,6 +36,7 @@ resource "aws_vpc_dhcp_options" "default" {
domain_name_servers = ["${aws_instance.dc.private_ip}", "${var.external_dns_servers}"] domain_name_servers = ["${aws_instance.dc.private_ip}", "${var.external_dns_servers}"]
netbios_name_servers = ["${aws_instance.dc.private_ip}"] netbios_name_servers = ["${aws_instance.dc.private_ip}"]
} }
resource "aws_vpc_dhcp_options_association" "default" { resource "aws_vpc_dhcp_options_association" "default" {
vpc_id = "${aws_vpc.default.id}" vpc_id = "${aws_vpc.default.id}"
dhcp_options_id = "${aws_vpc_dhcp_options.default.id}" dhcp_options_id = "${aws_vpc_dhcp_options.default.id}"
@@ -142,13 +143,16 @@ resource "aws_key_pair" "auth" {
resource "aws_instance" "logger" { resource "aws_instance" "logger" {
instance_type = "t2.medium" instance_type = "t2.medium"
ami = "ami-0ad16744583f21877" ami = "ami-0ad16744583f21877"
tags { tags {
Name = "logger" Name = "logger"
} }
subnet_id = "${aws_subnet.default.id}" subnet_id = "${aws_subnet.default.id}"
vpc_security_group_ids = ["${aws_security_group.logger.id}"] vpc_security_group_ids = ["${aws_security_group.logger.id}"]
key_name = "${aws_key_pair.auth.key_name}" key_name = "${aws_key_pair.auth.key_name}"
private_ip = "192.168.38.105" private_ip = "192.168.38.105"
# Provision the AWS Ubuntu 16.04 AMI from scratch. # Provision the AWS Ubuntu 16.04 AMI from scratch.
provisioner "remote-exec" { provisioner "remote-exec" {
inline = [ inline = [
@@ -166,12 +170,14 @@ resource "aws_instance" "logger" {
"sudo apt-get -qq update", "sudo apt-get -qq update",
"sudo /opt/DetectionLab/Vagrant/bootstrap.sh", "sudo /opt/DetectionLab/Vagrant/bootstrap.sh",
] ]
connection { connection {
type = "ssh" type = "ssh"
user = "ubuntu" user = "ubuntu"
private_key = "${file("${var.private_key_path}")}" private_key = "${file("${var.private_key_path}")}"
} }
} }
root_block_device { root_block_device {
delete_on_termination = true delete_on_termination = true
volume_size = 64 volume_size = 64
@@ -180,14 +186,18 @@ resource "aws_instance" "logger" {
resource "aws_instance" "dc" { resource "aws_instance" "dc" {
instance_type = "t2.medium" instance_type = "t2.medium"
# Change the below variable to "${var.dc_ami}" if using hardcoded AMIs # Change the below variable to "${var.dc_ami}" if using hardcoded AMIs
ami = "${data.aws_ami.dc_ami.image_id}" ami = "${data.aws_ami.dc_ami.image_id}"
tags { tags {
Name = "dc.windomain.local" Name = "dc.windomain.local"
} }
subnet_id = "${aws_subnet.default.id}" subnet_id = "${aws_subnet.default.id}"
vpc_security_group_ids = ["${aws_security_group.windows.id}"] vpc_security_group_ids = ["${aws_security_group.windows.id}"]
private_ip = "192.168.38.102" private_ip = "192.168.38.102"
root_block_device { root_block_device {
delete_on_termination = true delete_on_termination = true
} }
@@ -195,14 +205,18 @@ resource "aws_instance" "dc" {
resource "aws_instance" "wef" { resource "aws_instance" "wef" {
instance_type = "t2.medium" instance_type = "t2.medium"
# Change the below variable to "${var.wef_ami}" if using hardcoded AMIs # Change the below variable to "${var.wef_ami}" if using hardcoded AMIs
ami = "${data.aws_ami.wef_ami.image_id}" ami = "${data.aws_ami.wef_ami.image_id}"
tags { tags {
Name = "wef.windomain.local" Name = "wef.windomain.local"
} }
subnet_id = "${aws_subnet.default.id}" subnet_id = "${aws_subnet.default.id}"
vpc_security_group_ids = ["${aws_security_group.windows.id}"] vpc_security_group_ids = ["${aws_security_group.windows.id}"]
private_ip = "192.168.38.103" private_ip = "192.168.38.103"
root_block_device { root_block_device {
delete_on_termination = true delete_on_termination = true
} }
@@ -210,14 +224,18 @@ resource "aws_instance" "wef" {
resource "aws_instance" "win10" { resource "aws_instance" "win10" {
instance_type = "t2.medium" instance_type = "t2.medium"
# Change the below variable to "${var.win10_ami}" if using hardcoded AMIs # Change the below variable to "${var.win10_ami}" if using hardcoded AMIs
ami = "${data.aws_ami.win10_ami.image_id}" ami = "${data.aws_ami.win10_ami.image_id}"
tags { tags {
Name = "win10.windomain.local" Name = "win10.windomain.local"
} }
subnet_id = "${aws_subnet.default.id}" subnet_id = "${aws_subnet.default.id}"
vpc_security_group_ids = ["${aws_security_group.windows.id}"] vpc_security_group_ids = ["${aws_security_group.windows.id}"]
private_ip = "192.168.38.104" private_ip = "192.168.38.104"
root_block_device { root_block_device {
delete_on_termination = true delete_on_termination = true
} }

View File

@@ -29,3 +29,11 @@ output "latest_wef_ami_id" {
output "latest_win10_ami_id" { output "latest_win10_ami_id" {
value = "${data.aws_ami.wef_ami.image_id}" value = "${data.aws_ami.wef_ami.image_id}"
} }
output "fleet_url" {
value = "${local.fleet_url}"
}
output "splunk_url" {
value = "${local.splunk_url}"
}

View File

@@ -1,37 +1,45 @@
variable "region" { variable "region" {
default = "us-west-1" default = "us-west-1"
} }
variable "profile" { variable "profile" {
default = "terraform" default = "terraform"
} }
variable "availability_zone" { variable "availability_zone" {
description = "https://www.terraform.io/docs/providers/aws/d/availability_zone.html" description = "https://www.terraform.io/docs/providers/aws/d/availability_zone.html"
default = "" default = ""
} }
variable "shared_credentials_file" { variable "shared_credentials_file" {
description = "Path to your AWS credentials file" description = "Path to your AWS credentials file"
type = "string" type = "string"
default = "/home/username/.aws/credentials" default = "/home/username/.aws/credentials"
} }
variable "public_key_name" { variable "public_key_name" {
description = "A name for AWS Keypair to use to auth to logger. Can be anything you specify." description = "A name for AWS Keypair to use to auth to logger. Can be anything you specify."
default = "id_logger" default = "id_logger"
} }
variable "public_key_path" { variable "public_key_path" {
description = "Path to the public key to be loaded into the logger authorized_keys file" description = "Path to the public key to be loaded into the logger authorized_keys file"
type = "string" type = "string"
default = "/home/username/.ssh/id_logger.pub" default = "/home/username/.ssh/id_logger.pub"
} }
variable "private_key_path" { variable "private_key_path" {
description = "Path to the private key to use to authenticate to logger." description = "Path to the private key to use to authenticate to logger."
type = "string" type = "string"
default = "/home/username/.ssh/id_logger" default = "/home/username/.ssh/id_logger"
} }
variable "ip_whitelist" { variable "ip_whitelist" {
description = "A list of CIDRs that will be allowed to access the EC2 instances" description = "A list of CIDRs that will be allowed to access the EC2 instances"
type = "list" type = "list"
default = [""] default = [""]
} }
variable "external_dns_servers" { variable "external_dns_servers" {
description = "Configure lab to allow external DNS resolution" description = "Configure lab to allow external DNS resolution"
type = "list" type = "list"
@@ -41,6 +49,7 @@ variable "external_dns_servers" {
# Use Data Sources to resolve the AMI-ID for the pre-built DC host # Use Data Sources to resolve the AMI-ID for the pre-built DC host
data "aws_ami" "dc_ami" { data "aws_ami" "dc_ami" {
owners = ["505638924199"] owners = ["505638924199"]
filter { filter {
name = "name" name = "name"
values = ["detectionlab-dc"] values = ["detectionlab-dc"]
@@ -51,6 +60,7 @@ data "aws_ami" "dc_ami" {
data "aws_ami" "wef_ami" { data "aws_ami" "wef_ami" {
owners = ["505638924199"] owners = ["505638924199"]
most_recent = true most_recent = true
filter { filter {
name = "name" name = "name"
values = ["detectionlab-wef"] values = ["detectionlab-wef"]
@@ -61,6 +71,7 @@ data "aws_ami" "wef_ami" {
data "aws_ami" "win10_ami" { data "aws_ami" "win10_ami" {
owners = ["505638924199"] owners = ["505638924199"]
most_recent = true most_recent = true
filter { filter {
name = "name" name = "name"
values = ["detectionlab-win10"] values = ["detectionlab-win10"]
@@ -74,10 +85,12 @@ variable "dc_ami" {
type = "string" type = "string"
default = "ami-03e2df055c632a0dd" default = "ami-03e2df055c632a0dd"
} }
variable "wef_ami" { variable "wef_ami" {
type = "string" type = "string"
default = "ami-03c82482c03a740c5" default = "ami-03c82482c03a740c5"
} }
variable "win10_ami" { variable "win10_ami" {
type = "string" type = "string"
default = "ami-0a4644e74768900f7" default = "ami-0a4644e74768900f7"