Skip to content

Commit

Permalink
Cloudrun v2 job (GoogleCloudPlatform#6852)
Browse files Browse the repository at this point in the history
  • Loading branch information
shuyama1 authored and hao-nan-li committed Dec 6, 2022
1 parent 0516672 commit 58637e9
Show file tree
Hide file tree
Showing 8 changed files with 1,362 additions and 0 deletions.
658 changes: 658 additions & 0 deletions mmv1/products/cloudrunv2/api.yaml

Large diffs are not rendered by default.

90 changes: 90 additions & 0 deletions mmv1/products/cloudrunv2/terraform.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Copyright 2022 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

--- !ruby/object:Provider::Terraform::Config
overrides: !ruby/object:Overrides::ResourceOverrides
Job: !ruby/object:Overrides::Terraform::ResourceOverride
id_format: 'projects/{{project}}/locations/{{location}}/jobs/{{name}}'
import_format: ["projects/{{project}}/locations/{{location}}/jobs/{{name}}"]
autogen_async: true
examples:
- !ruby/object:Provider::Terraform::Examples
name: "cloudrunv2_job_basic"
primary_resource_id: "default"
primary_resource_name: "fmt.Sprintf(\"tf-test-cloudrun-srv%s\", context[\"random_suffix\"])"
vars:
cloud_run_job_name: "cloudrun-job"
- !ruby/object:Provider::Terraform::Examples
name: "cloudrunv2_job_sql"
primary_resource_id: "default"
primary_resource_name: "fmt.Sprintf(\"tf-test-cloudrun-srv%s\", context[\"random_suffix\"])"
vars:
cloud_run_job_name: "cloudrun-job"
secret_id: "secret"
cloud_run_sql_name: "cloudrun-sql"
deletion_protection: "true"
test_vars_overrides:
deletion_protection: "false"
oics_vars_overrides:
deletion_protection: "false"
- !ruby/object:Provider::Terraform::Examples
name: "cloudrunv2_job_vpcaccess"
primary_resource_id: "default"
primary_resource_name: "fmt.Sprintf(\"tf-test-cloudrun-srv%s\", context[\"random_suffix\"])"
vars:
cloud_run_job_name: "cloudrun-job"
vpc_access_connector_name: "run-vpc"
vpc_compute_subnetwork_name: "run-subnetwork"
compute_network_name: "run-network"
- !ruby/object:Provider::Terraform::Examples
name: "cloudrunv2_job_probes"
primary_resource_id: "default"
primary_resource_name: "fmt.Sprintf(\"tf-test-cloudrun-srv%s\", context[\"random_suffix\"])"
vars:
cloud_run_job_name: "cloudrun-job"
- !ruby/object:Provider::Terraform::Examples
name: "cloudrunv2_job_secret"
primary_resource_id: "default"
primary_resource_name: "fmt.Sprintf(\"tf-test-cloudrun-srv%s\", context[\"random_suffix\"])"
vars:
cloud_run_job_name: "cloudrun-job"
secret_id: "secret"
properties:
name: !ruby/object:Overrides::Terraform::PropertyOverride
diff_suppress_func: 'compareSelfLinkOrResourceName'
custom_expand: templates/terraform/custom_expand/resource_from_self_link.go.erb
custom_flatten: templates/terraform/custom_flatten/name_from_self_link.erb
launchStage: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
template.parallelism: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
template.taskCount: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
template.template.executionEnvironment: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
template.template.maxRetries: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
template.template.serviceAccount: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
template.template.timeout: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
template.template.containers: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
template.template.containers.resources: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
template.template.containers.resources.limits: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
template.template.containers.startupProbe: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
template.template.containers.startupProbe.tcpSocket.port: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
13 changes: 13 additions & 0 deletions mmv1/templates/terraform/examples/cloudrunv2_job_basic.tf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
resource "google_cloud_run_v2_job" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['cloud_run_job_name'] %>"
location = "us-central1"
launch_stage = "BETA"

template {
template {
containers {
image = "us-docker.pkg.dev/cloudrun/container/hello"
}
}
}
}
27 changes: 27 additions & 0 deletions mmv1/templates/terraform/examples/cloudrunv2_job_probes.tf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
resource "google_cloud_run_v2_job" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['cloud_run_job_name'] %>"
location = "us-central1"
launch_stage = "BETA"

