Repository navigation
Expand file tree
/
Copy pathiam-ec2.tf
More file actions
61 lines (57 loc) · 1.37 KB
/
Copy pathiam-ec2.tf
File metadata and controls
61 lines (57 loc) · 1.37 KB
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
# creating the ec2 role, this will be used to connect our NExtcloud to S3 bucket
resource "aws_iam_role" "nexcloud_ec2_role" {
name = "nexcloud-ec2-role"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Effect": "Allow"
}
]
}
EOF
tags = {
tag-key = "nexcloud-ec2-role"
}
}
# Creating ec2 iam profile and assigned it to our ec2 role
# we gave this profile
resource "aws_iam_instance_profile" "nexcloud-ec2-profile" {
name = "nexctloud-ec2-profile"
role = "${aws_iam_role.nexcloud_ec2_role.name}"
}
# Giving ec2 right to access s3
resource "aws_iam_role_policy" "nexcloud-ec2-policy" {
name = "nexcloud-ec2-policy"
role = "${aws_iam_role.nexcloud_ec2_role.name}"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"s3:PutAccountPublicAccessBlock",
"s3:GetAccountPublicAccessBlock",
"s3:ListAllMyBuckets",
"cloudwatch:*",
"s3:HeadBucket"
],
"Resource": "*"
},
{
"Sid": "VisualEditor1",
"Effect": "Allow",
"Action": "s3:*",
"Resource": "arn:aws:s3:::nextcloudtestbucket1112222"
}
]
}
EOF
}