diff --git a/region_backend_bucket_basic/backing_file.tf b/region_backend_bucket_basic/backing_file.tf new file mode 100644 index 00000000..c60b1199 --- /dev/null +++ b/region_backend_bucket_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/region_backend_bucket_basic/main.tf b/region_backend_bucket_basic/main.tf new file mode 100644 index 00000000..f779fa11 --- /dev/null +++ b/region_backend_bucket_basic/main.tf @@ -0,0 +1,14 @@ +resource "google_compute_region_backend_bucket" "image_backend" { + name = "region-image-backend-bucket-${local.name_suffix}" + region = "us-central1" + bucket_name = google_storage_bucket.image_backend.name + description = "Regional backend bucket example" + load_balancing_scheme = "INTERNAL_MANAGED" +} + +resource "google_storage_bucket" "image_backend" { + name = "region-image-store-bucket-${local.name_suffix}" + location = "US-CENTRAL1" + force_destroy = true + uniform_bucket_level_access = true +} diff --git a/region_backend_bucket_basic/motd b/region_backend_bucket_basic/motd new file mode 100644 index 00000000..45a906e8 --- /dev/null +++ b/region_backend_bucket_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/region_backend_bucket_basic/tutorial.md b/region_backend_bucket_basic/tutorial.md new file mode 100644 index 00000000..459d45fd --- /dev/null +++ b/region_backend_bucket_basic/tutorial.md @@ -0,0 +1,79 @@ +# Region Backend Bucket 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/region_backend_bucket_external_lb/backing_file.tf b/region_backend_bucket_external_lb/backing_file.tf new file mode 100644 index 00000000..c60b1199 --- /dev/null +++ b/region_backend_bucket_external_lb/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/region_backend_bucket_external_lb/main.tf b/region_backend_bucket_external_lb/main.tf new file mode 100644 index 00000000..ceb4cfc0 --- /dev/null +++ b/region_backend_bucket_external_lb/main.tf @@ -0,0 +1,34 @@ +resource "google_compute_region_backend_bucket" "external_backend" { + name = "regional-external-backend-${local.name_suffix}" + region = "us-east1" + bucket_name = google_storage_bucket.external_backend.name + load_balancing_scheme = "EXTERNAL_MANAGED" + description = "Regional external backend bucket for static content" + + # REMOVED: compression_mode (Not supported) + # REMOVED: custom_response_headers (Not supported) +} + +resource "google_storage_bucket" "external_backend" { + name = "regional-external-bucket-${local.name_suffix}" + location = "US-EAST1" + force_destroy = true + uniform_bucket_level_access = true + + website { + main_page_suffix = "index.html" + not_found_page = "404.html" + } +} + +resource "google_storage_bucket_object" "index" { + name = "index.html" + bucket = google_storage_bucket.external_backend.name + content = "

Regional External LB Backend Bucket

" +} + +resource "google_storage_bucket_object" "static_asset" { + name = "assets/style.css" + bucket = google_storage_bucket.external_backend.name + content = "body { font-family: Arial, sans-serif; }" +} diff --git a/region_backend_bucket_external_lb/motd b/region_backend_bucket_external_lb/motd new file mode 100644 index 00000000..45a906e8 --- /dev/null +++ b/region_backend_bucket_external_lb/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/region_backend_bucket_external_lb/tutorial.md b/region_backend_bucket_external_lb/tutorial.md new file mode 100644 index 00000000..cb3bf2f3 --- /dev/null +++ b/region_backend_bucket_external_lb/tutorial.md @@ -0,0 +1,79 @@ +# Region Backend Bucket External Lb - 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/region_backend_bucket_internal_lb/backing_file.tf b/region_backend_bucket_internal_lb/backing_file.tf new file mode 100644 index 00000000..c60b1199 --- /dev/null +++ b/region_backend_bucket_internal_lb/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/region_backend_bucket_internal_lb/main.tf b/region_backend_bucket_internal_lb/main.tf new file mode 100644 index 00000000..b7536421 --- /dev/null +++ b/region_backend_bucket_internal_lb/main.tf @@ -0,0 +1,25 @@ +resource "google_compute_region_backend_bucket" "internal_backend" { + name = "regional-internal-backend-${local.name_suffix}" + region = "us-central1" + bucket_name = google_storage_bucket.internal_backend.name + load_balancing_scheme = "INTERNAL_MANAGED" + description = "Regional internal backend bucket for static content" +} + +resource "google_storage_bucket" "internal_backend" { + name = "regional-internal-bucket-${local.name_suffix}" + location = "US-CENTRAL1" + force_destroy = true + uniform_bucket_level_access = true + + website { + main_page_suffix = "index.html" + not_found_page = "404.html" + } +} + +resource "google_storage_bucket_object" "index" { + name = "index.html" + bucket = google_storage_bucket.internal_backend.name + content = "

Regional Internal LB Backend Bucket

" +} diff --git a/region_backend_bucket_internal_lb/motd b/region_backend_bucket_internal_lb/motd new file mode 100644 index 00000000..45a906e8 --- /dev/null +++ b/region_backend_bucket_internal_lb/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/region_backend_bucket_internal_lb/tutorial.md b/region_backend_bucket_internal_lb/tutorial.md new file mode 100644 index 00000000..2651af12 --- /dev/null +++ b/region_backend_bucket_internal_lb/tutorial.md @@ -0,0 +1,79 @@ +# Region Backend Bucket Internal Lb - 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 +```