diff --git a/cloudrunv2_worker_pool_basic/backing_file.tf b/cloudrunv2_worker_pool_basic/backing_file.tf new file mode 100644 index 00000000..c60b1199 --- /dev/null +++ b/cloudrunv2_worker_pool_basic/backing_file.tf @@ -0,0 +1,15 @@ +# This file has some scaffolding to make sure that names are unique and that +# a region and zone are selected when you try to create your Terraform resources. + +locals { + name_suffix = "${random_pet.suffix.id}" +} + +resource "random_pet" "suffix" { + length = 2 +} + +provider "google" { + region = "us-central1" + zone = "us-central1-c" +} diff --git a/cloudrunv2_worker_pool_basic/main.tf b/cloudrunv2_worker_pool_basic/main.tf new file mode 100644 index 00000000..c224426d --- /dev/null +++ b/cloudrunv2_worker_pool_basic/main.tf @@ -0,0 +1,12 @@ +resource "google_cloud_run_v2_worker_pool" "default" { + name = "cloudrun-worker-pool-${local.name_suffix}" + location = "us-central1" + deletion_protection = false + launch_stage = "ALPHA" + + template { + containers { + image = "us-docker.pkg.dev/cloudrun/container/worker-pool" + } + } +} diff --git a/cloudrunv2_worker_pool_basic/motd b/cloudrunv2_worker_pool_basic/motd new file mode 100644 index 00000000..45a906e8 --- /dev/null +++ b/cloudrunv2_worker_pool_basic/motd @@ -0,0 +1,7 @@ +=== + +These examples use real resources that will be billed to the +Google Cloud Platform project you use - so make sure that you +run "terraform destroy" before quitting! + +=== diff --git a/cloudrunv2_worker_pool_basic/tutorial.md b/cloudrunv2_worker_pool_basic/tutorial.md new file mode 100644 index 00000000..1911ed72 --- /dev/null +++ b/cloudrunv2_worker_pool_basic/tutorial.md @@ -0,0 +1,79 @@ +# Cloudrunv2 Worker Pool Basic - Terraform + +## Setup + + + +Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform. + + + +Terraform provisions real GCP resources, so anything you create in this session will be billed against this project. + +## Terraforming! + +Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command +to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up +the project name from the environment variable. + +```bash +export GOOGLE_CLOUD_PROJECT={{project-id}} +``` + +After that, let's get Terraform started. Run the following to pull in the providers. + +```bash +terraform init +``` + +With the providers downloaded and a project set, you're ready to use Terraform. Go ahead! + +```bash +terraform apply +``` + +Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan. + +```bash +yes +``` + + +## Post-Apply + +### Editing your config + +Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed. + +```bash +terraform plan +``` + +So let's make a change! Try editing a number, or appending a value to the name in the editor. Then, +run a 'plan' again. + +```bash +terraform plan +``` + +Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes +at the 'yes' prompt. + +```bash +terraform apply +``` + +```bash +yes +``` + +## Cleanup + +Run the following to remove the resources Terraform provisioned: + +```bash +terraform destroy +``` +```bash +yes +``` diff --git a/cloudrunv2_worker_pool_custom_audiences/backing_file.tf b/cloudrunv2_worker_pool_custom_audiences/backing_file.tf new file mode 100644 index 00000000..c60b1199 --- /dev/null +++ b/cloudrunv2_worker_pool_custom_audiences/backing_file.tf @@ -0,0 +1,15 @@ +# This file has some scaffolding to make sure that names are unique and that +# a region and zone are selected when you try to create your Terraform resources. + +locals { + name_suffix = "${random_pet.suffix.id}" +} + +resource "random_pet" "suffix" { + length = 2 +} + +provider "google" { + region = "us-central1" + zone = "us-central1-c" +} diff --git a/cloudrunv2_worker_pool_custom_audiences/main.tf b/cloudrunv2_worker_pool_custom_audiences/main.tf new file mode 100644 index 00000000..ecb6f798 --- /dev/null +++ b/cloudrunv2_worker_pool_custom_audiences/main.tf @@ -0,0 +1,13 @@ +resource "google_cloud_run_v2_worker_pool" "default" { + name = "cloudrun-worker-pool-${local.name_suffix}" + location = "us-central1" + deletion_protection = false + launch_stage = "ALPHA" + + custom_audiences = ["aud1"] + template { + containers { + image = "us-docker.pkg.dev/cloudrun/container/worker-pool" + } + } +} diff --git a/cloudrunv2_worker_pool_custom_audiences/motd b/cloudrunv2_worker_pool_custom_audiences/motd new file mode 100644 index 00000000..45a906e8 --- /dev/null +++ b/cloudrunv2_worker_pool_custom_audiences/motd @@ -0,0 +1,7 @@ +=== + +These examples use real resources that will be billed to the +Google Cloud Platform project you use - so make sure that you +run "terraform destroy" before quitting! + +=== diff --git a/cloudrunv2_worker_pool_custom_audiences/tutorial.md b/cloudrunv2_worker_pool_custom_audiences/tutorial.md new file mode 100644 index 00000000..2a5aa548 --- /dev/null +++ b/cloudrunv2_worker_pool_custom_audiences/tutorial.md @@ -0,0 +1,79 @@ +# Cloudrunv2 Worker Pool Custom Audiences - Terraform + +## Setup + + + +Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform. + + + +Terraform provisions real GCP resources, so anything you create in this session will be billed against this project. + +## Terraforming! + +Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command +to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up +the project name from the environment variable. + +```bash +export GOOGLE_CLOUD_PROJECT={{project-id}} +``` + +After that, let's get Terraform started. Run the following to pull in the providers. + +```bash +terraform init +``` + +With the providers downloaded and a project set, you're ready to use Terraform. Go ahead! + +```bash +terraform apply +``` + +Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan. + +```bash +yes +``` + + +## Post-Apply + +### Editing your config + +Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed. + +```bash +terraform plan +``` + +So let's make a change! Try editing a number, or appending a value to the name in the editor. Then, +run a 'plan' again. + +```bash +terraform plan +``` + +Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes +at the 'yes' prompt. + +```bash +terraform apply +``` + +```bash +yes +``` + +## Cleanup + +Run the following to remove the resources Terraform provisioned: + +```bash +terraform destroy +``` +```bash +yes +``` diff --git a/cloudrunv2_worker_pool_directvpc/backing_file.tf b/cloudrunv2_worker_pool_directvpc/backing_file.tf new file mode 100644 index 00000000..c60b1199 --- /dev/null +++ b/cloudrunv2_worker_pool_directvpc/backing_file.tf @@ -0,0 +1,15 @@ +# This file has some scaffolding to make sure that names are unique and that +# a region and zone are selected when you try to create your Terraform resources. + +locals { + name_suffix = "${random_pet.suffix.id}" +} + +resource "random_pet" "suffix" { + length = 2 +} + +provider "google" { + region = "us-central1" + zone = "us-central1-c" +} diff --git a/cloudrunv2_worker_pool_directvpc/main.tf b/cloudrunv2_worker_pool_directvpc/main.tf new file mode 100644 index 00000000..f06fb7a8 --- /dev/null +++ b/cloudrunv2_worker_pool_directvpc/main.tf @@ -0,0 +1,19 @@ +resource "google_cloud_run_v2_worker_pool" "default" { + name = "cloudrun-worker-pool-${local.name_suffix}" + location = "us-central1" + deletion_protection = false + launch_stage = "ALPHA" + + template { + containers { + image = "us-docker.pkg.dev/cloudrun/container/worker-pool" + } + vpc_access{ + network_interfaces { + network = "default" + subnetwork = "default" + tags = ["tag1", "tag2", "tag3"] + } + } + } +} diff --git a/cloudrunv2_worker_pool_directvpc/motd b/cloudrunv2_worker_pool_directvpc/motd new file mode 100644 index 00000000..45a906e8 --- /dev/null +++ b/cloudrunv2_worker_pool_directvpc/motd @@ -0,0 +1,7 @@ +=== + +These examples use real resources that will be billed to the +Google Cloud Platform project you use - so make sure that you +run "terraform destroy" before quitting! + +=== diff --git a/cloudrunv2_worker_pool_directvpc/tutorial.md b/cloudrunv2_worker_pool_directvpc/tutorial.md new file mode 100644 index 00000000..72ca84b9 --- /dev/null +++ b/cloudrunv2_worker_pool_directvpc/tutorial.md @@ -0,0 +1,79 @@ +# Cloudrunv2 Worker Pool Directvpc - Terraform + +## Setup + + + +Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform. + + + +Terraform provisions real GCP resources, so anything you create in this session will be billed against this project. + +## Terraforming! + +Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command +to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up +the project name from the environment variable. + +```bash +export GOOGLE_CLOUD_PROJECT={{project-id}} +``` + +After that, let's get Terraform started. Run the following to pull in the providers. + +```bash +terraform init +``` + +With the providers downloaded and a project set, you're ready to use Terraform. Go ahead! + +```bash +terraform apply +``` + +Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan. + +```bash +yes +``` + + +## Post-Apply + +### Editing your config + +Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed. + +```bash +terraform plan +``` + +So let's make a change! Try editing a number, or appending a value to the name in the editor. Then, +run a 'plan' again. + +```bash +terraform plan +``` + +Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes +at the 'yes' prompt. + +```bash +terraform apply +``` + +```bash +yes +``` + +## Cleanup + +Run the following to remove the resources Terraform provisioned: + +```bash +terraform destroy +``` +```bash +yes +``` diff --git a/cloudrunv2_worker_pool_gpu/backing_file.tf b/cloudrunv2_worker_pool_gpu/backing_file.tf new file mode 100644 index 00000000..c60b1199 --- /dev/null +++ b/cloudrunv2_worker_pool_gpu/backing_file.tf @@ -0,0 +1,15 @@ +# This file has some scaffolding to make sure that names are unique and that +# a region and zone are selected when you try to create your Terraform resources. + +locals { + name_suffix = "${random_pet.suffix.id}" +} + +resource "random_pet" "suffix" { + length = 2 +} + +provider "google" { + region = "us-central1" + zone = "us-central1-c" +} diff --git a/cloudrunv2_worker_pool_gpu/main.tf b/cloudrunv2_worker_pool_gpu/main.tf new file mode 100644 index 00000000..86ea1a8f --- /dev/null +++ b/cloudrunv2_worker_pool_gpu/main.tf @@ -0,0 +1,22 @@ +resource "google_cloud_run_v2_worker_pool" "default" { + name = "cloudrun-worker-pool-${local.name_suffix}" + location = "us-central1" + deletion_protection = false + launch_stage = "ALPHA" + + template { + containers { + image = "us-docker.pkg.dev/cloudrun/container/worker-pool" + resources { + limits = { + "cpu" = "4" + "memory" = "16Gi" + "nvidia.com/gpu" = "1" + } + } + } + node_selector { + accelerator = "nvidia-l4" + } + } +} diff --git a/cloudrunv2_worker_pool_gpu/motd b/cloudrunv2_worker_pool_gpu/motd new file mode 100644 index 00000000..45a906e8 --- /dev/null +++ b/cloudrunv2_worker_pool_gpu/motd @@ -0,0 +1,7 @@ +=== + +These examples use real resources that will be billed to the +Google Cloud Platform project you use - so make sure that you +run "terraform destroy" before quitting! + +=== diff --git a/cloudrunv2_worker_pool_gpu/tutorial.md b/cloudrunv2_worker_pool_gpu/tutorial.md new file mode 100644 index 00000000..97d7674f --- /dev/null +++ b/cloudrunv2_worker_pool_gpu/tutorial.md @@ -0,0 +1,79 @@ +# Cloudrunv2 Worker Pool Gpu - Terraform + +## Setup + + + +Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform. + + + +Terraform provisions real GCP resources, so anything you create in this session will be billed against this project. + +## Terraforming! + +Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command +to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up +the project name from the environment variable. + +```bash +export GOOGLE_CLOUD_PROJECT={{project-id}} +``` + +After that, let's get Terraform started. Run the following to pull in the providers. + +```bash +terraform init +``` + +With the providers downloaded and a project set, you're ready to use Terraform. Go ahead! + +```bash +terraform apply +``` + +Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan. + +```bash +yes +``` + + +## Post-Apply + +### Editing your config + +Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed. + +```bash +terraform plan +``` + +So let's make a change! Try editing a number, or appending a value to the name in the editor. Then, +run a 'plan' again. + +```bash +terraform plan +``` + +Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes +at the 'yes' prompt. + +```bash +terraform apply +``` + +```bash +yes +``` + +## Cleanup + +Run the following to remove the resources Terraform provisioned: + +```bash +terraform destroy +``` +```bash +yes +``` diff --git a/cloudrunv2_worker_pool_limits/backing_file.tf b/cloudrunv2_worker_pool_limits/backing_file.tf new file mode 100644 index 00000000..c60b1199 --- /dev/null +++ b/cloudrunv2_worker_pool_limits/backing_file.tf @@ -0,0 +1,15 @@ +# This file has some scaffolding to make sure that names are unique and that +# a region and zone are selected when you try to create your Terraform resources. + +locals { + name_suffix = "${random_pet.suffix.id}" +} + +resource "random_pet" "suffix" { + length = 2 +} + +provider "google" { + region = "us-central1" + zone = "us-central1-c" +} diff --git a/cloudrunv2_worker_pool_limits/main.tf b/cloudrunv2_worker_pool_limits/main.tf new file mode 100644 index 00000000..78e0f699 --- /dev/null +++ b/cloudrunv2_worker_pool_limits/main.tf @@ -0,0 +1,18 @@ +resource "google_cloud_run_v2_worker_pool" "default" { + name = "cloudrun-worker-pool-${local.name_suffix}" + location = "us-central1" + deletion_protection = false + launch_stage = "ALPHA" + + template { + containers { + image = "us-docker.pkg.dev/cloudrun/container/worker-pool" + resources { + limits = { + cpu = "2" + memory = "1024Mi" + } + } + } + } +} diff --git a/cloudrunv2_worker_pool_limits/motd b/cloudrunv2_worker_pool_limits/motd new file mode 100644 index 00000000..45a906e8 --- /dev/null +++ b/cloudrunv2_worker_pool_limits/motd @@ -0,0 +1,7 @@ +=== + +These examples use real resources that will be billed to the +Google Cloud Platform project you use - so make sure that you +run "terraform destroy" before quitting! + +=== diff --git a/cloudrunv2_worker_pool_limits/tutorial.md b/cloudrunv2_worker_pool_limits/tutorial.md new file mode 100644 index 00000000..f2d7e296 --- /dev/null +++ b/cloudrunv2_worker_pool_limits/tutorial.md @@ -0,0 +1,79 @@ +# Cloudrunv2 Worker Pool Limits - Terraform + +## Setup + + + +Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform. + + + +Terraform provisions real GCP resources, so anything you create in this session will be billed against this project. + +## Terraforming! + +Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command +to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up +the project name from the environment variable. + +```bash +export GOOGLE_CLOUD_PROJECT={{project-id}} +``` + +After that, let's get Terraform started. Run the following to pull in the providers. + +```bash +terraform init +``` + +With the providers downloaded and a project set, you're ready to use Terraform. Go ahead! + +```bash +terraform apply +``` + +Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan. + +```bash +yes +``` + + +## Post-Apply + +### Editing your config + +Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed. + +```bash +terraform plan +``` + +So let's make a change! Try editing a number, or appending a value to the name in the editor. Then, +run a 'plan' again. + +```bash +terraform plan +``` + +Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes +at the 'yes' prompt. + +```bash +terraform apply +``` + +```bash +yes +``` + +## Cleanup + +Run the following to remove the resources Terraform provisioned: + +```bash +terraform destroy +``` +```bash +yes +``` diff --git a/cloudrunv2_worker_pool_mount_gcs/backing_file.tf b/cloudrunv2_worker_pool_mount_gcs/backing_file.tf new file mode 100644 index 00000000..c60b1199 --- /dev/null +++ b/cloudrunv2_worker_pool_mount_gcs/backing_file.tf @@ -0,0 +1,15 @@ +# This file has some scaffolding to make sure that names are unique and that +# a region and zone are selected when you try to create your Terraform resources. + +locals { + name_suffix = "${random_pet.suffix.id}" +} + +resource "random_pet" "suffix" { + length = 2 +} + +provider "google" { + region = "us-central1" + zone = "us-central1-c" +} diff --git a/cloudrunv2_worker_pool_mount_gcs/main.tf b/cloudrunv2_worker_pool_mount_gcs/main.tf new file mode 100644 index 00000000..01e7ce94 --- /dev/null +++ b/cloudrunv2_worker_pool_mount_gcs/main.tf @@ -0,0 +1,31 @@ +resource "google_cloud_run_v2_worker_pool" "default" { + name = "cloudrun-worker-pool-${local.name_suffix}" + + location = "us-central1" + deletion_protection = false + launch_stage = "ALPHA" + + template { + containers { + image = "us-docker.pkg.dev/cloudrun/container/worker-pool" + volume_mounts { + name = "bucket" + mount_path = "/var/www" + } + } + + volumes { + name = "bucket" + gcs { + bucket = google_storage_bucket.default.name + read_only = false + } + } + } +} + +resource "google_storage_bucket" "default" { + name = "cloudrun-worker-pool-${local.name_suffix}" + location = "US" + uniform_bucket_level_access = true +} diff --git a/cloudrunv2_worker_pool_mount_gcs/motd b/cloudrunv2_worker_pool_mount_gcs/motd new file mode 100644 index 00000000..45a906e8 --- /dev/null +++ b/cloudrunv2_worker_pool_mount_gcs/motd @@ -0,0 +1,7 @@ +=== + +These examples use real resources that will be billed to the +Google Cloud Platform project you use - so make sure that you +run "terraform destroy" before quitting! + +=== diff --git a/cloudrunv2_worker_pool_mount_gcs/tutorial.md b/cloudrunv2_worker_pool_mount_gcs/tutorial.md new file mode 100644 index 00000000..1940bb37 --- /dev/null +++ b/cloudrunv2_worker_pool_mount_gcs/tutorial.md @@ -0,0 +1,79 @@ +# Cloudrunv2 Worker Pool Mount Gcs - Terraform + +## Setup + + + +Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform. + + + +Terraform provisions real GCP resources, so anything you create in this session will be billed against this project. + +## Terraforming! + +Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command +to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up +the project name from the environment variable. + +```bash +export GOOGLE_CLOUD_PROJECT={{project-id}} +``` + +After that, let's get Terraform started. Run the following to pull in the providers. + +```bash +terraform init +``` + +With the providers downloaded and a project set, you're ready to use Terraform. Go ahead! + +```bash +terraform apply +``` + +Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan. + +```bash +yes +``` + + +## Post-Apply + +### Editing your config + +Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed. + +```bash +terraform plan +``` + +So let's make a change! Try editing a number, or appending a value to the name in the editor. Then, +run a 'plan' again. + +```bash +terraform plan +``` + +Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes +at the 'yes' prompt. + +```bash +terraform apply +``` + +```bash +yes +``` + +## Cleanup + +Run the following to remove the resources Terraform provisioned: + +```bash +terraform destroy +``` +```bash +yes +``` diff --git a/cloudrunv2_worker_pool_mount_nfs/backing_file.tf b/cloudrunv2_worker_pool_mount_nfs/backing_file.tf new file mode 100644 index 00000000..c60b1199 --- /dev/null +++ b/cloudrunv2_worker_pool_mount_nfs/backing_file.tf @@ -0,0 +1,15 @@ +# This file has some scaffolding to make sure that names are unique and that +# a region and zone are selected when you try to create your Terraform resources. + +locals { + name_suffix = "${random_pet.suffix.id}" +} + +resource "random_pet" "suffix" { + length = 2 +} + +provider "google" { + region = "us-central1" + zone = "us-central1-c" +} diff --git a/cloudrunv2_worker_pool_mount_nfs/main.tf b/cloudrunv2_worker_pool_mount_nfs/main.tf new file mode 100644 index 00000000..d27764d4 --- /dev/null +++ b/cloudrunv2_worker_pool_mount_nfs/main.tf @@ -0,0 +1,48 @@ +resource "google_cloud_run_v2_worker_pool" "default" { + name = "cloudrun-worker-pool-${local.name_suffix}" + + location = "us-central1" + deletion_protection = false + launch_stage = "ALPHA" + + template { + containers { + image = "us-docker.pkg.dev/cloudrun/container/worker-pool:latest" + volume_mounts { + name = "nfs" + mount_path = "/mnt/nfs/filestore" + } + } + vpc_access { + network_interfaces { + network = "default" + subnetwork = "default" + } + } + + volumes { + name = "nfs" + nfs { + server = google_filestore_instance.default.networks[0].ip_addresses[0] + path = "/share1" + read_only = false + } + } + } +} + +resource "google_filestore_instance" "default" { + name = "cloudrun-worker-pool-${local.name_suffix}" + location = "us-central1-b" + tier = "BASIC_HDD" + + file_shares { + capacity_gb = 1024 + name = "share1" + } + + networks { + network = "default" + modes = ["MODE_IPV4"] + } +} diff --git a/cloudrunv2_worker_pool_mount_nfs/motd b/cloudrunv2_worker_pool_mount_nfs/motd new file mode 100644 index 00000000..45a906e8 --- /dev/null +++ b/cloudrunv2_worker_pool_mount_nfs/motd @@ -0,0 +1,7 @@ +=== + +These examples use real resources that will be billed to the +Google Cloud Platform project you use - so make sure that you +run "terraform destroy" before quitting! + +=== diff --git a/cloudrunv2_worker_pool_mount_nfs/tutorial.md b/cloudrunv2_worker_pool_mount_nfs/tutorial.md new file mode 100644 index 00000000..d0d130c0 --- /dev/null +++ b/cloudrunv2_worker_pool_mount_nfs/tutorial.md @@ -0,0 +1,79 @@ +# Cloudrunv2 Worker Pool Mount Nfs - Terraform + +## Setup + + + +Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform. + + + +Terraform provisions real GCP resources, so anything you create in this session will be billed against this project. + +## Terraforming! + +Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command +to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up +the project name from the environment variable. + +```bash +export GOOGLE_CLOUD_PROJECT={{project-id}} +``` + +After that, let's get Terraform started. Run the following to pull in the providers. + +```bash +terraform init +``` + +With the providers downloaded and a project set, you're ready to use Terraform. Go ahead! + +```bash +terraform apply +``` + +Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan. + +```bash +yes +``` + + +## Post-Apply + +### Editing your config + +Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed. + +```bash +terraform plan +``` + +So let's make a change! Try editing a number, or appending a value to the name in the editor. Then, +run a 'plan' again. + +```bash +terraform plan +``` + +Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes +at the 'yes' prompt. + +```bash +terraform apply +``` + +```bash +yes +``` + +## Cleanup + +Run the following to remove the resources Terraform provisioned: + +```bash +terraform destroy +``` +```bash +yes +``` diff --git a/cloudrunv2_worker_pool_multicontainer/backing_file.tf b/cloudrunv2_worker_pool_multicontainer/backing_file.tf new file mode 100644 index 00000000..c60b1199 --- /dev/null +++ b/cloudrunv2_worker_pool_multicontainer/backing_file.tf @@ -0,0 +1,15 @@ +# This file has some scaffolding to make sure that names are unique and that +# a region and zone are selected when you try to create your Terraform resources. + +locals { + name_suffix = "${random_pet.suffix.id}" +} + +resource "random_pet" "suffix" { + length = 2 +} + +provider "google" { + region = "us-central1" + zone = "us-central1-c" +} diff --git a/cloudrunv2_worker_pool_multicontainer/main.tf b/cloudrunv2_worker_pool_multicontainer/main.tf new file mode 100644 index 00000000..8719f198 --- /dev/null +++ b/cloudrunv2_worker_pool_multicontainer/main.tf @@ -0,0 +1,33 @@ +resource "google_cloud_run_v2_worker_pool" "default" { + name = "cloudrun-worker-pool-${local.name_suffix}" + location = "us-central1" + deletion_protection = false + launch_stage = "ALPHA" + + template { + containers { + name = "hello-1" + image = "us-docker.pkg.dev/cloudrun/container/worker-pool" + depends_on = ["hello-2"] + volume_mounts { + name = "empty-dir-volume" + mount_path = "/mnt" + } + } + containers { + name = "hello-2" + image = "us-docker.pkg.dev/cloudrun/container/worker-pool" + env { + name = "PORT" + value = "8081" + } + } + volumes { + name = "empty-dir-volume" + empty_dir { + medium = "MEMORY" + size_limit = "256Mi" + } + } + } +} diff --git a/cloudrunv2_worker_pool_multicontainer/motd b/cloudrunv2_worker_pool_multicontainer/motd new file mode 100644 index 00000000..45a906e8 --- /dev/null +++ b/cloudrunv2_worker_pool_multicontainer/motd @@ -0,0 +1,7 @@ +=== + +These examples use real resources that will be billed to the +Google Cloud Platform project you use - so make sure that you +run "terraform destroy" before quitting! + +=== diff --git a/cloudrunv2_worker_pool_multicontainer/tutorial.md b/cloudrunv2_worker_pool_multicontainer/tutorial.md new file mode 100644 index 00000000..a931cfff --- /dev/null +++ b/cloudrunv2_worker_pool_multicontainer/tutorial.md @@ -0,0 +1,79 @@ +# Cloudrunv2 Worker Pool Multicontainer - Terraform + +## Setup + + + +Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform. + + + +Terraform provisions real GCP resources, so anything you create in this session will be billed against this project. + +## Terraforming! + +Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command +to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up +the project name from the environment variable. + +```bash +export GOOGLE_CLOUD_PROJECT={{project-id}} +``` + +After that, let's get Terraform started. Run the following to pull in the providers. + +```bash +terraform init +``` + +With the providers downloaded and a project set, you're ready to use Terraform. Go ahead! + +```bash +terraform apply +``` + +Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan. + +```bash +yes +``` + + +## Post-Apply + +### Editing your config + +Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed. + +```bash +terraform plan +``` + +So let's make a change! Try editing a number, or appending a value to the name in the editor. Then, +run a 'plan' again. + +```bash +terraform plan +``` + +Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes +at the 'yes' prompt. + +```bash +terraform apply +``` + +```bash +yes +``` + +## Cleanup + +Run the following to remove the resources Terraform provisioned: + +```bash +terraform destroy +``` +```bash +yes +``` diff --git a/cloudrunv2_worker_pool_secret/backing_file.tf b/cloudrunv2_worker_pool_secret/backing_file.tf new file mode 100644 index 00000000..c60b1199 --- /dev/null +++ b/cloudrunv2_worker_pool_secret/backing_file.tf @@ -0,0 +1,15 @@ +# This file has some scaffolding to make sure that names are unique and that +# a region and zone are selected when you try to create your Terraform resources. + +locals { + name_suffix = "${random_pet.suffix.id}" +} + +resource "random_pet" "suffix" { + length = 2 +} + +provider "google" { + region = "us-central1" + zone = "us-central1-c" +} diff --git a/cloudrunv2_worker_pool_secret/main.tf b/cloudrunv2_worker_pool_secret/main.tf new file mode 100644 index 00000000..c9d83e1c --- /dev/null +++ b/cloudrunv2_worker_pool_secret/main.tf @@ -0,0 +1,51 @@ +resource "google_cloud_run_v2_worker_pool" "default" { + name = "cloudrun-worker-pool-${local.name_suffix}" + location = "us-central1" + deletion_protection = false + launch_stage = "ALPHA" + + 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 = 0444 + } + } + } + containers { + image = "us-docker.pkg.dev/cloudrun/container/worker-pool" + 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 = "secret-1-${local.name_suffix}" + replication { + auto {} + } +} + +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] +} diff --git a/cloudrunv2_worker_pool_secret/motd b/cloudrunv2_worker_pool_secret/motd new file mode 100644 index 00000000..45a906e8 --- /dev/null +++ b/cloudrunv2_worker_pool_secret/motd @@ -0,0 +1,7 @@ +=== + +These examples use real resources that will be billed to the +Google Cloud Platform project you use - so make sure that you +run "terraform destroy" before quitting! + +=== diff --git a/cloudrunv2_worker_pool_secret/tutorial.md b/cloudrunv2_worker_pool_secret/tutorial.md new file mode 100644 index 00000000..880befd2 --- /dev/null +++ b/cloudrunv2_worker_pool_secret/tutorial.md @@ -0,0 +1,79 @@ +# Cloudrunv2 Worker Pool Secret - Terraform + +## Setup + + + +Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform. + + + +Terraform provisions real GCP resources, so anything you create in this session will be billed against this project. + +## Terraforming! + +Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command +to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up +the project name from the environment variable. + +```bash +export GOOGLE_CLOUD_PROJECT={{project-id}} +``` + +After that, let's get Terraform started. Run the following to pull in the providers. + +```bash +terraform init +``` + +With the providers downloaded and a project set, you're ready to use Terraform. Go ahead! + +```bash +terraform apply +``` + +Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan. + +```bash +yes +``` + + +## Post-Apply + +### Editing your config + +Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed. + +```bash +terraform plan +``` + +So let's make a change! Try editing a number, or appending a value to the name in the editor. Then, +run a 'plan' again. + +```bash +terraform plan +``` + +Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes +at the 'yes' prompt. + +```bash +terraform apply +``` + +```bash +yes +``` + +## Cleanup + +Run the following to remove the resources Terraform provisioned: + +```bash +terraform destroy +``` +```bash +yes +``` diff --git a/cloudrunv2_worker_pool_sql/backing_file.tf b/cloudrunv2_worker_pool_sql/backing_file.tf new file mode 100644 index 00000000..c60b1199 --- /dev/null +++ b/cloudrunv2_worker_pool_sql/backing_file.tf @@ -0,0 +1,15 @@ +# This file has some scaffolding to make sure that names are unique and that +# a region and zone are selected when you try to create your Terraform resources. + +locals { + name_suffix = "${random_pet.suffix.id}" +} + +resource "random_pet" "suffix" { + length = 2 +} + +provider "google" { + region = "us-central1" + zone = "us-central1-c" +} diff --git a/cloudrunv2_worker_pool_sql/main.tf b/cloudrunv2_worker_pool_sql/main.tf new file mode 100644 index 00000000..a3928cd8 --- /dev/null +++ b/cloudrunv2_worker_pool_sql/main.tf @@ -0,0 +1,77 @@ +resource "google_cloud_run_v2_worker_pool" "default" { + name = "cloudrun-worker-pool-${local.name_suffix}" + location = "us-central1" + deletion_protection = false + launch_stage = "ALPHA" + + template { + + volumes { + name = "cloudsql" + cloud_sql_instance { + instances = [google_sql_database_instance.instance.connection_name] + } + } + + containers { + image = "us-docker.pkg.dev/cloudrun/container/worker-pool" + + 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" + } + } + } + + instance_splits { + type = "INSTANCE_SPLIT_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 = "secret-1-${local.name_suffix}" + replication { + auto {} + } +} + +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 = "cloudrun-sql-${local.name_suffix}" + region = "us-central1" + database_version = "MYSQL_5_7" + settings { + tier = "db-f1-micro" + } + + deletion_protection = false +} diff --git a/cloudrunv2_worker_pool_sql/motd b/cloudrunv2_worker_pool_sql/motd new file mode 100644 index 00000000..45a906e8 --- /dev/null +++ b/cloudrunv2_worker_pool_sql/motd @@ -0,0 +1,7 @@ +=== + +These examples use real resources that will be billed to the +Google Cloud Platform project you use - so make sure that you +run "terraform destroy" before quitting! + +=== diff --git a/cloudrunv2_worker_pool_sql/tutorial.md b/cloudrunv2_worker_pool_sql/tutorial.md new file mode 100644 index 00000000..f528176a --- /dev/null +++ b/cloudrunv2_worker_pool_sql/tutorial.md @@ -0,0 +1,79 @@ +# Cloudrunv2 Worker Pool Sql - Terraform + +## Setup + + + +Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform. + + + +Terraform provisions real GCP resources, so anything you create in this session will be billed against this project. + +## Terraforming! + +Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command +to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up +the project name from the environment variable. + +```bash +export GOOGLE_CLOUD_PROJECT={{project-id}} +``` + +After that, let's get Terraform started. Run the following to pull in the providers. + +```bash +terraform init +``` + +With the providers downloaded and a project set, you're ready to use Terraform. Go ahead! + +```bash +terraform apply +``` + +Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan. + +```bash +yes +``` + + +## Post-Apply + +### Editing your config + +Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed. + +```bash +terraform plan +``` + +So let's make a change! Try editing a number, or appending a value to the name in the editor. Then, +run a 'plan' again. + +```bash +terraform plan +``` + +Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes +at the 'yes' prompt. + +```bash +terraform apply +``` + +```bash +yes +``` + +## Cleanup + +Run the following to remove the resources Terraform provisioned: + +```bash +terraform destroy +``` +```bash +yes +```