forked from hadenlabs/terraform-aws-iam-user
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
110 lines (93 loc) · 2.61 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
locals {
defaults = {
password_reset_required = false
path = "/"
}
input = {
username = var.username
first_name = var.first_name
path = try(var.path, local.defaults.path)
public_key = var.public_key
password_reset_required = try(var.password_reset_required, local.defaults.password_reset_required)
}
generated = {
username = local.input.username
first_name = local.input.first_name
path = local.input.path
public_key = local.input.public_key
password_reset_required = local.input.password_reset_required
}
outputs = {
username = local.generated.username
first_name = local.generated.first_name
path = local.generated.path
public_key = local.generated.public_key
password_reset_required = local.generated.password_reset_required
}
}
resource "aws_iam_user" "this" {
name = local.outputs.username
path = local.outputs.path
force_destroy = true
tags = {
managed-by = "Terraform"
Name = local.outputs.username
}
}
resource "aws_iam_access_key" "this" {
depends_on = [
aws_iam_user.this
]
user = aws_iam_user.this.name
}
resource "aws_iam_user_ssh_key" "this" {
depends_on = [
aws_iam_user.this
]
username = aws_iam_user.this.name
encoding = "SSH"
public_key = local.outputs.public_key
}
resource "aws_iam_policy" "mfa" {
depends_on = [
aws_iam_user.this
]
policy = data.aws_iam_policy_document.enforce_mfa_device.json
}
resource "aws_iam_policy" "password" {
depends_on = [
aws_iam_user.this
]
policy = data.aws_iam_policy_document.password.json
}
resource "aws_iam_policy" "access_key" {
depends_on = [
aws_iam_user.this
]
policy = data.aws_iam_policy_document.access_key.json
}
# Avoid this for Reducing access management complexity
resource "aws_iam_user_policy_attachment" "mfa" {
depends_on = [
aws_iam_user.this
]
user = aws_iam_user.this.name
# checkov:skip=CKV_AWS_40: Avoid this
policy_arn = aws_iam_policy.mfa.arn
}
resource "aws_iam_user_policy_attachment" "password" {
depends_on = [
aws_iam_user.this
]
user = aws_iam_user.this.name
# checkov:skip=CKV_AWS_40: Avoid this
policy_arn = aws_iam_policy.password.arn
}
resource "aws_iam_user_policy_attachment" "access_key" {
depends_on = [
aws_iam_user.this
]
user = aws_iam_user.this.name
# checkov:skip=CKV_AWS_40: Avoid this
policy_arn = aws_iam_policy.access_key.arn
}