forked from joshuamkite/terraform-aws-ssh-bastion-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam_child.tf
77 lines (64 loc) · 1.88 KB
/
iam_child.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#role in child account
resource "aws_iam_role" "bastion_service_assume_role" {
name = var.service_name == "bastion-service" ? format(
"%s-%s-%s_bastion",
var.environment_name,
data.aws_region.current.name,
var.vpc,
) : var.service_name
count = local.assume_role_yes
assume_role_policy = data.aws_iam_policy_document.bastion_service_assume_role[0].json
tags = var.tags
}
data "aws_iam_policy_document" "bastion_service_assume_role" {
count = local.assume_role_yes
statement {
actions = [
"sts:AssumeRole",
]
principals {
type = "Service"
identifiers = [
"ec2.amazonaws.com",
]
}
}
}
#Instance profile
resource "aws_iam_instance_profile" "bastion_service_assume_role_profile" {
name = var.service_name == "bastion-service" ? format(
"%s-%s-%s_bastion",
var.environment_name,
data.aws_region.current.name,
var.vpc,
) : var.service_name
count = local.assume_role_yes
role = aws_iam_role.bastion_service_assume_role[0].name
}
data "aws_iam_policy_document" "bastion_service_assume_role_in_parent" {
count = local.assume_role_yes
statement {
effect = "Allow"
actions = [
"sts:AssumeRole",
]
resources = [
var.assume_role_arn,
]
}
}
resource "aws_iam_policy" "bastion_service_assume_role_in_parent" {
count = local.assume_role_yes
name = var.service_name == "bastion-service" ? format(
"%s-%s-%s_bastion",
var.environment_name,
data.aws_region.current.name,
var.vpc,
) : var.service_name
policy = data.aws_iam_policy_document.bastion_service_assume_role_in_parent[0].json
}
resource "aws_iam_role_policy_attachment" "bastion_service_assume_role" {
role = aws_iam_role.bastion_service_assume_role[0].name
count = local.assume_role_yes
policy_arn = aws_iam_policy.bastion_service_assume_role_in_parent[0].arn
}