forked from expel-io/terraform-aws-eks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam.tf
77 lines (69 loc) · 2.43 KB
/
iam.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
77
# This Terraform file defines IAM roles and policies for an AWS EKS cluster.
# This data block defines an IAM policy document that allows Expel to assume the role.
data "aws_iam_policy_document" "assume_role_iam_document" {
# Allow Expel to assume the role
statement {
actions = ["sts:AssumeRole"]
effect = "Allow"
principals {
type = "AWS"
identifiers = [var.expel_aws_account_arn]
}
condition {
test = "StringEquals"
variable = "sts:ExternalId"
values = [var.expel_customer_organization_guid]
}
}
}
# This resource block defines an IAM role for Expel to assume.
resource "aws_iam_role" "expel_assume_role" {
name = "ExpelServiceAssumeRole"
assume_role_policy = data.aws_iam_policy_document.assume_role_iam_document.json
tags = local.tags
}
# This resource block attaches an IAM policy to the Expel assume role.
resource "aws_iam_role_policy_attachment" "eks_consumer_policy_attachment" {
role = aws_iam_role.expel_assume_role.name
policy_arn = aws_iam_policy.eks_consumer_policy.arn
}
# This resource block defines an IAM policy for Expel to access and manage EKS resources.
resource "aws_iam_policy" "eks_consumer_policy" {
name = "${var.prefix}-eks-consumer-policy"
policy = data.aws_iam_policy_document.eks_consumer_iam_document.json
tags = local.tags
}
# This data block defines an IAM policy document that allows Expel Workbench to access and manage Kinesis and EKS resources.
# Note: The policies with wildcards are ignored by tfsec.
#tfsec:ignore:aws-iam-no-policy-wildcards
data "aws_iam_policy_document" "eks_consumer_iam_document" {
# Allow Expel Workbench to retrieve data from Kinesis
statement {
actions = [
"kinesis:DescribeLimits",
"kinesis:DescribeStream",
"kinesis:DescribeStreamSummary",
"kinesis:GetRecords",
"kinesis:GetShardIterator",
"kinesis:ListShards"
]
resources = [aws_kinesis_stream.kinesis_data_stream.arn]
effect = "Allow"
}
# Allow Expel Workbench to gather information about EKS clusters
statement {
actions = [
"eks:AccessKubernetesApi",
"eks:DescribeCluster",
"eks:DescribeNodegroup",
"eks:ListClusters",
"eks:ListNodegroups",
"eks:ListUpdates",
"sts:GetCallerIdentity",
"ec2:DescribeRegions",
"autoscaling:DescribeAutoScalingGroups"
]
resources = ["*"]
effect = "Allow"
}
}