-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathmain.tf
121 lines (101 loc) · 3.22 KB
/
main.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
#################################################
# AWS Authentication
#################################################
resource "vault_auth_backend" "aws" {
type = "aws"
path = var.aws_auth_path
}
resource "vault_aws_auth_backend_role" "consul" {
backend = vault_auth_backend.aws.path
role = var.consul_role
auth_type = "ec2"
bound_iam_role_arns = [var.consul_iam_role_arn]
token_policies = setunion(var.base_policies, var.consul_policies)
token_period = var.period_minutes
}
resource "vault_aws_auth_backend_role" "nomad_server" {
backend = vault_auth_backend.aws.path
role = var.nomad_server_role
auth_type = "ec2"
bound_iam_role_arns = [var.nomad_server_iam_role_arn]
token_policies = setunion(var.base_policies, var.nomad_server_policies)
token_period = var.period_minutes
}
resource "vault_aws_auth_backend_role" "nomad_client" {
backend = vault_auth_backend.aws.path
role = var.nomad_client_role
auth_type = "ec2"
bound_iam_role_arns = [var.nomad_client_iam_role_arn]
token_policies = setunion(var.base_policies, var.nomad_client_policies)
token_period = var.period_minutes
}
resource "vault_aws_auth_backend_role" "vault" {
backend = vault_auth_backend.aws.path
role = var.vault_role
auth_type = "ec2"
bound_iam_role_arns = [var.vault_iam_role_arn]
token_policies = setunion(var.base_policies, var.vault_policies)
token_period = var.period_minutes
}
################################################
# Mark in Consul for the `core` module scripts to configure themselves
################################################
resource "consul_keys" "enabled" {
count = var.core_integration ? 1 : 0
key {
path = "${var.consul_key_prefix}aws-auth/enabled"
value = "yes"
delete = true
}
}
resource "consul_keys" "path" {
count = var.core_integration ? 1 : 0
key {
path = "${var.consul_key_prefix}aws-auth/path"
value = vault_auth_backend.aws.path
delete = true
}
}
resource "consul_keys" "readme" {
count = var.core_integration ? 1 : 0
key {
path = "${var.consul_key_prefix}aws-auth/README"
value = <<EOF
This is used for integration with the `core` module.
See https://github.com/GovTechSG/terraform-modules/tree/master/modules/aws-auth
EOF
delete = true
}
}
resource "consul_keys" "consul" {
count = var.core_integration ? 1 : 0
key {
path = "${var.consul_key_prefix}aws-auth/roles/consul"
value = var.consul_role
delete = true
}
}
resource "consul_keys" "nomad_server" {
count = var.core_integration ? 1 : 0
key {
path = "${var.consul_key_prefix}aws-auth/roles/nomad_server"
value = var.nomad_server_role
delete = true
}
}
resource "consul_keys" "nomad_client" {
count = var.core_integration ? 1 : 0
key {
path = "${var.consul_key_prefix}aws-auth/roles/nomad_client"
value = var.nomad_client_role
delete = true
}
}
resource "consul_keys" "vault" {
count = var.core_integration ? 1 : 0
key {
path = "${var.consul_key_prefix}aws-auth/roles/vault"
value = var.vault_role
delete = true
}
}