|
@@ -17,8 +17,8 @@ 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.repo_server_security_group_80.id, aws_security_group.repo_server_security_group_443.id]
|
|
|
+ subnet_id = var.public_subnets[0]
|
|
|
+ security_groups = [data.aws_security_group.typical-host.id, aws_security_group.repo_server_security_group.id]
|
|
|
description = var.instance_name
|
|
|
tags = merge(var.standard_tags, var.tags, { Name = var.instance_name })
|
|
|
}
|
|
@@ -49,6 +49,12 @@ resource "aws_instance" "instance" {
|
|
|
# that could be removed.
|
|
|
lifecycle { ignore_changes = [ami, key_name, user_data, ebs_block_device] }
|
|
|
|
|
|
+ metadata_options {
|
|
|
+ http_endpoint = "enabled"
|
|
|
+ http_tokens = "optional" # tfsec:ignore:aws-ec2-enforce-http-token-imds Breaks salt
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
# These device definitions are optional, but added for clarity.
|
|
|
root_block_device {
|
|
|
volume_type = "gp3"
|
|
@@ -141,7 +147,7 @@ resource "aws_instance" "instance" {
|
|
|
module "private_dns_record" {
|
|
|
source = "../../submodules/dns/private_A_record"
|
|
|
|
|
|
- name = var.instance_name
|
|
|
+ name = "${var.instance_name}-server"
|
|
|
ip_addresses = [aws_instance.instance.private_ip]
|
|
|
dns_info = var.dns_info
|
|
|
reverse_enabled = var.reverse_enabled
|
|
@@ -151,18 +157,6 @@ 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
|
|
|
-
|
|
|
- providers = {
|
|
|
- aws.mdr-common-services-commercial = aws.mdr-common-services-commercial
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
# Render a multi-part cloud-init config making use of the part
|
|
|
# above, and other source files
|
|
|
data "template_cloudinit_config" "cloud_init_config" {
|
|
@@ -193,78 +187,33 @@ data "template_cloudinit_config" "cloud_init_config" {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-resource "aws_security_group" "repo_server_security_group_80" {
|
|
|
- name = "repo_server_security_group_80"
|
|
|
+resource "aws_security_group" "repo_server_security_group" {
|
|
|
+ name = "repo_server_security_group"
|
|
|
description = "Security Group for the Repository Server(s) port 80"
|
|
|
vpc_id = var.vpc_id
|
|
|
tags = merge(var.standard_tags, var.tags)
|
|
|
}
|
|
|
|
|
|
-resource "aws_security_group" "repo_server_security_group_443" {
|
|
|
- name = "repo_server_security_group_443"
|
|
|
- description = "Security Group for the Repository Server(s) port 443"
|
|
|
- vpc_id = var.vpc_id
|
|
|
- tags = merge(var.standard_tags, var.tags)
|
|
|
-}
|
|
|
-
|
|
|
resource "aws_security_group_rule" "http-in" {
|
|
|
- description = "inbound repository requests"
|
|
|
- type = "ingress"
|
|
|
- from_port = 80
|
|
|
- to_port = 80
|
|
|
- protocol = "tcp"
|
|
|
- cidr_blocks = toset(concat(["10.0.0.0/8"], var.repo_server_whitelist))
|
|
|
- security_group_id = aws_security_group.repo_server_security_group_80.id
|
|
|
-}
|
|
|
-
|
|
|
-resource "aws_security_group_rule" "http-in-external-c2-users" {
|
|
|
-
|
|
|
- # This deserves some explanation. Terraform "for_each" expects to be
|
|
|
- # getting as input a map of values to iterate over as part of the foreach.
|
|
|
- # The keys of the map are used to name each of these objects created. Looking
|
|
|
- # in the terraform plan output of a for_each you'll see things like:
|
|
|
- #
|
|
|
- # aws_security_group_rule.resource_name["key-value-from-foreach"] will be created
|
|
|
- #
|
|
|
- # Our c2_services_external_ips is a list of maps, not a map of maps. The for-expression
|
|
|
- # makes a new thing that is a map of maps, where the key value is the description with
|
|
|
- # blanks removed.
|
|
|
- #
|
|
|
- # We could have made the variable more natively-friendly to for_each but this seemed
|
|
|
- # like a better solution for what we were trying to accomplish.
|
|
|
- for_each = { for s in var.c2_services_external_ips : replace(s.description, "/\\s*/", "") => s }
|
|
|
-
|
|
|
- description = "inbound repository requests - ${each.value.description}"
|
|
|
- type = "ingress"
|
|
|
- from_port = 80
|
|
|
- to_port = 80
|
|
|
- protocol = "tcp"
|
|
|
- cidr_blocks = each.value.cidr_blocks
|
|
|
- security_group_id = aws_security_group.repo_server_security_group_80.id
|
|
|
+ description = "inbound repository requests"
|
|
|
+ type = "ingress"
|
|
|
+ from_port = 80
|
|
|
+ to_port = 80
|
|
|
+ protocol = "tcp"
|
|
|
+ source_security_group_id = aws_security_group.alb_internal.id
|
|
|
+ security_group_id = aws_security_group.repo_server_security_group.id
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-resource "aws_security_group_rule" "https-in" {
|
|
|
- description = "inbound repository requests"
|
|
|
- type = "ingress"
|
|
|
- from_port = 443
|
|
|
- to_port = 443
|
|
|
- protocol = "tcp"
|
|
|
- cidr_blocks = toset(concat(["10.0.0.0/8"], var.repo_server_whitelist))
|
|
|
- security_group_id = aws_security_group.repo_server_security_group_443.id
|
|
|
+resource "aws_security_group_rule" "http-in-external" {
|
|
|
+ description = "inbound repository requests from the alb"
|
|
|
+ type = "ingress"
|
|
|
+ from_port = 80
|
|
|
+ to_port = 80
|
|
|
+ protocol = "tcp"
|
|
|
+ source_security_group_id = module.elb.security_group_id
|
|
|
+ security_group_id = aws_security_group.repo_server_security_group.id
|
|
|
}
|
|
|
|
|
|
-resource "aws_security_group_rule" "https-in-external-c2-users" {
|
|
|
- for_each = { for s in var.c2_services_external_ips : replace(s.description, "/\\s*/", "") => s }
|
|
|
-
|
|
|
- description = "inbound repository requests - ${each.value.description}"
|
|
|
- type = "ingress"
|
|
|
- from_port = 443
|
|
|
- to_port = 443
|
|
|
- protocol = "tcp"
|
|
|
- cidr_blocks = each.value.cidr_blocks
|
|
|
- security_group_id = aws_security_group.repo_server_security_group_443.id
|
|
|
-}
|
|
|
|
|
|
|
|
|
# Repo server has an extra volume that is created separately, to keep it from being destroyed
|
|
@@ -273,6 +222,8 @@ resource "aws_ebs_volume" "repo_server_drive" {
|
|
|
availability_zone = aws_instance.instance.availability_zone
|
|
|
size = local.repo_drive_size
|
|
|
type = "gp3" # consider moving to sc1 if this is ever > 500GB
|
|
|
+ encrypted = true
|
|
|
+ kms_key_id = data.aws_kms_key.ebs-key.arn
|
|
|
|
|
|
#snapshot_id = "${data.aws_ebs_snapshot.repo_snapshot.id}"
|
|
|
|