-
Notifications
You must be signed in to change notification settings - Fork 4
/
debiandesktop_ec2.tf
94 lines (85 loc) · 3.06 KB
/
debiandesktop_ec2.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# The Debian AMI, which we use for our "Debian desktop" instances
data "aws_ami" "debiandesktop" {
provider = aws.provisionassessment
most_recent = true
owners = [local.images_account_id]
filter {
name = "architecture"
values = ["arm64"]
}
filter {
name = "name"
values = [
"debian-hvm-*-arm64-ebs"
]
}
filter {
name = "root-device-type"
values = ["ebs"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
}
# The "Debian desktop" EC2 instances
resource "aws_instance" "debiandesktop" {
count = lookup(var.operations_instance_counts, "debiandesktop", 0)
# These instances require the EFS mount target to be present in
# order to mount the EFS volume at boot time.
depends_on = [
aws_efs_mount_target.target,
aws_security_group_rule.allow_nfs_inbound,
aws_security_group_rule.allow_nfs_outbound,
]
provider = aws.provisionassessment
ami = data.aws_ami.debiandesktop.id
associate_public_ip_address = true
iam_instance_profile = aws_iam_instance_profile.debiandesktop.name
instance_type = "t4g.medium"
# AWS Instance Meta-Data Service (IMDS) options
metadata_options {
# Enable IMDS (this is the default value)
http_endpoint = "enabled"
# Restrict put responses from IMDS to a single hop (this is the
# default value). This effectively disallows the retrieval of an
# IMDSv2 token via this machine from anywhere else.
http_put_response_hop_limit = 1
# Require IMDS tokens AKA require the use of IMDSv2
http_tokens = "required"
}
root_block_device {
volume_size = 128
volume_type = "gp3"
}
subnet_id = aws_subnet.operations.id
tags = {
Name = format("DebianDesktop%d", count.index)
"Publish Egress" = var.publish_egress_ip_addresses
}
user_data_base64 = data.cloudinit_config.debiandesktop_cloud_init_tasks[count.index].rendered
# volume_tags does not yet inherit the default tags from the
# provider. See hashicorp/terraform-provider-aws#19188 for more
# details.
volume_tags = merge(data.aws_default_tags.assessment.tags, {
Name = format("DebianDesktop%d", count.index)
})
vpc_security_group_ids = [
aws_security_group.cloudwatch_agent_endpoint_client.id,
aws_security_group.debiandesktop.id,
aws_security_group.efs_client.id,
aws_security_group.guacamole_accessible.id,
aws_security_group.ssm_agent_endpoint_client.id,
]
}
# CloudWatch alarms for the Debian Desktop instances
module "cw_alarms_debiandesktop" {
providers = {
aws = aws.provisionassessment
}
source = "github.com/cisagov/instance-cw-alarms-tf-module"
alarm_actions = [data.terraform_remote_state.dynamic_assessment.outputs.cw_alarm_sns_topic.arn]
instance_ids = [for instance in aws_instance.debiandesktop : instance.id]
insufficient_data_actions = [data.terraform_remote_state.dynamic_assessment.outputs.cw_alarm_sns_topic.arn]
ok_actions = [data.terraform_remote_state.dynamic_assessment.outputs.cw_alarm_sns_topic.arn]
}