Link Search Menu Expand Document

google

google_cloud_run_service/noauth/

destroy.sh

            #!/bin/bash
../../../bin/destroy.sh google
 

main.tf

            # Summary: Creates a GCP Cloud Run Service accessible without auth

# Documentation: https://www.terraform.io/docs/language/settings/index.html
terraform {
  required_version = ">= 1.0.0"
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "~> 3.0"
    }
  }
}

# Documentation: https://www.terraform.io/docs/language/values/variables.html
variable "project_id" {
  type = string
}

# Documentation: https://www.terraform.io/docs/language/providers/requirements.html
provider "google" {
  project = var.project_id
  region  = "us-central1"
  zone    = "us-central1-a"
}

# GCP Cloud Run Service
# Documentation: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/cloud_run_service
resource "google_cloud_run_service" "changeme_noauth_cloud_run_service" {
  name     = "changeme-noauth-cloud-run-service"
  location = "us-central1"

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

# Documentation: https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/iam_policy
data "google_iam_policy" "changeme_noauth_iam_policy" {
  binding {
    role = "roles/run.invoker"
    members = [
      "allUsers",
    ]
  }
}

# Documentation: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/cloud_run_service_iam
resource "google_cloud_run_service_iam_policy" "changeme_noauth" {
  location = google_cloud_run_service.changeme_noauth_cloud_run_service.location
  project  = google_cloud_run_service.changeme_noauth_cloud_run_service.project
  service  = google_cloud_run_service.changeme_noauth_cloud_run_service.name

  policy_data = data.google_iam_policy.changeme_noauth_iam_policy.policy_data
}
 

run.sh

            #!/bin/bash
../../../bin/apply.sh google
 

google_cloud_run_service/simple/

destroy.sh

            #!/bin/bash
../../../bin/destroy.sh google
 

main.tf

            # Summary: Creates the simplest GCP Cloud Run Service

# Documentation: https://www.terraform.io/docs/language/settings/index.html
terraform {
  required_version = ">= 1.0.0"
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "~> 3.0"
    }
  }
}

# Documentation: https://www.terraform.io/docs/language/values/variables.html
variable "project_id" {
  type = string
}

# Documentation: https://www.terraform.io/docs/language/providers/requirements.html
provider "google" {
  project = var.project_id
  region  = "us-central1"
  zone    = "us-central1-a"
}

# GCP Cloud Run Service
# Documentation: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/cloud_run_service
resource "google_cloud_run_service" "changeme_simple_cloud_run_service" {
  name     = "changeme-simple-cloud-run-service"
  location = "us-central1"

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

  traffic {
    percent         = 100
    latest_revision = true
  }
}
 

run.sh

            #!/bin/bash
../../../bin/apply.sh google
 

google_compute_attached_disk/count/

destroy.sh

            #!/bin/bash
../../../bin/destroy.sh google
 

main.tf

            # Summary: Uses the 'count' feature to create multiple disks attached to multiple VM instances (with google_compute_attached_disk)

# Documentation: https://www.terraform.io/docs/language/settings/index.html
terraform {
  required_version = ">= 1.0.0"
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "~> 3.0"
    }
  }
}

# Documentation: https://www.terraform.io/docs/language/values/variables.html
variable "project_id" {
  type = string
}

# Documentation: https://www.terraform.io/docs/language/providers/requirements.html
provider "google" {
  project = var.project_id
  region  = "us-central1"
  zone    = "us-central1-a"
}

# Documentation: https://www.terraform.io/docs/language/values/variables.html
variable "changeme_google_attached_disk_count_number_of_instances" {
  type    = number
  default = 3
}

# Attach disks to instances
# Documentation: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_attached_disk
resource "google_compute_attached_disk" "changeme_count_attached_disk" {
  # Documentation: https://www.terraform.io/docs/language/meta-arguments/count.html
  count    = var.changeme_google_attached_disk_count_number_of_instances
  disk     = google_compute_disk.changeme_count_attached_disk_disk[count.index].id
  instance = google_compute_instance.changeme_count_attached_disk_instance[count.index].id
}

