-
Notifications
You must be signed in to change notification settings - Fork 0
/
external-user.tf
57 lines (48 loc) · 1.64 KB
/
external-user.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
# ACME DNS challenge requires ACCESS_ and SECRET_KEY if hosted zone is in an external AWS Account
# The created IAM user is responsible to manage the dns validation record
# Alternative would be to use a custom AWS_PROFILE but it does not seem to be accepted either
module "iam_label" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.15.0"
context = module.label.context
attributes = [local.region]
}
data "aws_iam_policy_document" "dns_change" {
count = var.external_account && var.enabled ? 1 : 0
statement {
effect = "Allow"
actions = [
"route53:GetChange",
"route53:ChangeResourceRecordSets",
"route53:ListResourceRecordSets",
]
resources = [
"arn:aws:route53:::hostedzone/${data.aws_route53_zone.validation.zone_id}",
"arn:aws:route53:::change/*",
]
}
}
resource "aws_iam_user" "dns_user" {
count = var.external_account && var.enabled ? 1 : 0
name = module.iam_label.id
tags = module.iam_label.tags
path = "/service/"
}
resource "aws_iam_user_policy" "attachment" {
count = var.external_account && var.enabled ? 1 : 0
name = module.iam_label.id
user = join("", aws_iam_user.dns_user.*.name)
policy = join("", data.aws_iam_policy_document.dns_change.*.json)
}
resource "aws_iam_access_key" "dns_user" {
count = var.external_account && var.enabled ? 1 : 0
user = join("", aws_iam_user.dns_user.*.name)
}
resource "null_resource" "await_access" {
count = var.external_account && var.enabled ? 1 : 0
provisioner "local-exec" {
command = "sleep 30"
}
triggers = {
user = join("", aws_iam_access_key.dns_user.*.id)
}
}