|
@@ -16,55 +16,55 @@ data "aws_kms_key" "ebs-key" {
|
|
|
}
|
|
|
|
|
|
resource "aws_network_interface" "instance" {
|
|
|
- subnet_id = var.subnets[0]
|
|
|
- security_groups = [ data.aws_security_group.typical-host.id, aws_security_group.bastion_security_group.id ]
|
|
|
- description = var.instance_name
|
|
|
- tags = merge(var.standard_tags, var.tags, { Name = var.instance_name })
|
|
|
+ subnet_id = var.subnets[0]
|
|
|
+ security_groups = [data.aws_security_group.typical-host.id, aws_security_group.bastion_security_group.id]
|
|
|
+ description = var.instance_name
|
|
|
+ tags = merge(var.standard_tags, var.tags, { Name = var.instance_name })
|
|
|
}
|
|
|
|
|
|
resource "aws_eip" "instance" {
|
|
|
- vpc = true
|
|
|
+ vpc = true
|
|
|
tags = merge(var.standard_tags, var.tags, { Name = var.instance_name })
|
|
|
}
|
|
|
|
|
|
resource "aws_eip_association" "instance" {
|
|
|
network_interface_id = aws_network_interface.instance.id
|
|
|
- allocation_id = aws_eip.instance.id
|
|
|
+ allocation_id = aws_eip.instance.id
|
|
|
}
|
|
|
|
|
|
resource "aws_instance" "instance" {
|
|
|
#availability_zone = var.azs[count.index % 2]
|
|
|
- tenancy = "default"
|
|
|
- ebs_optimized = true
|
|
|
- disable_api_termination = var.instance_termination_protection
|
|
|
+ tenancy = "default"
|
|
|
+ ebs_optimized = true
|
|
|
+ disable_api_termination = var.instance_termination_protection
|
|
|
instance_initiated_shutdown_behavior = "stop"
|
|
|
- instance_type = var.instance_type
|
|
|
- key_name = "msoc-build"
|
|
|
- monitoring = false
|
|
|
- iam_instance_profile = "msoc-default-instance-profile"
|
|
|
+ instance_type = var.instance_type
|
|
|
+ key_name = "msoc-build"
|
|
|
+ monitoring = false
|
|
|
+ iam_instance_profile = "msoc-default-instance-profile"
|
|
|
|
|
|
ami = local.ami_map[local.ami_selection]
|
|
|
# We need to ignore ebs_block_device changes, because if the AMI changes, so does the snapshot_id.
|
|
|
# If they add a feature to block more specific changes (eg `ebs_block_devices[*].snapshot_id`), then
|
|
|
# that could be removed.
|
|
|
- lifecycle { ignore_changes = [ ami, key_name, user_data, ebs_block_device ] }
|
|
|
+ lifecycle { ignore_changes = [ami, key_name, user_data, ebs_block_device] }
|
|
|
|
|
|
# These device definitions are optional, but added for clarity.
|
|
|
root_block_device {
|
|
|
- volume_type = "gp2"
|
|
|
- #volume_size = "60"
|
|
|
- delete_on_termination = true
|
|
|
- encrypted = true
|
|
|
- kms_key_id = data.aws_kms_key.ebs-key.arn
|
|
|
+ volume_type = "gp2"
|
|
|
+ #volume_size = "60"
|
|
|
+ delete_on_termination = true
|
|
|
+ encrypted = true
|
|
|
+ kms_key_id = data.aws_kms_key.ebs-key.arn
|
|
|
}
|
|
|
|
|
|
ebs_block_device {
|
|
|
# swap
|
|
|
- device_name = "/dev/xvdm"
|
|
|
- volume_size = 48
|
|
|
+ device_name = "/dev/xvdm"
|
|
|
+ volume_size = 48
|
|
|
delete_on_termination = true
|
|
|
- encrypted = true
|
|
|
- kms_key_id = data.aws_kms_key.ebs-key.arn
|
|
|
+ encrypted = true
|
|
|
+ kms_key_id = data.aws_kms_key.ebs-key.arn
|
|
|
# Snapshot IDs need to be grabbed from the ami, or it will replace every time. It's ugly.
|
|
|
# This may prompt replacement when the AMI is updated.
|
|
|
# See:
|
|
@@ -77,9 +77,9 @@ resource "aws_instance" "instance" {
|
|
|
device_name = "/dev/xvdn"
|
|
|
# volume_size = xx
|
|
|
delete_on_termination = true
|
|
|
- encrypted = true
|
|
|
- kms_key_id = data.aws_kms_key.ebs-key.arn
|
|
|
- snapshot_id = local.block_device_mappings[local.ami_selection]["/dev/xvdn"].ebs.snapshot_id
|
|
|
+ encrypted = true
|
|
|
+ kms_key_id = data.aws_kms_key.ebs-key.arn
|
|
|
+ snapshot_id = local.block_device_mappings[local.ami_selection]["/dev/xvdn"].ebs.snapshot_id
|
|
|
|
|
|
}
|
|
|
ebs_block_device {
|
|
@@ -87,63 +87,63 @@ resource "aws_instance" "instance" {
|
|
|
device_name = "/dev/xvdo"
|
|
|
# volume_size = xx
|
|
|
delete_on_termination = true
|
|
|
- encrypted = true
|
|
|
- kms_key_id = data.aws_kms_key.ebs-key.arn
|
|
|
- snapshot_id = local.block_device_mappings[local.ami_selection]["/dev/xvdo"].ebs.snapshot_id
|
|
|
+ encrypted = true
|
|
|
+ kms_key_id = data.aws_kms_key.ebs-key.arn
|
|
|
+ snapshot_id = local.block_device_mappings[local.ami_selection]["/dev/xvdo"].ebs.snapshot_id
|
|
|
}
|
|
|
ebs_block_device {
|
|
|
# /var/tmp
|
|
|
device_name = "/dev/xvdp"
|
|
|
# volume_size = xx
|
|
|
delete_on_termination = true
|
|
|
- encrypted = true
|
|
|
- kms_key_id = data.aws_kms_key.ebs-key.arn
|
|
|
- snapshot_id = local.block_device_mappings[local.ami_selection]["/dev/xvdp"].ebs.snapshot_id
|
|
|
+ encrypted = true
|
|
|
+ kms_key_id = data.aws_kms_key.ebs-key.arn
|
|
|
+ snapshot_id = local.block_device_mappings[local.ami_selection]["/dev/xvdp"].ebs.snapshot_id
|
|
|
}
|
|
|
ebs_block_device {
|
|
|
# /var/log
|
|
|
device_name = "/dev/xvdq"
|
|
|
# volume_size = xx
|
|
|
delete_on_termination = true
|
|
|
- encrypted = true
|
|
|
- kms_key_id = data.aws_kms_key.ebs-key.arn
|
|
|
- snapshot_id = local.block_device_mappings[local.ami_selection]["/dev/xvdq"].ebs.snapshot_id
|
|
|
+ encrypted = true
|
|
|
+ kms_key_id = data.aws_kms_key.ebs-key.arn
|
|
|
+ snapshot_id = local.block_device_mappings[local.ami_selection]["/dev/xvdq"].ebs.snapshot_id
|
|
|
}
|
|
|
ebs_block_device {
|
|
|
# /var/log/audit
|
|
|
device_name = "/dev/xvdr"
|
|
|
# volume_size = xx
|
|
|
delete_on_termination = true
|
|
|
- encrypted = true
|
|
|
- kms_key_id = data.aws_kms_key.ebs-key.arn
|
|
|
- snapshot_id = local.block_device_mappings[local.ami_selection]["/dev/xvdr"].ebs.snapshot_id
|
|
|
+ encrypted = true
|
|
|
+ kms_key_id = data.aws_kms_key.ebs-key.arn
|
|
|
+ snapshot_id = local.block_device_mappings[local.ami_selection]["/dev/xvdr"].ebs.snapshot_id
|
|
|
}
|
|
|
ebs_block_device {
|
|
|
# /tmp
|
|
|
device_name = "/dev/xvds"
|
|
|
# volume_size = xx
|
|
|
delete_on_termination = true
|
|
|
- encrypted = true
|
|
|
- kms_key_id = data.aws_kms_key.ebs-key.arn
|
|
|
- snapshot_id = local.block_device_mappings[local.ami_selection]["/dev/xvds"].ebs.snapshot_id
|
|
|
+ encrypted = true
|
|
|
+ kms_key_id = data.aws_kms_key.ebs-key.arn
|
|
|
+ snapshot_id = local.block_device_mappings[local.ami_selection]["/dev/xvds"].ebs.snapshot_id
|
|
|
}
|
|
|
|
|
|
network_interface {
|
|
|
- device_index = 0
|
|
|
+ device_index = 0
|
|
|
network_interface_id = aws_network_interface.instance.id
|
|
|
}
|
|
|
|
|
|
- user_data = data.template_cloudinit_config.cloud-init.rendered
|
|
|
- tags = merge( var.standard_tags, var.tags, var.instance_tags, { Name = var.instance_name })
|
|
|
- volume_tags = merge( var.standard_tags, var.tags, { Name = var.instance_name })
|
|
|
+ user_data = data.template_cloudinit_config.cloud-init.rendered
|
|
|
+ tags = merge(var.standard_tags, var.tags, var.instance_tags, { Name = var.instance_name })
|
|
|
+ volume_tags = merge(var.standard_tags, var.tags, { Name = var.instance_name })
|
|
|
}
|
|
|
|
|
|
module "private_dns_record" {
|
|
|
source = "../../submodules/dns/private_A_record"
|
|
|
|
|
|
- name = var.instance_name
|
|
|
- ip_addresses = [ aws_instance.instance.private_ip ]
|
|
|
- dns_info = var.dns_info
|
|
|
+ name = var.instance_name
|
|
|
+ ip_addresses = [aws_instance.instance.private_ip]
|
|
|
+ dns_info = var.dns_info
|
|
|
reverse_enabled = var.reverse_enabled
|
|
|
|
|
|
providers = {
|
|
@@ -154,9 +154,9 @@ module "private_dns_record" {
|
|
|
module "public_dns_record" {
|
|
|
source = "../../submodules/dns/public_A_record"
|
|
|
|
|
|
- name = var.instance_name
|
|
|
- ip_addresses = [ aws_eip.instance.public_ip ]
|
|
|
- dns_info = var.dns_info
|
|
|
+ name = var.instance_name
|
|
|
+ ip_addresses = [aws_eip.instance.public_ip]
|
|
|
+ dns_info = var.dns_info
|
|
|
|
|
|
providers = {
|
|
|
aws.mdr-common-services-commercial = aws.mdr-common-services-commercial
|
|
@@ -173,16 +173,16 @@ data "template_cloudinit_config" "cloud-init" {
|
|
|
part {
|
|
|
filename = "init.cfg"
|
|
|
content_type = "text/cloud-config"
|
|
|
- content = templatefile("${path.module}/cloud-init/cloud-init.tpl",
|
|
|
+ content = templatefile("${path.module}/cloud-init/cloud-init.tpl",
|
|
|
{
|
|
|
- hostname = var.instance_name
|
|
|
- fqdn = "${var.instance_name}.${var.dns_info["private"]["zone"]}"
|
|
|
- environment = var.environment
|
|
|
- salt_master = var.salt_master
|
|
|
- proxy = var.proxy
|
|
|
- aws_partition = var.aws_partition
|
|
|
+ hostname = var.instance_name
|
|
|
+ fqdn = "${var.instance_name}.${var.dns_info["private"]["zone"]}"
|
|
|
+ environment = var.environment
|
|
|
+ salt_master = var.salt_master
|
|
|
+ proxy = var.proxy
|
|
|
+ aws_partition = var.aws_partition
|
|
|
aws_partition_alias = var.aws_partition_alias
|
|
|
- aws_region = var.aws_region
|
|
|
+ aws_region = var.aws_region
|
|
|
}
|
|
|
)
|
|
|
}
|
|
@@ -195,10 +195,10 @@ data "template_cloudinit_config" "cloud-init" {
|
|
|
}
|
|
|
|
|
|
resource "aws_security_group" "bastion_security_group" {
|
|
|
- name = "bastion_security_group"
|
|
|
+ name = "bastion_security_group"
|
|
|
description = "Security Group for Bastion Server(s)"
|
|
|
- vpc_id = var.vpc_id
|
|
|
- tags = merge(var.standard_tags, var.tags)
|
|
|
+ vpc_id = var.vpc_id
|
|
|
+ tags = merge(var.standard_tags, var.tags)
|
|
|
}
|
|
|
|
|
|
resource "aws_security_group_rule" "ssh-in" {
|
|
@@ -232,39 +232,39 @@ resource "aws_security_group_rule" "ssh-in" {
|
|
|
#}
|
|
|
|
|
|
resource "aws_security_group_rule" "ssh-out" {
|
|
|
- type = "egress"
|
|
|
- from_port = 22
|
|
|
- to_port = 22
|
|
|
- protocol = "tcp"
|
|
|
- cidr_blocks = [ "10.0.0.0/8" ]
|
|
|
+ type = "egress"
|
|
|
+ from_port = 22
|
|
|
+ to_port = 22
|
|
|
+ protocol = "tcp"
|
|
|
+ cidr_blocks = ["10.0.0.0/8"]
|
|
|
security_group_id = aws_security_group.bastion_security_group.id
|
|
|
}
|
|
|
|
|
|
# Bastion can access any port internally
|
|
|
resource "aws_security_group_rule" "bastion-out-all-ports" {
|
|
|
- type = "egress"
|
|
|
- protocol = "all"
|
|
|
- from_port = -1
|
|
|
- to_port = -1
|
|
|
- cidr_blocks = [ "10.0.0.0/8" ]
|
|
|
+ type = "egress"
|
|
|
+ protocol = "all"
|
|
|
+ from_port = -1
|
|
|
+ to_port = -1
|
|
|
+ cidr_blocks = ["10.0.0.0/8"]
|
|
|
security_group_id = aws_security_group.bastion_security_group.id
|
|
|
}
|
|
|
|
|
|
# Bastion gets http/https out to the internet. Most hosts need to use the proxy
|
|
|
resource "aws_security_group_rule" "http-out" {
|
|
|
- type = "egress"
|
|
|
- from_port = 80
|
|
|
- to_port = 80
|
|
|
- protocol = "tcp"
|
|
|
- cidr_blocks = [ "0.0.0.0/0" ]
|
|
|
+ type = "egress"
|
|
|
+ from_port = 80
|
|
|
+ to_port = 80
|
|
|
+ protocol = "tcp"
|
|
|
+ cidr_blocks = ["0.0.0.0/0"]
|
|
|
security_group_id = aws_security_group.bastion_security_group.id
|
|
|
}
|
|
|
|
|
|
resource "aws_security_group_rule" "https-out" {
|
|
|
- type = "egress"
|
|
|
- from_port = 443
|
|
|
- to_port = 443
|
|
|
- protocol = "tcp"
|
|
|
- cidr_blocks = [ "0.0.0.0/0" ]
|
|
|
+ type = "egress"
|
|
|
+ from_port = 443
|
|
|
+ to_port = 443
|
|
|
+ protocol = "tcp"
|
|
|
+ cidr_blocks = ["0.0.0.0/0"]
|
|
|
security_group_id = aws_security_group.bastion_security_group.id
|
|
|
}
|