...

Text file src/github.com/GoogleCloudPlatform/k8s-config-connector/scripts/resource-autogen/generated/samples/CloudFunctions2-CloudFunctions2Function-cloudfunctions2_secret_env/main.tf

Documentation: github.com/GoogleCloudPlatform/k8s-config-connector/scripts/resource-autogen/generated/samples/CloudFunctions2-CloudFunctions2Function-cloudfunctions2_secret_env

     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
    18locals {
    19  project = "my-project-name" # Google Cloud Platform Project ID
    20}
    21
    22resource "google_storage_bucket" "bucket" {
    23  name     = "${local.project}-gcf-source"  # Every bucket name must be globally unique
    24  location = "US"
    25  uniform_bucket_level_access = true
    26}
    27 
    28resource "google_storage_bucket_object" "object" {
    29  name   = "function-source.zip"
    30  bucket = google_storage_bucket.bucket.name
    31  source = "function-source.zip"  # Add path to the zipped function source code
    32}
    33 
    34resource "google_cloudfunctions2_function" "function" {
    35  name = "function-secret"
    36  location = "us-central1"
    37  description = "a new function"
    38 
    39  build_config {
    40    runtime = "nodejs16"
    41    entry_point = "helloHttp"  # Set the entry point 
    42    source {
    43      storage_source {
    44        bucket = google_storage_bucket.bucket.name
    45        object = google_storage_bucket_object.object.name
    46      }
    47    }
    48  }
    49 
    50  service_config {
    51    max_instance_count  = 1
    52    available_memory    = "256M"
    53    timeout_seconds     = 60
    54
    55    secret_environment_variables {
    56      key        = "TEST"
    57      project_id = local.project
    58      secret     = google_secret_manager_secret.secret.secret_id
    59      version    = "latest"
    60    }
    61  }
    62  depends_on = [google_secret_manager_secret_version.secret]
    63}
    64
    65resource "google_secret_manager_secret" "secret" {
    66  secret_id = "secret"
    67
    68  replication {
    69    user_managed {
    70      replicas {
    71        location = "us-central1"
    72      }
    73    }
    74  }  
    75}
    76
    77resource "google_secret_manager_secret_version" "secret" {
    78  secret = google_secret_manager_secret.secret.name
    79
    80  secret_data = "secret"
    81  enabled = true
    82}
    83```

View as plain text