-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathiam.tf
51 lines (43 loc) · 1.41 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
data "aws_iam_policy_document" "assume" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["ec2.amazonaws.com"]
}
}
}
resource "aws_iam_role" "this" {
name_prefix = var.name
assume_role_policy = data.aws_iam_policy_document.assume.json
tags = var.tags
lifecycle {
create_before_destroy = true
}
}
data "aws_iam_policy_document" "bucket_access" {
statement {
actions = ["s3:GetObject"]
effect = "Allow"
resources = ["arn:${data.aws_partition.current.partition}:s3:::${var.config_bucket_name}/*"]
}
}
resource "aws_iam_policy" "bucket_access" {
count = var.enable_auto_config && var.create_config_bucket_iam_policy ? 1 : 0
name_prefix = var.name
policy = data.aws_iam_policy_document.bucket_access.json
}
resource "aws_iam_role_policy_attachment" "bucket_access" {
count = var.enable_auto_config && var.create_config_bucket_iam_policy ? 1 : 0
role = aws_iam_role.this.id
policy_arn = aws_iam_policy.bucket_access[0].arn
}
resource "aws_iam_role_policy_attachment" "sdn_access" {
count = var.enable_sdn_access ? 1 : 0
role = aws_iam_role.this.id
policy_arn = "arn:${data.aws_partition.current.partition}:iam::aws:policy/AmazonEC2ReadOnlyAccess"
}
resource "aws_iam_instance_profile" "this" {
name_prefix = var.name
role = aws_iam_role.this.name
}