# Compute Instances
# Documentation: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_instance
resource "google_compute_instance" "changeme_count_attached_disk_instance" {
  name         = "changeme-count-attached-disk-instance-${count.index}"
  count        = var.changeme_google_attached_disk_count_number_of_instances
  machine_type = "f1-micro"
  zone         = "us-central1-a"

  boot_disk {
    initialize_params {
      image = "debian-cloud/debian-10"
    }
  }

  network_interface {
    # Explanation: A default network is created for all GCP projects
    network = "default"
    access_config {
    }
  }
}

# Persistent disks
# Documentation: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_disk
resource "google_compute_disk" "changeme_count_attached_disk_disk" {
  name                      = "changeme-count-attached-disk-disk-${count.index}"
  count                     = var.changeme_google_attached_disk_count_number_of_instances
  type                      = "pd-ssd"
  zone                      = "us-central1-a"
  size                      = 4
  physical_block_size_bytes = 4096
}
 

run.sh

            #!/bin/bash
../../../bin/apply.sh google
 

google_compute_attached_disk/simple/

destroy.sh

            #!/bin/bash
../../../bin/destroy.sh google
 

main.tf

            # Summary: Attaches a persistent disk to an instance with google_compute_attached_disk resource type

# Documentation: https://www.terraform.io/docs/language/settings/index.html
terraform {
  required_version = ">= 1.0.0"
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "~> 3.0"
    }
  }
}

# Documentation: https://www.terraform.io/docs/language/values/variables.html
variable "project_id" {
  type = string
}

# Documentation: https://www.terraform.io/docs/language/providers/requirements.html
provider "google" {
  project = var.project_id
  region  = "us-central1"
  zone    = "us-central1-a"
}

# Attach a disk to an instance
# Documentation: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_attached_disk
resource "google_compute_attached_disk" "changeme_simple_attached_disk" {
  disk     = google_compute_disk.changeme_simple_attached_disk_disk.id
  instance = google_compute_instance.changeme_simple_attached_disk_instance.id
}

# Compute Instance
# Documentation: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_instance
resource "google_compute_instance" "changeme_simple_attached_disk_instance" {
  name         = "changeme-simple-attached-disk-instance"
  machine_type = "f1-micro"
  zone         = "us-central1-a"

  boot_disk {
    initialize_params {
      image = "debian-cloud/debian-10"
    }
  }

  network_interface {
    # Explanation: A default network is created for all GCP projects
    network = "default"
    access_config {
    }
  }
}

# Persistent disks
# Documentation: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_disk
resource "google_compute_disk" "changeme_simple_attached_disk_disk" {
  name = "changeme-simple-attached-disk-disk"
  type = "pd-ssd"
  zone = "us-central1-a"
  size = 4
  labels = {
    environment = "dev"
  }
  physical_block_size_bytes = 4096
}
 

run.sh

            #!/bin/bash
../../../bin/apply.sh google
 

google_compute_disk/simple/

destroy.sh

            #!/bin/bash
../../../bin/destroy.sh google
 

main.tf

            # Summary: Creates a persistent disk

# Documentation: https://www.terraform.io/docs/language/settings/index.html
terraform {
  required_version = ">= 1.0.0"
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "~> 3.0"
    }
  }
}

# Documentation: https://www.terraform.io/docs/language/values/variables.html
variable "project_id" {
  type = string
}

# Documentation: https://www.terraform.io/docs/language/providers/requirements.html
provider "google" {
  project = var.project_id
  region  = "us-central1"
  zone    = "us-central1-a"
}

# Persistent disks
# Documentation: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_disk
resource "google_compute_disk" "changeme_simple_disk" {
  name = "changeme-simple-disk"
  type = "pd-ssd"
  zone = "us-central1-a"
  size = 4
  labels = {
    environment = "dev"
  }
  physical_block_size_bytes = 4096
}
 

run.sh

            #!/bin/bash
../../../bin/apply.sh google
 

google_compute_instance/simple/

destroy.sh

            #!/bin/bash
