-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudstorage.tf
87 lines (73 loc) · 2.11 KB
/
cloudstorage.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
locals {
bucket_name = format("%s-%s", var.project_id, var.region)
}
##########################################
## Define resources
##########################################
# create resource template for the gcs data lake
resource "google_storage_bucket" "data_lake" {
name = local.bucket_name
project = var.project_id
location = var.region
storage_class = "REGIONAL" # other options are MULTI_REGIONAL, STANDARD, NEARLINE, COLDLINE
force_destroy = true # defines if the bucket object should be deleted when the resource is destroyed
uniform_bucket_level_access = true # defines the bucket level access policy
requester_pays = true # defines if the requester pays for the storage when pulling objects from the bucket
# retention policy for how long objects in the bucket should be retained.
retention_policy {
is_locked = false
retention_period = 90 # defines the retention period in seconds
}
# encryption {
# # defines the encryption settings for the bucket
# default_kms_key_name = "NONE"
# }
# define logging storage location for the bucket
logging {
log_bucket = local.bucket_name
log_object_prefix = "logs"
}
# define the data lifecycle management policy
lifecycle_rule {
action {
type = "Delete"
}
condition {
age = 365
}
}
# defines if we want versioning or not
versioning {
enabled = true
}
labels = {
"data-lake" = "true"
}
}
# # create permissions resource template for the bucket
####
# COMMENTED OUT BECAUSE WE ALREADY DEFINE A POLICY DATA IN THE RESOURCE BELOW
####
# resource "google_storage_bucket_iam_binding" "data_lake_permissions" {
# bucket = google_storage_bucket.data_lake.name
# role = "roles/storage.objectViewer"
# members = [
# "allAuthenticatedUsers",
# ]
# }
# create the data lake bucket policy
resource "google_storage_bucket_iam_policy" "data_lake_policy" {
bucket = google_storage_bucket.data_lake.name
policy_data = <<POLICY
{
"bindings": [
{
"members": [
"allAuthenticatedUsers"
],
"role": "roles/storage.objectViewer"
}
]
}
POLICY
}