forked from cloudposse/terraform-aws-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.tf
32 lines (27 loc) · 803 Bytes
/
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
locals {
ecr_user_enabled = module.this.enabled && var.ecr_user_enabled
}
resource "aws_iam_user" "ecr" {
count = local.ecr_user_enabled ? 1 : 0
name = module.this.id
tags = module.this.tags
}
data "aws_iam_policy_document" "ecr_user" {
count = local.ecr_user_enabled ? 1 : 0
statement {
sid = "ECRGetAuthorizationToken"
effect = "Allow"
actions = ["ecr:GetAuthorizationToken"]
resources = ["*"]
}
}
resource "aws_iam_policy" "ecr_user" {
count = local.ecr_user_enabled ? 1 : 0
name = module.this.id
policy = data.aws_iam_policy_document.ecr_user[0].json
}
resource "aws_iam_user_policy_attachment" "ecr_user" {
count = local.ecr_user_enabled ? 1 : 0
user = aws_iam_user.ecr[0].name
policy_arn = aws_iam_policy.ecr_user[0].arn
}