-
Notifications
You must be signed in to change notification settings - Fork 41
/
main.cloud-storage.tf
49 lines (41 loc) · 1.59 KB
/
main.cloud-storage.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
resource "google_storage_bucket" "cloud_storage" {
name = local.mithril_aggregator_cdn_host
location = var.google_region
force_destroy = var.google_storage_bucket_force_destroy
depends_on = [googlesiteverification_dns.mithril-aggregator]
lifecycle_rule {
condition {
age = var.google_storage_bucket_max_age
}
action {
type = "Delete"
}
}
}
resource "google_service_account" "cloud_storage" {
account_id = local.environment_name
display_name = "${local.environment_name}-cs-sa"
description = "${local.environment_name} cloud storage service account"
}
resource "google_service_account_key" "cloud_storage" {
service_account_id = google_service_account.cloud_storage.name
public_key_type = "TYPE_X509_PEM_FILE"
}
locals {
google_cloud_storage_credentials_json = base64decode(google_service_account_key.cloud_storage.private_key)
}
resource "google_storage_bucket_iam_member" "cloud_storage_viewer" {
bucket = google_storage_bucket.cloud_storage.name
role = "roles/storage.objectViewer"
member = "serviceAccount:${google_service_account.cloud_storage.email}"
}
resource "google_storage_bucket_iam_member" "cloud_storage_creator" {
bucket = google_storage_bucket.cloud_storage.name
role = "roles/storage.objectCreator"
member = "serviceAccount:${google_service_account.cloud_storage.email}"
}
resource "google_storage_bucket_iam_member" "legacy_bucket_writer" {
bucket = google_storage_bucket.cloud_storage.name
role = "roles/storage.legacyBucketWriter"
member = "serviceAccount:${google_service_account.cloud_storage.email}"
}