-
Notifications
You must be signed in to change notification settings - Fork 0
/
console.tf
158 lines (132 loc) · 3.77 KB
/
console.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
locals {
console_services = ["cloudwatch", "ec2", "ecr", "ecs", "efs", "iam", "lambda", "rds", "route53", "servicediscovery", "vpc"]
}
data "aws_iam_policy_document" "nurax_console" {
statement {
effect = "Allow"
actions = [
"s3:*",
]
resources = [
"${aws_s3_bucket.fedora_binaries.arn}",
"${aws_s3_bucket.fedora_binaries.arn}/*"
]
}
statement {
effect = "Allow"
actions = ["ecr:GetAuthorizationToken"]
resources = [ "*" ]
}
statement {
effect = "Allow"
actions = [for service in local.console_services: "${service}:*"]
resources = [ "*" ]
# condition {
# test = "StringEquals"
# variable = "aws:ResourceTag/Namespace"
# values = [var.namespace]
# }
}
}
resource "aws_iam_policy" "nurax_console_policy" {
name = "${var.namespace}-console"
policy = data.aws_iam_policy_document.nurax_console.json
}
resource "aws_iam_role" "nurax_console_role" {
name = "${var.namespace}-console"
assume_role_policy = jsonencode({
Version = "2008-10-17"
Statement = [
{
Sid = ""
Effect = "Allow"
Principal = {
Service = "ec2.amazonaws.com"
}
Action = "sts:AssumeRole"
}
]
})
}
resource "aws_iam_role_policy_attachment" "nurax_console_task_policy" {
role = aws_iam_role.nurax_console_role.id
policy_arn = aws_iam_policy.nurax_role_policy.arn
}
resource "aws_iam_role_policy_attachment" "nurax_console_admin_policy" {
role = aws_iam_role.nurax_console_role.id
policy_arn = aws_iam_policy.nurax_console_policy.arn
}
resource "aws_iam_instance_profile" "console_instance_profile" {
name = "${var.namespace}-console-profile"
role = aws_iam_role.nurax_console_role.name
}
resource "aws_security_group" "nurax_console" {
name = "${var.namespace}-console"
vpc_id = module.vpc.vpc_id
}
data "aws_ami" "nurax_console" {
owners = [136693071363]
most_recent = true
filter {
name = "name"
values = ["debian-11-*"]
}
filter {
name = "architecture"
values = ["x86_64"]
}
filter {
name = "root-device-type"
values = ["ebs"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
}
resource "random_shuffle" "az" {
input = module.vpc.public_subnets
result_count = 1
}
data "aws_subnet" "nurax_console_subnet" {
id = random_shuffle.az.result[0]
}
resource "aws_instance" "nurax_console" {
ami = data.aws_ami.nurax_console.id
instance_type = "t3a.large"
key_name = "nurax"
disable_api_termination = true
instance_initiated_shutdown_behavior = "stop"
availability_zone = data.aws_subnet.nurax_console_subnet.availability_zone
subnet_id = data.aws_subnet.nurax_console_subnet.id
iam_instance_profile = aws_iam_instance_profile.console_instance_profile.name
associate_public_ip_address = true
vpc_security_group_ids = [
module.vpc.default_security_group_id,
aws_security_group.nurax_console.id,
aws_security_group.nurax.id,
aws_security_group.ssh.id,
]
ebs_block_device {
device_name = "/dev/xvda"
encrypted = false
delete_on_termination = true
volume_size = 50
volume_type = "gp3"
throughput = 125
}
user_data = templatefile(
"${path.module}/support/console-init.sh",
{
console_users = join(" ", var.console_users)
stack_efs_id = aws_efs_file_system.samvera_stack_data_volume.id
nurax_efs_id = aws_efs_file_system.nurax_data_volume.id
}
)
lifecycle {
ignore_changes = [ user_data, associate_public_ip_address ]
}
tags = {
Name = "${var.namespace}-console"
}
}