|
@@ -23,6 +23,7 @@ resource "aws_network_interface" "instance" {
|
|
|
}
|
|
|
|
|
|
resource "aws_eip" "instance" {
|
|
|
+ # checkov:skip=CKV2_AWS_19: EIPs are attached to VPC
|
|
|
vpc = true
|
|
|
tags = merge(local.standard_tags, var.tags, { Name = var.instance_name })
|
|
|
}
|
|
@@ -33,16 +34,23 @@ resource "aws_eip_association" "instance" {
|
|
|
}
|
|
|
|
|
|
resource "aws_instance" "instance" {
|
|
|
- #availability_zone = var.azs[count.index % 2]
|
|
|
+ # availability_zone = var.azs[count.index % 2]
|
|
|
tenancy = "default"
|
|
|
ebs_optimized = true
|
|
|
disable_api_termination = var.instance_termination_protection
|
|
|
instance_initiated_shutdown_behavior = "stop"
|
|
|
instance_type = "t3a.medium"
|
|
|
key_name = "msoc-build"
|
|
|
- monitoring = false
|
|
|
+ monitoring = false # checkov:skip=CKV_AWS_126:Detailed monitoring not needed at this time
|
|
|
iam_instance_profile = "msoc-default-instance-profile"
|
|
|
|
|
|
+ metadata_options {
|
|
|
+ http_endpoint = "enabled"
|
|
|
+ # checkov:skip=CKV_AWS_79:see tfsec explanation
|
|
|
+ # tfsec:ignore:aws-ec2-enforce-http-token-imds Saltstack doesn't use s3 sources appropriately; see https://github.com/saltstack/salt/issues/60668
|
|
|
+ http_tokens = "optional"
|
|
|
+ }
|
|
|
+
|
|
|
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
|
|
@@ -194,6 +202,9 @@ data "template_cloudinit_config" "cloud-init" {
|
|
|
#}
|
|
|
}
|
|
|
|
|
|
+#----------------------------------------------------------------------------
|
|
|
+# Bastion Security Group
|
|
|
+#----------------------------------------------------------------------------
|
|
|
resource "aws_security_group" "bastion_security_group" {
|
|
|
name = "bastion_security_group"
|
|
|
description = "Security Group for Bastion Server(s)"
|
|
@@ -201,8 +212,12 @@ resource "aws_security_group" "bastion_security_group" {
|
|
|
tags = merge(local.standard_tags, var.tags)
|
|
|
}
|
|
|
|
|
|
+#----------------------------------------------------------------------------
|
|
|
+# INGRESS
|
|
|
+#----------------------------------------------------------------------------
|
|
|
resource "aws_security_group_rule" "ssh-in" {
|
|
|
type = "ingress"
|
|
|
+ description = "SSH - Inbound"
|
|
|
from_port = 22
|
|
|
to_port = 22
|
|
|
protocol = "tcp"
|
|
@@ -233,6 +248,7 @@ resource "aws_security_group_rule" "ssh-in" {
|
|
|
|
|
|
resource "aws_security_group_rule" "ssh-out" {
|
|
|
type = "egress"
|
|
|
+ description = "SSH - Outbound"
|
|
|
from_port = 22
|
|
|
to_port = 22
|
|
|
protocol = "tcp"
|
|
@@ -240,9 +256,13 @@ resource "aws_security_group_rule" "ssh-out" {
|
|
|
security_group_id = aws_security_group.bastion_security_group.id
|
|
|
}
|
|
|
|
|
|
+#----------------------------------------------------------------------------
|
|
|
+# EGRESS
|
|
|
+#----------------------------------------------------------------------------
|
|
|
# Bastion can access any port internally
|
|
|
resource "aws_security_group_rule" "bastion-out-all-ports" {
|
|
|
type = "egress"
|
|
|
+ description = "Bastion can access any port internally - Outbound"
|
|
|
protocol = "all"
|
|
|
from_port = -1
|
|
|
to_port = -1
|
|
@@ -253,18 +273,20 @@ resource "aws_security_group_rule" "bastion-out-all-ports" {
|
|
|
# Bastion gets http/https out to the internet. Most hosts need to use the proxy
|
|
|
resource "aws_security_group_rule" "http-out" {
|
|
|
type = "egress"
|
|
|
+ description = "Bastion HTTP - Outbound"
|
|
|
from_port = 80
|
|
|
to_port = 80
|
|
|
protocol = "tcp"
|
|
|
- cidr_blocks = ["0.0.0.0/0"] #tfsec:ignore:aws-vpc-no-public-egress-sgr
|
|
|
+ cidr_blocks = ["0.0.0.0/0"] # tfsec:ignore:aws-vpc-no-public-egress-sgr
|
|
|
security_group_id = aws_security_group.bastion_security_group.id
|
|
|
}
|
|
|
|
|
|
resource "aws_security_group_rule" "https-out" {
|
|
|
type = "egress"
|
|
|
+ description = "Bastion HTTPS - Outbound"
|
|
|
from_port = 443
|
|
|
to_port = 443
|
|
|
protocol = "tcp"
|
|
|
- cidr_blocks = ["0.0.0.0/0"] #tfsec:ignore:aws-vpc-no-public-egress-sgr
|
|
|
+ cidr_blocks = ["0.0.0.0/0"] # tfsec:ignore:aws-vpc-no-public-egress-sgr
|
|
|
security_group_id = aws_security_group.bastion_security_group.id
|
|
|
}
|