-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.tf
More file actions
71 lines (57 loc) · 1.91 KB
/
admin.tf
File metadata and controls
71 lines (57 loc) · 1.91 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
module "elastio_asset_accounts" {
# Use the link from the real terraform registry here. Relative path is used for testing purposes.
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.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
assume_role_policy = data.aws_iam_policy_document.admin_trust.json
name = "AWSCloudFormationStackSetAdministrationRole"
}
data "aws_iam_policy_document" "admin_trust" {
statement {
actions = ["sts:AssumeRole"]
effect = "Allow"
principals {
identifiers = ["cloudformation.amazonaws.com"]
type = "Service"
}
# Conditions to prevent the confused deputy attack
condition {
test = "StringEquals"
variable = "aws:SourceAccount"
values = [local.admin_account_id]
}
condition {
test = "StringLike"
variable = "aws:SourceArn"
values = ["arn:aws:cloudformation:*:${local.admin_account_id}:stackset/*"]
}
}
}
data "aws_iam_policy_document" "admin_execution" {
statement {
actions = ["sts:AssumeRole"]
effect = "Allow"
resources = ["arn:aws:iam::*:role/AWSCloudFormationStackSetExecutionRole"]
}
}
resource "aws_iam_role_policy" "admin_execution" {
provider = aws.admin
name = "AssumeExecutionRole"
policy = data.aws_iam_policy_document.admin_execution.json
role = aws_iam_role.admin.name
}