-
Notifications
You must be signed in to change notification settings - Fork 7
/
secrets.tf
92 lines (75 loc) · 2.67 KB
/
secrets.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
# =============================================
# ECS Task Role
# =============================================
resource "aws_iam_role" "execution_role" {
name = "${var.cluster_name}-execution-role"
path = "/"
assume_role_policy = data.aws_iam_policy_document.execution_assume_role_policy_document.json
# necessary to ensure deletion
force_detach_policies = true
}
data "aws_iam_policy_document" "execution_assume_role_policy_document" {
statement {
actions = [
"sts:AssumeRole",
]
principals {
type = "Service"
identifiers = ["ecs-tasks.amazonaws.com"]
}
}
}
resource "aws_iam_role_policy_attachment" "execution_role_attachment" {
role = aws_iam_role.execution_role.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
}
data "aws_iam_policy_document" "execution_role_secrets_policy" {
statement {
actions = [
"ssm:GetParameters",
"secretsmanager:GetSecretValue",
"kms:Decrypt"
]
resources = [
module.db_password.secret.arn,
module.awx_admin_password.secret.arn,
module.awx_secret_key.secret.arn
]
}
}
resource "aws_iam_role_policy" "execution_role_secrets_policy" {
name = "${var.cluster_name}-execution-role-secrets-policy"
role = aws_iam_role.execution_role.id
policy = data.aws_iam_policy_document.execution_role_secrets_policy.json
}
# =============================================
# ECS ALB SSL Cert
# =============================================
resource "aws_lb_listener_certificate" "awx" {
listener_arn = aws_lb_listener.awx.arn
certificate_arn = var.alb_ssl_certificate_arn
}
# =============================================
# AWX Component Secrets
# =============================================
module "db_password" {
source = "github.com/rhythmictech/terraform-aws-secretsmanager-secret?ref=v0.0.3"
name = "${var.cluster_name}-db-password"
description = "RDS password for AWX ECS cluster ${var.cluster_name}"
value = module.database.this_rds_cluster_master_password
tags = local.common_tags
}
module "awx_secret_key" {
source = "github.com/rhythmictech/terraform-aws-secretsmanager-secret?ref=v0.0.3"
name = "${var.cluster_name}-awx-secret"
description = "AWX secret for ${var.cluster_name}"
value = var.awx_secret_key
tags = local.common_tags
}
module "awx_admin_password" {
source = "github.com/rhythmictech/terraform-aws-secretsmanager-secret?ref=v0.0.3"
name = "${var.cluster_name}-awx-password"
description = "AWX password for ${var.cluster_name}"
value = var.awx_admin_password
tags = local.common_tags
}