-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam.tf
60 lines (52 loc) · 1.91 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
data "aws_iam_policy_document" "lambda" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = [
"lambda.amazonaws.com",
"edgelambda.amazonaws.com"
]
}
}
}
resource "aws_iam_role" "main" {
name_prefix = "${var.bucket_name}"
assume_role_policy = "${data.aws_iam_policy_document.lambda.json}"
}
resource "aws_iam_role_policy_attachment" "basic" {
role = "${aws_iam_role.main.name}"
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}
###############################################################################
## Configure website bucket policy
###############################################################################
data "template_file" "bucket_policy" {
template = "${file("${path.module}/website_bucket_policy.json")}"
vars {
bucket = "${var.bucket_name}"
secret = "${var.duplicate-content-penalty-secret}"
}
}
###############################################################################
## Configure the credentials and access to the bucket for a deployment user
###############################################################################
data "template_file" "deployer_role_policy_file" {
template = "${file("${path.module}/deployer_role_policy.json")}"
vars {
bucket = "${var.bucket_name}"
}
}
resource "aws_iam_policy" "site_deployer_policy" {
provider = "aws.${var.region}"
name = "${var.bucket_name}.deployer"
path = "/"
description = "Policy allowing to publish a new version of the website to the S3 bucket"
policy = "${data.template_file.deployer_role_policy_file.rendered}"
}
resource "aws_iam_policy_attachment" "site-deployer-attach-user-policy" {
provider = "aws.${var.region}"
name = "${var.bucket_name}-deployer-policy-attachment"
users = ["${var.deployer}"]
policy_arn = "${aws_iam_policy.site_deployer_policy.arn}"
}