../../../bin/destroy.sh google
 

main.tf

            # Summary: Creates the simplest VM instance

# Documentation: https://www.terraform.io/docs/language/settings/index.html
terraform {
  required_version = ">= 1.0.0"
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "~> 3.0"
    }
  }
}

# Documentation: https://www.terraform.io/docs/language/providers/requirements.html
provider "google" {
  project = var.project_id
  region  = "us-central1"
  zone    = "us-central1-a"
}

# Documentation: https://www.terraform.io/docs/language/values/variables.html
variable "project_id" {
  type = string
}

# Compute Instance
# Documentation: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_instance
resource "google_compute_instance" "changeme_simple_instance" {
  name         = "changeme-simple-instance"
  machine_type = "f1-micro"
  zone         = "us-central1-a"

  boot_disk {
    initialize_params {
      image = "debian-cloud/debian-10"
    }
  }

  network_interface {
    # Explanation: A default network is created for all GCP projects
    network = "default"
    access_config {
    }
  }
}
 

run.sh

            #!/bin/bash
../../../bin/apply.sh google
 

google_compute_network/simple/

destroy.sh

            #!/bin/bash
../../../bin/destroy.sh google
 

main.tf

            # Summary: A simple GCP VPC (google_compute_network)

# Documentation: https://www.terraform.io/docs/language/settings/index.html
terraform {
  required_version = ">= 1.0.0"
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "~> 3.0"
    }
  }
}

# Documentation: https://www.terraform.io/docs/language/values/variables.html
variable "project_id" {
  type = string
}

# Documentation: https://www.terraform.io/docs/language/providers/requirements.html
provider "google" {
  project = var.project_id
  region  = "us-central1"
  zone    = "us-central1-c"
}

# Documentation: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_network
resource "google_compute_network" "changeme_simple_vpc" {
  name                    = "changeme-simple-vpc"
  auto_create_subnetworks = "false"
}

# Documentation: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_subnetwork
resource "google_compute_subnetwork" "changeme_simple_vpc_subnet_1" {
  name          = "${google_compute_network.changeme_simple_vpc.name}-subnet-1"
  region        = "us-central1"
  network       = google_compute_network.changeme_simple_vpc.name
  ip_cidr_range = "10.10.0.0/24"
}
 

run.sh

            #!/bin/bash
../../../bin/apply.sh google
 

google_container_cluster/autopilot/

destroy.sh

            #!/bin/bash
../../../bin/destroy.sh google
 

main.tf

            # Summary: Creates a GKE (Google Kubernetes Engine) Autopilot cluster.

# Documentation: https://www.terraform.io/docs/language/settings/index.html
terraform {
  required_version = ">= 1.0.0"
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "~> 3.0"
    }
  }
}

# Documentation: https://www.terraform.io/docs/language/values/variables.html
variable "project_id" {
  type = string
}

# Documentation: https://www.terraform.io/docs/language/providers/requirements.html
provider "google" {
  project = var.project_id
  region  = "us-central1"
  zone    = "us-central1-a"
}

# GKE
# Documentation: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_cluster
resource "google_container_cluster" "changeme_autopilot_cluster" {
  name     = "changeme-autopilot-cluster"
  location = "us-central1"

  # Documentation: https://cloud.google.com/kubernetes-engine/docs/concepts/autopilot-overview
  enable_autopilot = true
}
 

run.sh

            #!/bin/bash
../../../bin/apply.sh google
 

google_container_cluster/cluster_and_deployment/

destroy.sh

            #!/bin/bash
../../../bin/destroy.sh google
 

main.tf

            # Summary: Creates a GKE (Google Kubernetes Engine) cluster, connects the Terraform Kubernetes Provider to it, and creates a k8s deployment.

# Documentation: https://www.terraform.io/docs/language/settings/index.html
terraform {
  required_version = ">= 1.0.0"
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "~> 3.0"
    }
  }
}

# Documentation: https://www.terraform.io/docs/language/values/variables.html
variable "project_id" {
  type = string
}

