-
Notifications
You must be signed in to change notification settings - Fork 16
/
main.tf
108 lines (93 loc) · 2.92 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
99
100
101
102
103
104
105
106
107
/**
* AWS S3 Bucket Terraform Module
* =====================
*
* Create multiple AWS S3 buckets and set policies
*
* Usage:
* ------
* '''hcl
* module "s3-bucket" {
* source = "../s3-bucket"
* names = ["images","thumbnails"]
* environment = "dev"
* org = "corp"
* }
* '''
**/
# TODO: Allow pass policy via variable. Default empty policy. If can be done, otherwise 2 modules
# create s3 bucket and set policy
# TODO: setup encryption
# https://www.terraform.io/docs/providers/aws/r/aws_s3_bucket.html
# https://www.terraform.io/docs/providers/aws/r/aws_s3_bucket_policy.html
# https://www.terraform.io/docs/providers/aws/r/aws_s3_bucket_notification.html
# https://www.terraform.io/docs/providers/aws/r/aws_s3_bucket_object.html
module "enabled" {
source = "devops-workflow/boolean/local"
version = "0.1.1"
value = "${var.enabled}"
}
module "labels" {
source = "devops-workflow/labels/null"
version = "0.1.0"
attributes = "${var.attributes}"
component = "${var.component}"
delimiter = "${var.delimiter}"
enabled = "${module.enabled.value}"
environment = "${var.environment}"
monitor = "${var.monitor}"
names = "${var.names}"
namespace-env = "${var.namespace-env}"
namespace-org = "${var.namespace-org}"
organization = "${var.organization}"
owner = "${var.owner}"
product = "${var.product}"
service = "${var.service}"
tags = "${var.tags}"
team = "${var.team}"
}
resource "aws_s3_bucket" "this" {
count = "${module.enabled.value ? length(var.names) : 0}"
bucket = "${module.labels.id[count.index]}"
acl = "${var.public ? "public-read" : "private"}"
force_destroy = "${var.force_destroy}"
versioning {
enabled = "${var.versioned}"
}
#acceleration_status
#lifecycle_rule {}
#logging {
# target_bucket
# target_prefix
#}
#region
#request_payer
#replication_configuration {}
#server_side_encryption_configuration
tags = "${module.labels.tags[count.index]}"
}
/*
data "template_file" "policy_s3_bucket" {
# TODO: add condition to select public or private template
# or 2 data and condition in policy for which data to use
template = "${file("${path.module}/files/policy_s3_bucket.json")}"
vars = {
name = "${aws_s3_bucket.this.bucket}"
principal = "${var.principal}"
}
}
resource "aws_s3_bucket_policy" "bucket_policy" {
bucket = "${aws_s3_bucket.this.id}"
policy = "${data.template_file.policy_s3_bucket.rendered}"
}
*/
#resource "aws_s3_bucket_notification"
/*
resource "aws_s3_bucket_object" "this" {
count = "${length(var.files)}"
bucket = "${aws_s3_bucket.this.id}"
key = "${element(keys(var.files), count.index)}"
source = "${lookup(var.files, element(keys(var.files), count.index))}"
etag = "${md5(file("${lookup(var.files, element(keys(var.files), count.index))}"))}"
}
*/