template {
template{
containers {
image = "us-docker.pkg.dev/cloudrun/container/hello"
startup_probe {
initial_delay_seconds = 0
timeout_seconds = 1
period_seconds = 3
failure_threshold = 1
tcp_socket {
port = 8080
}
}
liveness_probe {
http_get {
path = "/"
}
}
}
}
}
}
51 changes: 51 additions & 0 deletions mmv1/templates/terraform/examples/cloudrunv2_job_secret.tf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
resource "google_cloud_run_v2_job" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['cloud_run_job_name'] %>"
location = "us-central1"
launch_stage = "BETA"

template {
template {
volumes {
name = "a-volume"
secret {
secret = google_secret_manager_secret.secret.secret_id
default_mode = 292 # 0444
items {
version = "1"
path = "my-secret"
mode = 256 # 0400
}
}
}
containers {
image = "us-docker.pkg.dev/cloudrun/container/hello"
volume_mounts {
name = "a-volume"
mount_path = "/secrets"
}
}
}
}
}

data "google_project" "project" {
}

resource "google_secret_manager_secret" "secret" {
secret_id = "<%= ctx[:vars]['secret_id'] %>"
replication {
automatic = true
}
}

resource "google_secret_manager_secret_version" "secret-version-data" {
secret = google_secret_manager_secret.secret.name
secret_data = "secret-data"
}

resource "google_secret_manager_secret_iam_member" "secret-access" {
secret_id = google_secret_manager_secret.secret.id
role = "roles/secretmanager.secretAccessor"
member = "serviceAccount:${data.google_project.project.number}-compute@developer.gserviceaccount.com"
depends_on = [google_secret_manager_secret.secret]
}
71 changes: 71 additions & 0 deletions mmv1/templates/terraform/examples/cloudrunv2_job_sql.tf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
resource "google_cloud_run_v2_job" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['cloud_run_job_name'] %>"
location = "us-central1"
launch_stage = "BETA"

template {
template{
volumes {
name = "cloudsql"
cloud_sql_instance {
instances = [google_sql_database_instance.instance.connection_name]
}
}

containers {
image = "us-docker.pkg.dev/cloudrun/container/hello"

env {
name = "FOO"
value = "bar"
}
env {
name = "latestdclsecret"
value_source {
secret_key_ref {
secret = google_secret_manager_secret.secret.secret_id
version = "1"
}
}
}
volume_mounts {
name = "cloudsql"
mount_path = "/cloudsql"
}
}
}
}
}

data "google_project" "project" {
}

resource "google_secret_manager_secret" "secret" {
secret_id = "<%= ctx[:vars]['secret_id'] %>"
replication {
automatic = true
}
}

resource "google_secret_manager_secret_version" "secret-version-data" {
secret = google_secret_manager_secret.secret.name
secret_data = "secret-data"
}

resource "google_secret_manager_secret_iam_member" "secret-access" {
secret_id = google_secret_manager_secret.secret.id
role = "roles/secretmanager.secretAccessor"
member = "serviceAccount:${data.google_project.project.number}-compute@developer.gserviceaccount.com"
depends_on = [google_secret_manager_secret.secret]
}

resource "google_sql_database_instance" "instance" {
name = "<%= ctx[:vars]['cloud_run_sql_name'] %>"
region = "us-central1"
database_version = "MYSQL_5_7"
settings {
tier = "db-f1-micro"
}

deletion_protection = "<%= ctx[:vars]['deletion_protection'] %>"
}
38 changes: 38 additions & 0 deletions mmv1/templates/terraform/examples/cloudrunv2_job_vpcaccess.tf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
resource "google_cloud_run_v2_job" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['cloud_run_job_name'] %>"
location = "us-central1"
launch_stage = "BETA"

template {
template{
containers {
image = "us-docker.pkg.dev/cloudrun/container/hello"
}
vpc_access{
connector = google_vpc_access_connector.connector.id
egress = "ALL_TRAFFIC"
}
}
}
}

resource "google_vpc_access_connector" "connector" {
name = "<%= ctx[:vars]['vpc_access_connector_name'] %>"
subnet {
name = google_compute_subnetwork.custom_test.name
}
machine_type = "e2-standard-4"
min_instances = 2
max_instances = 3
region = "us-central1"
}
resource "google_compute_subnetwork" "custom_test" {
name = "<%= ctx[:vars]['vpc_compute_subnetwork_name'] %>"
ip_cidr_range = "10.2.0.0/28"
region = "us-central1"
network = google_compute_network.custom_test.id
}
resource "google_compute_network" "custom_test" {
name = "<%= ctx[:vars]['compute_network_name'] %>"
auto_create_subnetworks = false
}
Loading

0 comments on commit 58637e9

Please sign in to comment.