...
1/**
2 * Copyright 2022 Google LLC
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17```hcl
18resource "google_cloud_run_v2_job" "default" {
19 name = "cloudrun-job"
20 location = "us-central1"
21 launch_stage = "BETA"
22
23 template {
24 template {
25 volumes {
26 name = "a-volume"
27 secret {
28 secret = google_secret_manager_secret.secret.secret_id
29 default_mode = 292 # 0444
30 items {
31 version = "1"
32 path = "my-secret"
33 mode = 256 # 0400
34 }
35 }
36 }
37 containers {
38 image = "us-docker.pkg.dev/cloudrun/container/hello"
39 volume_mounts {
40 name = "a-volume"
41 mount_path = "/secrets"
42 }
43 }
44 }
45 }
46
47 lifecycle {
48 ignore_changes = [
49 launch_stage,
50 ]
51 }
52}
53
54data "google_project" "project" {
55}
56
57resource "google_secret_manager_secret" "secret" {
58 secret_id = "secret"
59 replication {
60 automatic = true
61 }
62}
63
64resource "google_secret_manager_secret_version" "secret-version-data" {
65 secret = google_secret_manager_secret.secret.name
66 secret_data = "secret-data"
67}
68
69resource "google_secret_manager_secret_iam_member" "secret-access" {
70 secret_id = google_secret_manager_secret.secret.id
71 role = "roles/secretmanager.secretAccessor"
72 member = "serviceAccount:${data.google_project.project.number}-compute@developer.gserviceaccount.com"
73 depends_on = [google_secret_manager_secret.secret]
74}
75```
View as plain text