generated from Infrastrukturait/terraform-module-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
68 lines (56 loc) · 1.55 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
locals {
username = aws_iam_user.this.name
inline_policies_map = merge(
var.inline_policies_map,
{ for i in var.inline_policies : md5(i) => i }
)
policy_arns_map = merge(
var.policy_arns_map,
{ for i in var.policy_arns : i => i }
)
secret_key_name = "${trimsuffix(var.sm_base_path, "/")}/${local.username}"
}
resource "aws_iam_user" "this" {
name = var.name
path = var.path
force_destroy = var.force_destroy
tags = var.tags
permissions_boundary = var.permissions_boundary
}
resource "aws_iam_access_key" "this" {
count = var.create_iam_access_key ? 1 : 0
user = local.username
}
resource "aws_iam_user_policy" "this" {
for_each = local.inline_policies_map
lifecycle {
create_before_destroy = true
}
user = local.username
policy = each.value
}
resource "aws_iam_user_policy_attachment" "this" {
for_each = local.policy_arns_map
lifecycle {
create_before_destroy = true
}
user = local.username
policy_arn = each.value
}
module "secret_iam" {
source = "Infrastrukturait/secret-manager/aws"
version = "0.2.0"
count = var.sm_enabled ? 1 : 0
name = local.secret_key_name
values = merge(
{
access_key_id = aws_iam_access_key.this[0].id
secret_access_key = aws_iam_access_key.this[0].secret
},
var.sm_ses_smtp_password_enabled ? {
ses_smtp_password_v4 = aws_iam_access_key.this[0].ses_smtp_password_v4
} : {}
)
description = "Access for the ${local.username} user."
tags = var.tags
}