-
Notifications
You must be signed in to change notification settings - Fork 31
/
iam-cross-account-client-roles.tf
55 lines (51 loc) · 1.61 KB
/
iam-cross-account-client-roles.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
/**
* Copyright (C) 2018-2020 Expedia, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
*/
resource "aws_iam_role" "apiary_assume_role" {
count = length(var.apiary_assume_roles)
name = "${local.instance_alias}-${var.apiary_assume_roles[count.index].name}-${var.aws_region}"
max_session_duration = lookup(var.apiary_assume_roles[count.index], "max_role_session_duration_seconds", "3600")
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": [ "${join("\",\"", var.apiary_assume_roles[count.index].principals)}" ]
},
"Action": "sts:AssumeRole"
}
]
}
EOF
tags = var.apiary_tags
}
resource "aws_iam_role_policy" "apiary_assume_role_s3" {
count = length(var.apiary_assume_roles)
name = "s3_access"
role = aws_iam_role.apiary_assume_role[count.index].id
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetBucketLocation",
"s3:GetObject",
"s3:ListBucket",
"s3:PutObject",
"s3:DeleteObject"
],
"Resource": [
"${join("\",\"", [for schema in var.apiary_assume_roles[count.index].schema_names : "arn:aws:s3:::${local.apiary_assume_role_bucket_prefix[count.index]}-${replace(schema, "_", "-")}"])}",
"${join("\",\"", [for schema in var.apiary_assume_roles[count.index].schema_names : "arn:aws:s3:::${local.apiary_assume_role_bucket_prefix[count.index]}-${replace(schema, "_", "-")}/*"])}"
]
}
]
}
EOF
}