-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.tf
More file actions
76 lines (64 loc) · 2.11 KB
/
admin.tf
File metadata and controls
76 lines (64 loc) · 2.11 KB
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
module "elastio_asset_account" {
source = "../../"
providers = {
aws = aws.admin
}
depends_on = [
# Needs to wait for the execution role in the asset account to be fully created
aws_iam_role_policy_attachment.execution_deployment,
# Needs to wait for the admin role in the admin account to be fully created
aws_iam_role_policy.admin_execution,
]
template_url = var.template_url
# We are deploying just into a single asset account in this example
accounts = [local.asset_account_id]
administration_role_arn = aws_iam_role.admin.arn
}
# Admin role, that StackSets will use to access the asset accounts to deploy the stacks
resource "aws_iam_role" "admin" {
provider = aws.admin
name = "AWSCloudFormationStackSetAdministrationRole"
# Allow assuming for CFN with some `Condition` elements to prevent the confused deputy attack
# as described in AWS docs: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stacksets-prereqs-self-managed.html#confused-deputy-mitigation
assume_role_policy = jsonencode(
{
"Version" : "2012-10-17",
"Statement" : [
{
"Effect" : "Allow",
"Principal" : {
"Service" : "cloudformation.amazonaws.com"
},
"Action" : "sts:AssumeRole",
"Condition" : {
"StringEquals" : {
"aws:SourceAccount" : local.admin_account_id
},
"StringLike" : {
"aws:SourceArn" : "arn:aws:cloudformation:*:${local.admin_account_id}:stackset/*"
}
}
}
],
}
)
}
resource "aws_iam_role_policy" "admin_execution" {
provider = aws.admin
name = "AssumeExecutionRole"
role = aws_iam_role.admin.name
# Allow assuming the execution role in any (*) account to avoid coupling the
# target accounts with assets with this policy.
policy = jsonencode(
{
"Version" : "2012-10-17",
"Statement" : [
{
"Effect" : "Allow",
"Action" : "sts:AssumeRole",
"Resource" : "arn:aws:iam::*:role/AWSCloudFormationStackSetExecutionRole"
}
]
}
)
}