|
| 1 | +# Copyright 2024 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +# GCS bucket used as skaffold build cache |
| 16 | +resource "google_storage_bucket" "build_cache" { |
| 17 | + project = var.project_id |
| 18 | + name = "build-cache-${local.service_name}-${data.google_project.project.number}" |
| 19 | + uniform_bucket_level_access = true |
| 20 | + location = var.region |
| 21 | + force_destroy = var.buckets_force_destroy |
| 22 | +} |
| 23 | + |
| 24 | +resource "google_storage_bucket" "release_source_development" { |
| 25 | + project = var.project_id |
| 26 | + name = "release-source-development-${local.service_name}-${data.google_project.project.number}" |
| 27 | + uniform_bucket_level_access = true |
| 28 | + location = var.region |
| 29 | + force_destroy = var.buckets_force_destroy |
| 30 | +} |
| 31 | + |
| 32 | +# Initialize cache with empty file |
| 33 | +resource "google_storage_bucket_object" "cache" { |
| 34 | + bucket = google_storage_bucket.build_cache.name |
| 35 | + |
| 36 | + name = local.cache_filename |
| 37 | + content = " " |
| 38 | + |
| 39 | + lifecycle { |
| 40 | + # do not reset cache when running terraform |
| 41 | + ignore_changes = [ |
| 42 | + content, |
| 43 | + detect_md5hash |
| 44 | + ] |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +# give CloudBuild SA access to skaffold cache |
| 49 | +resource "google_storage_bucket_iam_member" "build_cache" { |
| 50 | + bucket = google_storage_bucket.build_cache.name |
| 51 | + |
| 52 | + member = "serviceAccount:${google_service_account.cloud_build.email}" |
| 53 | + role = "roles/storage.admin" |
| 54 | +} |
| 55 | + |
| 56 | +# give CloudBuild SA access to write to source development bucket |
| 57 | +resource "google_storage_bucket_iam_member" "release_source_development_admin" { |
| 58 | + bucket = google_storage_bucket.release_source_development.name |
| 59 | + |
| 60 | + member = "serviceAccount:${google_service_account.cloud_build.email}" |
| 61 | + role = "roles/storage.admin" |
| 62 | +} |
| 63 | + |
| 64 | +# give CloudDeploy SA access to read from source development bucket |
| 65 | +resource "google_storage_bucket_iam_member" "release_source_development_objectViewer" { |
| 66 | + bucket = google_storage_bucket.release_source_development.name |
| 67 | + |
| 68 | + member = "serviceAccount:${google_service_account.cloud_deploy.email}" |
| 69 | + role = "roles/storage.objectViewer" |
| 70 | +} |
0 commit comments