|
@@ -1,31 +1,343 @@
|
|
|
-#Certificate
|
|
|
-resource "aws_acm_certificate" "portal_cert" {
|
|
|
- domain_name = "portal.${var.dns_info["public"]["zone"]}"
|
|
|
- validation_method = "DNS"
|
|
|
+# Some instance variables
|
|
|
+locals {
|
|
|
+ ami_selection = "minion" # master, minion, ...
|
|
|
+}
|
|
|
+
|
|
|
+# Rather than pass in the aws security group, we just look it up. This will
|
|
|
+# probably be useful other places, as well.
|
|
|
+data "aws_security_group" "typical-host" {
|
|
|
+ name = "typical-host"
|
|
|
+ vpc_id = var.vpc_id
|
|
|
+}
|
|
|
+
|
|
|
+# Use the default EBS key
|
|
|
+data "aws_kms_key" "ebs-key" {
|
|
|
+ key_id = "alias/ebs_root_encrypt_decrypt"
|
|
|
+}
|
|
|
+
|
|
|
+#------------------------------------
|
|
|
+# EC2 ASG
|
|
|
+#------------------------------------
|
|
|
+module "customer_portal_asg" {
|
|
|
+ source = "terraform-aws-modules/autoscaling/aws"
|
|
|
+ version = "3.8.0"
|
|
|
+ name = "customer-portal"
|
|
|
+
|
|
|
+ lc_name = "customer-portal-lc"
|
|
|
|
|
|
- tags = merge(var.standard_tags, var.tags)
|
|
|
+ iam_instance_profile = aws_iam_instance_profile.portal_server_instance_profile.name
|
|
|
+ image_id = local.ami_map[local.ami_selection]
|
|
|
+ instance_type = var.instance_type
|
|
|
+ security_groups = [ data.aws_security_group.typical-host.id, aws_security_group.customer_portal.id ]
|
|
|
+ user_data = data.template_cloudinit_config.cloud-init.rendered
|
|
|
+ key_name = "msoc-build"
|
|
|
+ ebs_optimized = true
|
|
|
+
|
|
|
+ root_block_device = [
|
|
|
+ {
|
|
|
+ volume_type = "gp2"
|
|
|
+ volume_size = "100"
|
|
|
+ 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
|
|
|
+ delete_on_termination = true
|
|
|
+ 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:
|
|
|
+ # https://github.com/hashicorp/terraform/issues/19958
|
|
|
+ # https://github.com/terraform-providers/terraform-provider-aws/issues/13118
|
|
|
+ snapshot_id = local.block_device_mappings[local.ami_selection]["/dev/xvdm"].ebs.snapshot_id
|
|
|
+ },
|
|
|
+ {
|
|
|
+ # /home
|
|
|
+ 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
|
|
|
+ },
|
|
|
+ {
|
|
|
+ # /var
|
|
|
+ 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
|
|
|
+ },
|
|
|
+ {
|
|
|
+ # /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
|
|
|
+ },
|
|
|
+ {
|
|
|
+ # /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
|
|
|
+ },
|
|
|
+ {
|
|
|
+ # /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
|
|
|
+ },
|
|
|
+ {
|
|
|
+ # /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
|
|
|
+ },
|
|
|
+ ]
|
|
|
+
|
|
|
+
|
|
|
+ # Auto scaling group
|
|
|
+ asg_name = "customer-portal-asg"
|
|
|
+ vpc_zone_identifier = [ element(var.subnets,0), element(var.subnets,1), element(var.subnets,2) ]
|
|
|
+ health_check_type = "EC2"
|
|
|
+ min_size = 1
|
|
|
+ max_size = 2
|
|
|
+ desired_capacity = 2
|
|
|
+ wait_for_capacity_timeout = 0
|
|
|
+ tags_as_map = merge(var.standard_tags, var.tags)
|
|
|
}
|
|
|
|
|
|
-resource "aws_acm_certificate_validation" "portal_cert" {
|
|
|
- certificate_arn = aws_acm_certificate.portal_cert.arn
|
|
|
- validation_record_fqdns = [for record in aws_route53_record.portal_cert_validation: record.fqdn]
|
|
|
+
|
|
|
+data "template_file" "cloud-init" {
|
|
|
+ # Should these be in a common directory? I suspect they'd be reusable
|
|
|
+ template = file("${path.module}/cloud-init/cloud-init.tpl")
|
|
|
+
|
|
|
+ vars = {
|
|
|
+ zone = 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
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-resource "aws_route53_record" "portal_cert_validation" {
|
|
|
- provider = 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" {
|
|
|
+ gzip = true
|
|
|
+ base64_encode = true
|
|
|
|
|
|
- for_each = {
|
|
|
- for dvo in aws_acm_certificate.portal_cert.domain_validation_options : dvo.domain_name => {
|
|
|
- name = dvo.resource_record_name
|
|
|
- record = dvo.resource_record_value
|
|
|
- type = dvo.resource_record_type
|
|
|
- }
|
|
|
+ # Main cloud-config configuration file.
|
|
|
+ part {
|
|
|
+ filename = "init.cfg"
|
|
|
+ content_type = "text/cloud-config"
|
|
|
+ content = data.template_file.cloud-init.rendered
|
|
|
}
|
|
|
|
|
|
- allow_overwrite = true
|
|
|
- name = each.value.name
|
|
|
- records = [each.value.record]
|
|
|
- ttl = 60
|
|
|
- type = each.value.type
|
|
|
- zone_id = var.dns_info["public"]["zone_id"]
|
|
|
+ # Additional parts as needed
|
|
|
+ #part {
|
|
|
+ # content_type = "text/x-shellscript"
|
|
|
+ # content = "ffbaz"
|
|
|
+ #}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+#------------------------------------
|
|
|
+# S3 Bucket What is this used for?
|
|
|
+#------------------------------------
|
|
|
+resource "aws_s3_bucket" "customer-portal" {
|
|
|
+ bucket = "dps-customer-portal-${terraform.workspace}"
|
|
|
+ acl = "private"
|
|
|
+
|
|
|
+ tags = merge(var.standard_tags, var.tags, )
|
|
|
+}
|
|
|
+
|
|
|
+#------------------------------------
|
|
|
+# Security Groups
|
|
|
+#------------------------------------
|
|
|
+
|
|
|
+resource "aws_security_group" "customer_portal" {
|
|
|
+ name = "customer_portal_http_inbound_sg"
|
|
|
+ description = "Allow Customer Portal HTTP Inbound From ALB"
|
|
|
+ vpc_id = var.vpc_id
|
|
|
+}
|
|
|
+
|
|
|
+resource "aws_security_group_rule" "customer_portal" {
|
|
|
+ protocol = "tcp"
|
|
|
+ type = "ingress"
|
|
|
+ from_port = 443
|
|
|
+ to_port = 443
|
|
|
+ security_group_id = aws_security_group.customer_portal.id
|
|
|
+ source_security_group_id = aws_security_group.customer_portal_alb.id
|
|
|
+}
|
|
|
+
|
|
|
+resource "aws_security_group" "customer_portal_ecr" {
|
|
|
+ name = "ecr_customer_portal"
|
|
|
+ description = "Allow HTTPS outbound from portal to ECR"
|
|
|
+ vpc_id = var.vpc_id
|
|
|
+}
|
|
|
+
|
|
|
+resource "aws_security_group_rule" "customer_portal_ecr_inbound" {
|
|
|
+ security_group_id = aws_security_group.customer_portal_ecr.id
|
|
|
+
|
|
|
+ type = "ingress"
|
|
|
+ from_port = 443
|
|
|
+ to_port = 443
|
|
|
+ protocol = "tcp"
|
|
|
+ source_security_group_id = aws_security_group.customer_portal.id
|
|
|
+}
|
|
|
+
|
|
|
+resource "aws_security_group_rule" "customer_portal_postgres_outbound" {
|
|
|
+ security_group_id = aws_security_group.customer_portal.id
|
|
|
+
|
|
|
+ type = "egress"
|
|
|
+ from_port = 5432
|
|
|
+ to_port = 5432
|
|
|
+ protocol = "tcp"
|
|
|
+ source_security_group_id = aws_security_group.postgres.id
|
|
|
+}
|
|
|
+
|
|
|
+#resource "aws_security_group_rule" "customer_portal_salt_outbound" {
|
|
|
+# security_group_id = aws_security_group.customer_portal.id
|
|
|
+#
|
|
|
+# type = "egress"
|
|
|
+# from_port = 4505
|
|
|
+# to_port = 4506
|
|
|
+# protocol = "tcp"
|
|
|
+# cidr_blocks = var.salt_master_ip
|
|
|
+#}
|
|
|
+
|
|
|
+#resource "aws_security_group_rule" "customer_portal_gc_salt_outbound" {
|
|
|
+# security_group_id = aws_security_group.customer_portal.id
|
|
|
+#
|
|
|
+# type = "egress"
|
|
|
+# from_port = 4505
|
|
|
+# to_port = 4506
|
|
|
+# protocol = "tcp"
|
|
|
+# cidr_blocks = var.salt_master_ip
|
|
|
+#}
|
|
|
+
|
|
|
+#resource "aws_security_group_rule" "customer_portal_sensu_outbound" {
|
|
|
+# security_group_id = aws_security_group.customer_portal.id
|
|
|
+#
|
|
|
+# type = "egress"
|
|
|
+# from_port = 8081
|
|
|
+# to_port = 8081
|
|
|
+# protocol = "tcp"
|
|
|
+# source_security_group_id = "${data.terraform_remote_state.infra.sensu_servers_sg}"
|
|
|
+#}
|
|
|
+
|
|
|
+resource "aws_security_group_rule" "customer_portal_http_outbound" {
|
|
|
+ security_group_id = aws_security_group.customer_portal.id
|
|
|
+
|
|
|
+ type = "egress"
|
|
|
+ from_port = 80
|
|
|
+ to_port = 80
|
|
|
+ protocol = "tcp"
|
|
|
+ cidr_blocks = ["0.0.0.0/0"]
|
|
|
+}
|
|
|
+
|
|
|
+resource "aws_security_group_rule" "customer_portal_https_outbound" {
|
|
|
+ security_group_id = aws_security_group.customer_portal.id
|
|
|
+
|
|
|
+ type = "egress"
|
|
|
+ from_port = 443
|
|
|
+ to_port = 443
|
|
|
+ protocol = "tcp"
|
|
|
+ cidr_blocks = ["0.0.0.0/0"]
|
|
|
+}
|
|
|
+
|
|
|
+# resource "aws_security_group_rule" "customer_portal_hec_outbound" {
|
|
|
+# security_group_id = aws_security_group.customer_portal.id
|
|
|
+
|
|
|
+# type = "egress"
|
|
|
+# from_port = 8088
|
|
|
+# to_port = 8088
|
|
|
+# protocol = "tcp"
|
|
|
+# cidr_blocks = ["${lookup(local.workspace-default-moose-idx-cidrs,terraform.workspace,"")}"]
|
|
|
+
|
|
|
+# description = "Outbound to Splunk Http Event Collector"
|
|
|
+# }
|
|
|
+
|
|
|
+# resource "aws_security_group_rule" "customer_portal_idxc_outbound" {
|
|
|
+# security_group_id = aws_security_group.customer_portal.id
|
|
|
+
|
|
|
+# type = "egress"
|
|
|
+# from_port = 8089
|
|
|
+# to_port = 8089
|
|
|
+# protocol = "tcp"
|
|
|
+# cidr_blocks = ["10.0.0.0/8"]
|
|
|
+# description = "Outbound IDXC Discovery to MOOSE"
|
|
|
+# }
|
|
|
+
|
|
|
+#resource "aws_security_group_rule" "customer_portal_ssh_inbound" {
|
|
|
+# security_group_id = "${aws_security_group.customer_portal.id}"
|
|
|
+#
|
|
|
+# type = "ingress"
|
|
|
+# from_port = 22
|
|
|
+# to_port = 22
|
|
|
+# protocol = "tcp"
|
|
|
+# cidr_blocks = "${ local.access-server-cidrs[terraform.workspace] }"
|
|
|
+#}
|
|
|
+
|
|
|
+#resource "aws_security_group_rule" "customer_portal_ssh_inbound_openvpn" {
|
|
|
+# security_group_id = "${aws_security_group.customer_portal.id}"
|
|
|
+#
|
|
|
+# type = "ingress"
|
|
|
+# from_port = 22
|
|
|
+# to_port = 22
|
|
|
+# protocol = "tcp"
|
|
|
+# source_security_group_id = "${data.terraform_remote_state.infra.openvpn_servers_sg}"
|
|
|
+#}
|
|
|
+
|
|
|
+#resource "aws_security_group_rule" "customer_portal_outbound_tcp_dns"
|
|
|
+#{
|
|
|
+# type = "egress"
|
|
|
+# from_port = 53
|
|
|
+# to_port = 53
|
|
|
+# protocol = "tcp"
|
|
|
+# cidr_blocks = "${local.dns-server-cidrs[terraform.workspace]}"
|
|
|
+# security_group_id = "${aws_security_group.customer_portal.id}"
|
|
|
+# description = "Connect to unbound servers for dns"
|
|
|
+#}
|
|
|
+
|
|
|
+#resource "aws_security_group_rule" "customer_portal_outbound_udp_dns"
|
|
|
+#{
|
|
|
+# type = "egress"
|
|
|
+# from_port = 53
|
|
|
+# to_port = 53
|
|
|
+# protocol = "udp"
|
|
|
+# cidr_blocks = "${local.dns-server-cidrs[terraform.workspace]}"
|
|
|
+# security_group_id = "${aws_security_group.customer_portal.id}"
|
|
|
+# description = "Connect to unbound servers for dns"
|
|
|
+#}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+### Output environment ID for purposes
|
|
|
+#output portal_env_id {
|
|
|
+# value = "${aws_elastic_beanstalk_environment.mdr-customer-portal-env.id}"
|
|
|
+#}
|
|
|
+
|