2021-01-01 21:49:51 +03:00
|
|
|
# Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
2019-04-04 11:33:38 +03:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
data "google_project" "current" {
|
2021-02-08 20:25:04 +03:00
|
|
|
project_id = var.project
|
2019-04-04 11:33:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
locals {
|
|
|
|
default_role_entities = [
|
|
|
|
"OWNER:project-owners-${data.google_project.current.number}",
|
|
|
|
"OWNER:project-editors-${data.google_project.current.number}",
|
|
|
|
"READER:project-viewers-${data.google_project.current.number}",
|
|
|
|
|
|
|
|
# all the objects are publicly readable!
|
|
|
|
"READER:allUsers",
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_storage_bucket" "default" {
|
2021-02-08 20:25:04 +03:00
|
|
|
project = var.project
|
|
|
|
name = var.name
|
|
|
|
labels = var.labels
|
2019-04-04 11:33:38 +03:00
|
|
|
|
|
|
|
# SLA is enough for a cache and is cheaper than MULTI_REGIONAL
|
|
|
|
# see https://cloud.google.com/storage/docs/storage-classes
|
|
|
|
storage_class = "REGIONAL"
|
|
|
|
|
|
|
|
# Use a normal region since the storage_class is regional
|
2021-02-08 20:25:04 +03:00
|
|
|
location = var.region
|
2019-04-04 11:33:38 +03:00
|
|
|
|
2019-07-02 13:14:21 +03:00
|
|
|
# cleanup the cache after ${var.cache_retention_days} days
|
2019-04-04 11:33:38 +03:00
|
|
|
lifecycle_rule {
|
|
|
|
action {
|
|
|
|
type = "Delete"
|
|
|
|
}
|
|
|
|
|
|
|
|
condition {
|
2021-02-08 20:25:04 +03:00
|
|
|
age = var.cache_retention_days # days
|
2019-04-04 11:33:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-24 15:33:59 +03:00
|
|
|
website {
|
|
|
|
# This doesn't exist, but the property has to have a value, otherwise GCP
|
|
|
|
# sets a default one and Terraform never thinks the config applies cleanly.
|
|
|
|
# I miss AWS.
|
|
|
|
main_page_suffix = "index.html"
|
|
|
|
}
|
|
|
|
|
2019-04-04 11:33:38 +03:00
|
|
|
force_destroy = true
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_storage_bucket_acl" "default" {
|
2021-02-08 20:25:04 +03:00
|
|
|
bucket = google_storage_bucket.default.name
|
2019-04-04 11:33:38 +03:00
|
|
|
default_acl = "publicread"
|
2021-02-08 20:25:04 +03:00
|
|
|
role_entity = local.default_role_entities
|
2019-04-04 11:33:38 +03:00
|
|
|
}
|