forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cloudrun v2 service (GoogleCloudPlatform#6850)
- Loading branch information
1 parent
fbfb40c
commit f167928
Showing
8 changed files
with
1,381 additions
and
1 deletion.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
mmv1/templates/terraform/examples/cloudrunv2_service_basic.tf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
resource "google_cloud_run_v2_service" "<%= ctx[:primary_resource_id] %>" { | ||
name = "<%= ctx[:vars]['cloud_run_service_name'] %>" | ||
location = "us-central1" | ||
ingress = "INGRESS_TRAFFIC_ALL" | ||
|
||
binary_authorization { | ||
use_default = true | ||
breakglass_justification = "Some justification" | ||
} | ||
template { | ||
containers { | ||
image = "us-docker.pkg.dev/cloudrun/container/hello" | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
mmv1/templates/terraform/examples/cloudrunv2_service_probes.tf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
resource "google_cloud_run_v2_service" "<%= ctx[:primary_resource_id] %>" { | ||
name = "<%= ctx[:vars]['cloud_run_service_name'] %>" | ||
location = "us-central1" | ||
|
||
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 = "/" | ||
} | ||
} | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
mmv1/templates/terraform/examples/cloudrunv2_service_secret.tf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
resource "google_cloud_run_v2_service" "<%= ctx[:primary_resource_id] %>" { | ||
name = "<%= ctx[:vars]['cloud_run_service_name'] %>" | ||
location = "us-central1" | ||
ingress = "INGRESS_TRAFFIC_ALL" | ||
|
||
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" | ||
} | ||
} | ||
} | ||
depends_on = [google_secret_manager_secret_version.secret-version-data] | ||
} | ||
|
||
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] | ||
} |
79 changes: 79 additions & 0 deletions
79
mmv1/templates/terraform/examples/cloudrunv2_service_sql.tf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
resource "google_cloud_run_v2_service" "<%= ctx[:primary_resource_id] %>" { | ||
name = "<%= ctx[:vars]['cloud_run_service_name'] %>" | ||
location = "us-central1" | ||
ingress = "INGRESS_TRAFFIC_ALL" | ||
|
||
template { | ||
scaling { | ||
max_instance_count = 2 | ||
} | ||
|
||
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 = "SECRET_ENV_VAR" | ||
value_source { | ||
secret_key_ref { | ||
secret = google_secret_manager_secret.secret.secret_id | ||
version = "1" | ||
} | ||
} | ||
} | ||
volume_mounts { | ||
name = "cloudsql" | ||
mount_path = "/cloudsql" | ||
} | ||
} | ||
} | ||
|
||
traffic { | ||
type = "TRAFFIC_TARGET_ALLOCATION_TYPE_LATEST" | ||
percent = 100 | ||
} | ||
depends_on = [google_secret_manager_secret_version.secret-version-data] | ||
} | ||
|
||
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'] %>" | ||
} |
35 changes: 35 additions & 0 deletions
35
mmv1/templates/terraform/examples/cloudrunv2_service_vpcaccess.tf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
resource "google_cloud_run_v2_service" "<%= ctx[:primary_resource_id] %>" { | ||
name = "<%= ctx[:vars]['cloud_run_service_name'] %>" | ||
location = "us-central1" | ||
|
||
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 | ||
} |
Oops, something went wrong.