# Documentation: https://www.terraform.io/docs/language/providers/requirements.html
provider "google" {
  project = var.project_id
  region  = "us-central1"
  zone    = "us-central1-a"
}

# GKE
# Documentation: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_cluster
resource "google_container_cluster" "changeme_cluster_and_deployment_cluster" {
  name               = "changeme-cluster-and-deployment-cluster"
  location           = "us-central1-a"
  initial_node_count = 1
  node_config {
    preemptible  = true
    machine_type = "n1-standard-1"
  }
}

# Kubernetes
# Documentation: https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/using_gke_with_terraform

# # Explanation: Retrieve an access token as the Terraform runner
data "google_client_config" "changeme_cluster_and_deployment_provider" {}

# Documentation: https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs
provider "kubernetes" {
  host  = "https://${google_container_cluster.changeme_cluster_and_deployment_cluster.endpoint}"
  token = data.google_client_config.changeme_cluster_and_deployment_provider.access_token
  cluster_ca_certificate = base64decode(
    google_container_cluster.changeme_cluster_and_deployment_cluster.master_auth[0].cluster_ca_certificate,
  )
}

# Deployment
# Documentation: https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/deployment
resource "kubernetes_deployment" "changeme_cluster_and_deployment_deployment" {
  metadata {
    name = "changeme-cluster-and-deployment-deployment"
    labels = {
      app = "changeme-cluster-and-deployment-app"
    }
  }

  spec {
    replicas = 1
    selector {
      match_labels = {
        app = "changeme-cluster-and-deployment-app"
      }
    }
    template {
      metadata {
        labels = {
          app = "changeme-cluster-and-deployment-app"
        }
      }
      spec {
        container {
          image = "nginx"
          name  = "nginx"
        }
      }
    }
  }
}
 

run.sh

            #!/bin/bash
../../../bin/apply.sh google
 

google_container_cluster/separate_node_pool/

destroy.sh

            #!/bin/bash
../../../bin/destroy.sh google
 

main.tf

            # Summary: Creates a GKE (Google Kubernetes Engine) cluster with a separatelly managed node pool.

# Documentation: https://www.terraform.io/docs/language/settings/index.html
terraform {
  required_version = ">= 1.0.0"
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "~> 3.0"
    }
  }
}

# Documentation: https://www.terraform.io/docs/language/values/variables.html
variable "project_id" {
  type = string
}

# Documentation: https://www.terraform.io/docs/language/providers/requirements.html
provider "google" {
  project = var.project_id
  region  = "us-central1"
  zone    = "us-central1-a"
}

# GKE
# Documentation: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_cluster
resource "google_container_cluster" "changeme_separate_node_pool_cluster" {
  name     = "changeme-separate-node-pool-cluster"
  location = "us-central1-a"

  # Explanation: Cannot create a cluster with no node pool. So we create a pool and immediately delete it.
  remove_default_node_pool = true
  initial_node_count       = 1
}

# Node Pool in a GKE cluster (managed separately)
# Documentation: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_node_pool
resource "google_container_node_pool" "changeme_separate_node_pool" {
  name       = "changeme-separate-node-pool"
  location   = "us-central1-a"
  cluster    = google_container_cluster.changeme_separate_node_pool_cluster.name
  node_count = 1

  node_config {
    preemptible  = true
    machine_type = "n1-standard-1"
  }
}
 

run.sh

            #!/bin/bash
../../../bin/apply.sh google
 

google_container_cluster/simple/

destroy.sh

            #!/bin/bash
../../../bin/destroy.sh google
 

main.tf

            # Summary: Creates the simplest GKE (Google Kubernetes Engine) cluster.

# Documentation: https://www.terraform.io/docs/language/settings/index.html
terraform {
  required_version = ">= 1.0.0"
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "~> 3.0"
    }
  }
}

# Documentation: https://www.terraform.io/docs/language/values/variables.html
variable "project_id" {
  type = string
}

# Documentation: https://www.terraform.io/docs/language/providers/requirements.html
provider "google" {
  project = var.project_id
  region  = "us-central1"
  zone    = "us-central1-a"
}

