This repository has been archived by the owner on Jan 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.tf
98 lines (81 loc) · 2.35 KB
/
main.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
module "label" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.3"
namespace = "${var.namespace}"
stage = "${var.stage}"
name = "${var.name}"
delimiter = "${var.delimiter}"
attributes = "${var.attributes}"
tags = "${var.tags}"
}
module "kops_metadata" {
source = "git::https://github.com/cloudposse/terraform-aws-kops-data-iam.git?ref=tags/0.1.0"
cluster_name = "${var.cluster_name}"
}
resource "aws_s3_bucket" "default" {
bucket = "${module.label.id}"
acl = "private"
force_destroy = false
tags = "${module.label.tags}"
versioning {
enabled = true
}
server_side_encryption_configuration {
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
}
data "aws_iam_policy_document" "default" {
statement {
actions = ["s3:ListBucket"]
resources = ["*"]
}
statement {
actions = [
"s3:DeleteObject",
"s3:GetObject",
"s3:PutObject",
]
resources = ["${aws_s3_bucket.default.arn}/*"]
}
}
resource "aws_iam_policy" "default" {
name = "${module.label.id}"
policy = "${data.aws_iam_policy_document.default.json}"
description = "Allow Kops nodes to get/put/delete objects from the chart repo S3 bucket"
}
locals {
arns = {
masters = ["${module.kops_metadata.masters_role_arn}"]
nodes = ["${module.kops_metadata.nodes_role_arn}"]
both = ["${module.kops_metadata.masters_role_arn}", "${module.kops_metadata.nodes_role_arn}"]
}
}
data "aws_iam_policy_document" "role_trust" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["ec2.amazonaws.com"]
}
}
statement {
actions = ["sts:AssumeRole"]
principals {
type = "AWS"
identifiers = ["${local.arns[var.permitted_nodes]}"]
}
}
}
resource "aws_iam_role" "default" {
name = "${module.label.id}"
assume_role_policy = "${data.aws_iam_policy_document.role_trust.json}"
description = "Allow Kops nodes to get/put/delete objects from the chart repo S3 bucket"
max_session_duration = "${var.iam_role_max_session_duration}"
}
resource "aws_iam_role_policy_attachment" "default" {
role = "${aws_iam_role.default.name}"
policy_arn = "${aws_iam_policy.default.arn}"
}