-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathturbo-aws-setup.tf
158 lines (132 loc) · 3.12 KB
/
turbo-aws-setup.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
provider "aws" {
access_key = "${var.aws_access_key}"
secret_key = "${var.aws_secret_key}"
region = "${var.aws_region}"
}
resource "aws_iam_access_key" "lb" {
user = "${aws_iam_user.lb.name}"
}
resource "aws_iam_user" "lb" {
name = "${var.user_name}"
}
resource "aws_iam_group_membership" "turbo_access_group" {
name = "turbonomic-access-group-membership"
users = [
"${aws_iam_user.lb.name}",
]
group = "${var.rw_user == "1" ? aws_iam_group.turbo_rw_group.name : aws_iam_group.turbo_ro_group.name}"
}
resource "aws_iam_group_policy" "lb_rw" {
name = "TurbonomicRWIAMPolicy"
policy = "${file("TurboRWGroupPolicy.json")}"
group = "${aws_iam_group.turbo_rw_group.id}"
}
resource "aws_iam_group_policy" "lb_ro" {
name = "TurbonomicROIAMPolicy"
policy = "${file("TurboROGroupPolicy.json")}"
group = "${aws_iam_group.turbo_ro_group.id}"
}
resource "aws_iam_group" "turbo_rw_group" {
name = "TurbonomicRWgroup"
path = "/"
}
resource "aws_iam_group" "turbo_ro_group" {
name = "TurbonomicROgroup"
path = "/"
}
output "group_applied" {
value = "${aws_iam_group_membership.turbo_access_group.group}"
}
output "user_applied" {
value = "${aws_iam_user.lb.name}"
}
output "user_access_key" {
value = "${aws_iam_access_key.lb.id}"
}
output "user_secret" {
value = "${aws_iam_access_key.lb.secret}"
sensitive = true
}
output "user_arn" {
value = "${aws_iam_user.lb.arn}"
}
resource "aws_s3_bucket" "bucket" {
bucket = "${var.bucket_name}"
}
resource "aws_s3_bucket_acl" "bucket_acl" {
bucket = aws_s3_bucket.bucket.id
acl = "private"
}
resource "aws_s3_bucket_cors_configuration" "bucket_cors" {
bucket = aws_s3_bucket.bucket.id
cors_rule {
allowed_headers = ["Authorization"]
allowed_methods = ["GET"]
allowed_origins = ["*"]
max_age_seconds = 3000
}
}
resource "aws_s3_bucket_policy" "bucket_policy_from_another" {
bucket = aws_s3_bucket.bucket.id
policy = data.aws_iam_policy_document.allow_access_from_another_account.json
}
data "aws_iam_policy_document" "allow_access_from_another_account" {
statement {
principals {
type = "AWS"
identifiers = [
"${aws_iam_user.lb.arn}",
"386209384616"
]
}
actions = [
"s3:GetBucketAcl",
"s3:GetBucketPolicy",
"s3:PutObject"
]
resources = [
aws_s3_bucket.bucket.arn,
"${aws_s3_bucket.bucket.arn}/*"
]
}
}
/*
policy = <<POLICY
{
"Version": "2008-10-17",
"Id": "TurboPolicyCUR",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "${aws_iam_user.lb.arn}",
"AWS": "386209384616"
},
"Action": [
"s3:GetBucketAcl",
"s3:GetBucketPolicy"
],
"Resource": "arn:aws:s3:::${var.bucket_name}"
},
{
"Effect": "Allow",
"Principal": {
"AWS": "${aws_iam_user.lb.arn}",
"AWS": "386209384616"
},
"Action": [
"s3:PutObject"
],
"Resource": "arn:aws:s3:::${var.bucket_name}/*"
}
]
}
POLICY
}
*/
output "s3_cur_bucket_name" {
value = "${var.bucket_name}"
}
output "s3_cur_bucket_path" {
value = "/"
}