-
Notifications
You must be signed in to change notification settings - Fork 17
/
main.tf
74 lines (62 loc) · 2.34 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
# Managed By : CloudDrove
# Description : Terraform module to create IAM user resource on AWS.
# Copyright @ CloudDrove. All Right Reserved.
#Module : label
#Description : This terraform module is designed to generate consistent label names and tags
# for resources. You can use terraform-labels to implement a strict naming
# convention.
module "labels" {
source = "clouddrove/labels/aws"
version = "1.3.0"
name = var.name
environment = var.environment
repository = var.repository
managedby = var.managedby
attributes = var.attributes
label_order = var.label_order
}
# Module : IAM user
# Description : Terraform module to create IAm user resource on AWS.
resource "aws_iam_user" "default" {
count = var.enabled ? 1 : 0
name = module.labels.id
force_destroy = var.force_destroy
path = var.path
permissions_boundary = var.permissions_boundary
tags = module.labels.tags
}
resource "aws_iam_access_key" "default" {
count = var.enabled ? 1 : 0
user = aws_iam_user.default.*.name[0]
pgp_key = var.pgp_key
status = var.status
}
resource "aws_iam_user_policy" "default" {
count = var.enabled && var.policy_enabled && var.policy_arn == "" ? 1 : 0
name = format("%s-policy", module.labels.id)
user = aws_iam_user.default.*.name[0]
policy = var.policy
}
resource "aws_iam_user_policy_attachment" "default" {
count = var.enabled && var.policy_enabled && var.policy_arn != "" ? 1 : 0
user = aws_iam_user.default.*.name[0]
policy_arn = var.policy_arn
}
resource "aws_iam_user_group_membership" "default" {
count = var.enabled && length(var.groups) > 0 ? 1 : 0
user = aws_iam_user.default[count.index].name
groups = var.groups
depends_on = [aws_iam_user.default]
}
resource "aws_iam_user_login_profile" "default" {
count = var.create_user && var.create_iam_user_login_profile ? 1 : 0
user = aws_iam_user.default[0].name
password_length = var.password_length
password_reset_required = var.password_reset_required
}
resource "aws_iam_user_ssh_key" "default" {
count = var.create_user && var.upload_iam_user_ssh_key ? 1 : 0
username = aws_iam_user.default[0].name
encoding = var.ssh_key_encoding
public_key = var.ssh_public_key
}