# GKE
# Documentation: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_cluster
resource "google_container_cluster" "changeme_simple_cluster" {
  name               = "changeme-simple-cluster"
  location           = "us-central1-a"
  initial_node_count = 1
  node_config {
    preemptible  = true
    machine_type = "n1-standard-1"
  }
}
 

run.sh

            #!/bin/bash
../../../bin/apply.sh google
 

google_container_cluster/vpc_native_cluster/

destroy.sh

            #!/bin/bash
../../../bin/destroy.sh google
 

import.sh

            #!/bin/bash

cd "${0%/*}" || exit 1

echo '================================================================================'
echo "In $(pwd), running $0"
echo '================================================================================'

GCP_PROJECT="$(gcloud config get-value project)"
GCP_VPCS="changeme_vpc_native_cluster_vpc changeme_vpc_native_cluster_subnet"

for vpc in $GCP_VPCS
do
  vpc_name="$(echo "${vpc}" | tr '_' '-')"
  if [[ $(gcloud compute networks list --filter='name~^'"${vpc_name}"'$' 2>&1 | grep -v ^NAME | grep -v ^Listed.0 | awk '{print $1}') != '' ]]
  then
    terraform import -var project_id="${GCP_PROJECT}" "google_compute_network.${vpc}" "${vpc_name}"
  fi
done
 

main.tf

            # Summary: Creates a VPC-native GKE (Google Kubernetes Engine) cluster .
# Documentation: https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/using_gke_with_terraform#vpc-native-clusters

# Documentation: https://www.terraform.io/docs/language/settings/index.html
terraform {
  required_version = ">= 1.0.0"
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "~> 3.0"
    }
  }
}

# Documentation: https://www.terraform.io/docs/language/values/variables.html
variable "project_id" {
  type = string
}

# Documentation: https://www.terraform.io/docs/language/providers/requirements.html
provider "google" {
  project = var.project_id
  region  = "us-central1"
  zone    = "us-central1-a"
}

# Google VPC network
# Documentation: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_network
resource "google_compute_network" "changeme_vpc_native_cluster_vpc" {
  name                    = "changeme-vpc-native-cluster-vpc"
  auto_create_subnetworks = false
}

# Subnetwork
# Documentation: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_subnetwork
resource "google_compute_subnetwork" "changeme_vpc_native_cluster_subnet" {
  name          = "changeme-vpc-native-cluster-subnet"
  ip_cidr_range = "10.2.0.0/16"
  region        = "us-central1"
  network       = google_compute_network.changeme_vpc_native_cluster_vpc.id
  secondary_ip_range {
    range_name    = "services-range"
    ip_cidr_range = "192.168.1.0/24"
  }

  secondary_ip_range {
    range_name    = "pod-ranges"
    ip_cidr_range = "192.168.64.0/22"
  }
}

# GKE
# Documentation: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_cluster
resource "google_container_cluster" "changeme_vpc_native_cluster" {
  name               = "changeme-vpc-native-cluster"
  location           = "us-central1-a"
  initial_node_count = 1

  network    = google_compute_network.changeme_vpc_native_cluster_vpc.id
  subnetwork = google_compute_subnetwork.changeme_vpc_native_cluster_subnet.id

  ip_allocation_policy {
    cluster_secondary_range_name  = "services-range"
    services_secondary_range_name = google_compute_subnetwork.changeme_vpc_native_cluster_subnet.secondary_ip_range.1.range_name
  }

  node_config {
    preemptible  = true
    machine_type = "n1-standard-1"
  }
}
 

run.sh

            #!/bin/bash
../../../bin/apply.sh google
 

google_dns_managed_zone/private/

destroy.sh

            #!/bin/bash
../../../bin/destroy.sh google
 

main.tf

            # Summary: Creates a private DNS managed zone

# Documentation: https://www.terraform.io/docs/language/settings/index.html
terraform {
  required_version = ">= 1.0.0"
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "~> 3.0"
    }
  }
}

