-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam.tf
64 lines (50 loc) · 1.61 KB
/
iam.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
# --- TRUST RELATIONSHIPS ---
# Amplify Trust Relationship
data "aws_iam_policy_document" "amplify_trust_relationship" {
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["amplify.amazonaws.com"]
}
}
}
# --- IAM ROLES ---
# Amplify
resource "aws_iam_role" "amplify_codecommit" {
# count = var.create_codecommit_repo ? 1 : 0
count = var.create_codecommit_repo ? 1 : 0
name = "${var.amplify_codecommit_role_name}-${var.app_name}"
assume_role_policy = data.aws_iam_policy_document.amplify_trust_relationship.json
managed_policy_arns = ["arn:aws:iam::aws:policy/AWSCodeCommitReadOnly"]
}
# GitLab
resource "aws_iam_user" "gitlab_mirroring" {
count = var.enable_gitlab_mirroring ? 1 : 0
name = var.gitlab_mirroring_iam_user_name != null ? var.gitlab_mirroring_iam_user_name : "gitlab-mirroring"
path = "/${var.app_name}/"
force_destroy = true // prevents DeleteConflict Error
tags = merge(
{
"AppName" = var.app_name
},
var.tags,
)
}
resource "aws_iam_user_policy" "gitlab_mirroring_policy" {
count = var.enable_gitlab_mirroring ? 1 : 0
name = var.gitlab_mirroring_policy_name
user = aws_iam_user.gitlab_mirroring[0].name
policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Sid = "MinimumGitLabMirroringPermissions"
Action = ["codecommit:GitPull", "codecommit:GitPush"]
Effect = "Allow"
Resource = [
"${aws_codecommit_repository.codecommit_repo[0].arn}"
]
}]
})
}