|
| 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 | +# https://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 | +# Not enabling the permissions on the default service account here Since the permissions |
| 16 | +# bindings specified here will be removed when the terraform cleanup happens, that causes |
| 17 | +# failures in app engine environment. These permissions should be granted through the latch-key |
| 18 | +# configurations. |
| 19 | + |
| 20 | +resource "google_app_engine_standard_app_version" "test_service" { |
| 21 | + |
| 22 | + version_id = "v1" |
| 23 | + project = var.project_id |
| 24 | + service = "test-standard-service-${var.runtime}-${terraform.workspace}" |
| 25 | + runtime = var.runtime |
| 26 | + |
| 27 | + deployment { |
| 28 | + zip { |
| 29 | + // The object's media_link does not work, GAE requires this format |
| 30 | + // https://cloud.google.com/appengine/docs/admin-api/reference/rpc/google.appengine.v1#zipinfo |
| 31 | + source_url = "https://storage.googleapis.com/${google_storage_bucket.bucket.name}/${google_storage_bucket_object.object.name}" |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + // Required, but leave empty to fall back to the runtime default |
| 36 | + entrypoint { |
| 37 | + shell = "" |
| 38 | + } |
| 39 | + |
| 40 | + env_variables = { |
| 41 | + "PUSH_PORT" = "8080", |
| 42 | + "REQUEST_SUBSCRIPTION_NAME" = module.pubsub.info.request_topic.subscription_name, |
| 43 | + "RESPONSE_TOPIC_NAME" = module.pubsub.info.response_topic.topic_name, |
| 44 | + "PROJECT_ID" = var.project_id, |
| 45 | + "SUBSCRIPTION_MODE" = "push" |
| 46 | + } |
| 47 | + |
| 48 | + noop_on_destroy = false |
| 49 | + delete_service_on_destroy = true |
| 50 | +} |
| 51 | + |
| 52 | +resource "google_storage_bucket" "bucket" { |
| 53 | + name = "${terraform.workspace}-appsource" # Every bucket name must be globally unique |
| 54 | + location = "US" |
| 55 | + uniform_bucket_level_access = true |
| 56 | +} |
| 57 | + |
| 58 | +resource "google_storage_bucket_object" "object" { |
| 59 | + name = "appsource.zip" |
| 60 | + bucket = google_storage_bucket.bucket.name |
| 61 | + # Add path to the zipped function source code, source file zip should be in the bucket |
| 62 | + source = var.appsource |
| 63 | +} |
| 64 | + |
| 65 | +module "pubsub" { |
| 66 | + source = "../modules/pubsub" |
| 67 | + |
| 68 | + project_id = var.project_id |
| 69 | +} |
| 70 | + |
| 71 | +module "pubsub-push-subscription" { |
| 72 | + source = "../modules/pubsub-push-subscription" |
| 73 | + |
| 74 | + project_id = var.project_id |
| 75 | + topic = module.pubsub.info.request_topic.topic_name |
| 76 | + push_endpoint = "https://${google_app_engine_standard_app_version.test_service.service}-dot-${var.project_id}.uc.r.appspot.com/" |
| 77 | +} |
| 78 | + |
| 79 | +variable "appsource" { |
| 80 | + type = string |
| 81 | +} |
| 82 | + |
| 83 | +variable "runtime" { |
| 84 | + type = string |
| 85 | +} |
| 86 | + |
| 87 | +output "pubsub_info" { |
| 88 | + value = module.pubsub.info |
| 89 | + description = "Info about the request/response pubsub topics and subscription to use in the test" |
| 90 | +} |
0 commit comments