# Documentation: https://www.terraform.io/docs/language/providers/requirements.html
provider "google" {
  project = var.project_id
  region  = "us-central1"
  zone    = "us-central1-a"
}

# Documentation: https://www.terraform.io/docs/language/values/variables.html
variable "project_id" {
  type = string
}

# DNS Managed Zone
# Documentation: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/dns_managed_zone
resource "google_dns_managed_zone" "changeme_private_zone" {
  name       = "changeme-private-zone"
  dns_name   = "changeme-private-zone.com."
  visibility = "private"
}
 

run.sh

            #!/bin/bash
../../../bin/apply.sh google
 

google_dns_managed_zone/public/

destroy.sh

            #!/bin/bash
../../../bin/destroy.sh google
 

main.tf

            # Summary: Creates a public DNS managed zone

# Documentation: https://www.terraform.io/docs/language/settings/index.html
terraform {
  required_version = ">= 1.0.0"
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "~> 3.0"
    }
  }
}

# Documentation: https://www.terraform.io/docs/language/providers/requirements.html
provider "google" {
  project = var.project_id
  region  = "us-central1"
  zone    = "us-central1-a"
}

# Documentation: https://www.terraform.io/docs/language/values/variables.html
variable "project_id" {
  type = string
}

# DNS Managed Zone
# Documentation: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/dns_managed_zone
resource "google_dns_managed_zone" "changeme_public_zone" {
  name     = "changeme-public-zone"
  dns_name = "changeme-public-zone.com."
}
 

run.sh

            #!/bin/bash
../../../bin/apply.sh google
 

google_sql_database/simple/

destroy.sh

            #!/bin/bash
../../../bin/destroy.sh google 

main.tf

            # Summary: Creates a SQL database instance on the gcp console

# Documentation: https://www.terraform.io/docs/language/settings/index.html
terraform {
  required_version = ">= 1.0.0"
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "~> 3.0"
    }
  }
}

# Documentation: https://www.terraform.io/docs/language/values/variables.html
variable "project_id" {
  type = string
}

# Documentation: https://www.terraform.io/docs/language/providers/requirements.html
provider "google" {
  project = var.project_id
  region  = "us-central1"
  zone    = "us-central1-a"
}

# SQL database instance
# Documentation: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database_instance

resource "google_sql_database" "changeme_sql_database" {
  name     = "changeme_database"
  project  = var.project_id
  instance = google_sql_database_instance.changeme_simple_sql_database_instance.name
}

resource "google_sql_database_instance" "changeme_simple_sql_database_instance" {
  name             = "changedb"
  database_version = "POSTGRES_11"
  region           = "us-central1"
  settings {
    tier = "db-f1-micro"
  }
  deletion_protection = false
}
 

run.sh

            #!/bin/bash
../../../bin/apply.sh google 

google_storage_bucket/simple/

destroy.sh

            #!/bin/bash
../../../bin/destroy.sh google
 

main.tf

            # Summary: Creates a GCS (Google Cloud Storage) bucket

# Documentation: https://www.terraform.io/docs/language/settings/index.html
terraform {
  required_version = ">= 1.0.0"
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "~> 3.0"
    }
  }
}

# Documentation: https://www.terraform.io/docs/language/values/variables.html
variable "project_id" {
  type = string
}

# Documentation: https://www.terraform.io/docs/language/providers/requirements.html
provider "google" {
  project = var.project_id
  region  = "us-central1"
  zone    = "us-central1-a"
}

# Explanation: This resource is not necessary for the creation of an GCS bucket, but is here to ensure that
# the GCS bucket name is unique.
#
# Documentation: https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/id
resource "random_id" "changeme_google_storage_bucket_simple_name" {
  byte_length = 16
}

# GCS (Google Cloud Storage) bucket
# Documentation: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/storage_bucket
resource "google_storage_bucket" "changeme_google_storage_simple_bucket" {
  name     = "changeme-${random_id.changeme_google_storage_bucket_simple_name.hex}"
  location = "US"
}
 

run.sh

            #!/bin/bash
../../../bin/apply.sh google