Terraform を使用してトリガーを作成する

このドキュメントでは、Terraform と google_eventarc_trigger リソースを使用して、次の宛先の Eventarc トリガーを作成する方法について説明します。 Google Cloud

Terraform の使用方法については、Terraform on Google Cloud のドキュメントをご覧ください。

このガイドのコードサンプルでは、Cloud Storage からの直接イベントを転送しますが、任意のイベント プロバイダに適用できます。たとえば、Pub/Sub から Cloud Run に直接イベントを転送する方法については、Terraform のクイックスタートをご覧ください。

始める前に

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  5. Make sure that billing is enabled for your Google Cloud project.

  6. Enable the Cloud Resource Manager and Identity and Access Management (IAM) APIs.

    Enable the APIs

  7. In the Google Cloud console, activate Cloud Shell.

    Activate Cloud Shell

    At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.

  8. Terraform は Cloud Shell 環境に統合されているため、Terraform をインストールしなくても、Cloud Shell を使用して Terraform リソースをデプロイできます。

    Terraform のデプロイを準備する

    Terraform リソースをデプロイする前に、Terraform 構成ファイルを作成する必要があります。Terraform 構成ファイルを使用すると、Terraform 構文を使用してインフラストラクチャの望ましい最終状態を定義できます。

    Cloud Shell を準備する

    Cloud Shell で、Terraform 構成を適用するデフォルトの Google Cloud プロジェクトを設定します。このコマンドは、プロジェクトごとに 1 回だけ実行する必要があります。これは任意のディレクトリで実行できます。

    export GOOGLE_CLOUD_PROJECT=PROJECT_ID

    PROJECT_ID は、 Google Cloud プロジェクトの ID に置き換えます。

    Terraform 構成ファイルに明示的な値を設定すると、環境変数がオーバーライドされます。

    ディレクトリを準備する

    Terraform 構成ファイルには独自のディレクトリ(ルート モジュール)が必要です。Cloud Shell で、ディレクトリを作成し、そのディレクトリ内に新しいファイルを作成します。

    mkdir DIRECTORY && cd DIRECTORY && touch main.tf

    ファイル名の拡張子は .tf にする必要があります。たとえば、このドキュメントでは、ファイルは main.tf と呼ばれます。

    Terraform 構成を定義する

    該当する Terraform コードサンプルを新しく作成した main.tf ファイルにコピーします。必要に応じて、GitHub からコードをコピーします。Terraform スニペットがエンドツーエンドのソリューションの一部である場合は、この方法をおすすめします。

    通常は、構成全体を一度に適用します。ただし、特定のリソースをターゲットにすることもできます。次に例を示します。

    terraform apply -target="google_eventarc_trigger.default"

    Terraform コードサンプルでは、参照変数、リソースの属性、関数の呼び出しなどの代入に補間を使用しています。

    API を有効にする

    Terraform のサンプルでは通常、必要な API がGoogle Cloud プロジェクトで有効になっていることを前提としています。次のコードを使用して API を有効にします。

    Cloud Run

    # Enable Cloud Run API
    resource "google_project_service" "run" {
      service            = "run.googleapis.com"
      disable_on_destroy = false
    }
    
    # Enable Eventarc API
    resource "google_project_service" "eventarc" {
      service            = "eventarc.googleapis.com"
      disable_on_destroy = false
    }
    
    # Enable Pub/Sub API
    resource "google_project_service" "pubsub" {
      service            = "pubsub.googleapis.com"
      disable_on_destroy = false
    }

    GKE

    # Enable GKE API
    resource "google_project_service" "container" {
      service            = "container.googleapis.com"
      disable_on_destroy = false
    }
    
    # Enable Eventarc API
    resource "google_project_service" "eventarc" {
      service            = "eventarc.googleapis.com"
      disable_on_destroy = false
    }
    
    # Enable Pub/Sub API
    resource "google_project_service" "pubsub" {
      service            = "pubsub.googleapis.com"
      disable_on_destroy = false
    }

    Workflows

    # Enable Workflows API
    resource "google_project_service" "workflows" {
      service            = "workflows.googleapis.com"
      disable_on_destroy = false
    }
    
    # Enable Eventarc API
    resource "google_project_service" "eventarc" {
      service            = "eventarc.googleapis.com"
      disable_on_destroy = false
    }
    
    # Enable Pub/Sub API
    resource "google_project_service" "pubsub" {
      service            = "pubsub.googleapis.com"
      disable_on_destroy = false
    }

    サービス アカウントを作成してアクセスを構成する

    すべての Eventarc トリガーは、トリガーの作成時に IAM サービス アカウントに関連付けられます。次のコードを使用して専用のサービス アカウントを作成し、イベントを管理するための特定の Identity and Access Management ロールをユーザー マネージド サービス アカウントに付与します。

    Cloud Run

    # Used to retrieve project information later
    data "google_project" "project" {}
    
    # Create a dedicated service account
    resource "google_service_account" "eventarc" {
      account_id   = "eventarc-trigger-sa"
      display_name = "Eventarc Trigger Service Account"
    }
    
    # Grant permission to receive Eventarc events
    resource "google_project_iam_member" "eventreceiver" {
      project = data.google_project.project.id
      role    = "roles/eventarc.eventReceiver"
      member  = "serviceAccount:${google_service_account.eventarc.email}"
    }
    
    # Grant permission to invoke Cloud Run services
    resource "google_project_iam_member" "runinvoker" {
      project = data.google_project.project.id
      role    = "roles/run.invoker"
      member  = "serviceAccount:${google_service_account.eventarc.email}"
    }

    Pub/Sub サービス エージェントは、Pub/Sub API が有効になると自動的に作成されます。Pub/Sub サービス エージェントが 2021 年 4 月 8 日以前に作成され、サービス アカウントに Cloud Pub/Sub サービス エージェントのロールroles/pubsub.serviceAgent)が付与されていない場合は、サービス エージェントにサービス アカウント トークン作成者のロールroles/iam.serviceAccountTokenCreator)を付与します。詳細については、ロールを作成してサービス エージェントに付与するをご覧ください。

    resource "google_project_iam_member" "tokencreator" {
      project  = data.google_project.project.id
      role     = "roles/iam.serviceAccountTokenCreator"
      member   = "serviceAccount:service-${data.google_project.project.number}@gcp-sa-pubsub.iam.gserviceaccount.com"
    }

    GKE

    1. サービス アカウントを作成する前に、Eventarc が GKE クラスタを管理できるようにします。

      # Used to retrieve project_number later
      data "google_project" "project" {}
      
      # Enable Eventarc to manage GKE clusters
      # This is usually done with: gcloud eventarc gke-destinations init
      #
      # Eventarc creates a separate Event Forwarder pod for each trigger targeting a
      # GKE service, and  requires explicit permissions to make changes to the
      # cluster. This is done by granting permissions to a special service account
      # (the Eventarc P4SA) to manage resources in the cluster. This needs to be done
      # once per Google Cloud project.
      
      # This identity is created with: gcloud beta services identity create --service eventarc.googleapis.com
      # This local variable is used for convenience
      locals {
        eventarc_sa = "serviceAccount:service-${data.google_project.project.number}@gcp-sa-eventarc.iam.gserviceaccount.com"
      }
      
      resource "google_project_iam_member" "computeViewer" {
        project = data.google_project.project.id
        role    = "roles/compute.viewer"
        member  = local.eventarc_sa
      }
      
      resource "google_project_iam_member" "containerDeveloper" {
        project = data.google_project.project.id
        role    = "roles/container.developer"
        member  = local.eventarc_sa
      }
      
      resource "google_project_iam_member" "serviceAccountAdmin" {
        project = data.google_project.project.id
        role    = "roles/iam.serviceAccountAdmin"
        member  = local.eventarc_sa
      }
    2. サービス アカウントを作成します。

      # Create a service account to be used by GKE trigger
      resource "google_service_account" "eventarc_gke_trigger_sa" {
        account_id   = "eventarc-gke-trigger-sa"
        display_name = "Evenarc GKE Trigger Service Account"
      }
      
      # Grant permission to receive Eventarc events
      resource "google_project_iam_member" "eventreceiver" {
        project = data.google_project.project.id
        role    = "roles/eventarc.eventReceiver"
        member  = "serviceAccount:${google_service_account.eventarc_gke_trigger_sa.email}"
      }
      
      # Grant permission to subscribe to Pub/Sub topics
      resource "google_project_iam_member" "pubsubscriber" {
        project = data.google_project.project.id
        role    = "roles/pubsub.subscriber"
        member  = "serviceAccount:${google_service_account.eventarc_gke_trigger_sa.email}"
      }
      

    Workflows

    # Used to retrieve project information later
    data "google_project" "project" {}
    
    # Create a service account for Eventarc trigger and Workflows
    resource "google_service_account" "eventarc" {
      account_id   = "eventarc-workflows-sa"
      display_name = "Eventarc Workflows Service Account"
    }
    
    # Grant permission to invoke Workflows
    resource "google_project_iam_member" "workflowsinvoker" {
      project = data.google_project.project.id
      role    = "roles/workflows.invoker"
      member  = "serviceAccount:${google_service_account.eventarc.email}"
    }
    
    # Grant permission to receive events
    resource "google_project_iam_member" "eventreceiver" {
      project = data.google_project.project.id
      role    = "roles/eventarc.eventReceiver"
      member  = "serviceAccount:${google_service_account.eventarc.email}"
    }
    
    # Grant permission to write logs
    resource "google_project_iam_member" "logwriter" {
      project = data.google_project.project.id
      role    = "roles/logging.logWriter"
      member  = "serviceAccount:${google_service_account.eventarc.email}"
    }

    Pub/Sub サービス エージェントは、Pub/Sub API が有効になると自動的に作成されます。Pub/Sub サービス エージェントが 2021 年 4 月 8 日以前に作成され、サービス アカウントに Cloud Pub/Sub サービス エージェントのロールroles/pubsub.serviceAgent)が付与されていない場合は、サービス エージェントにサービス アカウント トークン作成者のロールroles/iam.serviceAccountTokenCreator)を付与します。詳細については、ロールを作成してサービス エージェントに付与するをご覧ください。

    resource "google_project_iam_member" "tokencreator" {
      project  = data.google_project.project.id
      role     = "roles/iam.serviceAccountTokenCreator"
      member   = "serviceAccount:service-${data.google_project.project.number}@gcp-sa-pubsub.iam.gserviceaccount.com"
    }

    イベント プロバイダとして Cloud Storage バケットを作成する

    次のコードを使用して Cloud Storage バケットを作成し、Cloud Storage サービス エージェントに Pub/Sub パブリッシャーのロールroles/pubsub.publisher)を付与します。

    Cloud Run

    # Cloud Storage bucket names must be globally unique
    resource "random_id" "bucket_name_suffix" {
      byte_length = 4
    }
    
    # Create a Cloud Storage bucket
    resource "google_storage_bucket" "default" {
      name          = "trigger-cloudrun-${data.google_project.project.name}-${random_id.bucket_name_suffix.hex}"
      location      = google_cloud_run_v2_service.default.location
      force_destroy = true
    
      uniform_bucket_level_access = true
    }
    
    # Grant the Cloud Storage service account permission to publish pub/sub topics
    data "google_storage_project_service_account" "gcs_account" {}
    resource "google_project_iam_member" "pubsubpublisher" {
      project = data.google_project.project.id
      role    = "roles/pubsub.publisher"
      member  = "serviceAccount:${data.google_storage_project_service_account.gcs_account.email_address}"
    }

    GKE

    # Cloud Storage bucket names must be globally unique
    resource "random_id" "bucket_name_suffix" {
      byte_length = 4
    }
    
    # Create a Cloud Storage bucket
    resource "google_storage_bucket" "default" {
      name          = "trigger-gke-${data.google_project.project.name}-${random_id.bucket_name_suffix.hex}"
      location      = "us-central1"
      force_destroy = true
    
      uniform_bucket_level_access = true
    }
    
    # Grant the Cloud Storage service account permission to publish pub/sub topics
    data "google_storage_project_service_account" "gcs_account" {}
    resource "google_project_iam_member" "pubsubpublisher" {
      project = data.google_project.project.id
      role    = "roles/pubsub.publisher"
      member  = "serviceAccount:${data.google_storage_project_service_account.gcs_account.email_address}"
    }

    Workflows

    # Cloud Storage bucket names must be globally unique
    resource "random_id" "bucket_name_suffix" {
      byte_length = 4
    }
    
    # Create a Cloud Storage bucket
    resource "google_storage_bucket" "default" {
      name          = "trigger-workflows-${data.google_project.project.name}-${random_id.bucket_name_suffix.hex}"
      location      = google_workflows_workflow.default.region
      force_destroy = true
    
      uniform_bucket_level_access = true
    }
    
    # Grant the Cloud Storage service account permission to publish Pub/Sub topics
    data "google_storage_project_service_account" "gcs_account" {}
    resource "google_project_iam_member" "pubsubpublisher" {
      project = data.google_project.project.id
      role    = "roles/pubsub.publisher"
      member  = "serviceAccount:${data.google_storage_project_service_account.gcs_account.email_address}"
    }

    イベント ターゲットとなるイベント レシーバーを作成する

    次のいずれかの Terraform リソースを使用して、イベント受信側を作成します。

    Cloud Run

    Eventarc トリガーのイベントの宛先として Cloud Run サービスを作成します。

    # Deploy Cloud Run service
    resource "google_cloud_run_v2_service" "default" {
      name     = "hello-events"
      location = "us-central1"
    
      deletion_protection = false # set to "true" in production
    
      template {
        containers {
          # This container will log received events
          image = "us-docker.pkg.dev/cloudrun/container/hello"
        }
        service_account = google_service_account.eventarc.email
      }
    
      depends_on = [google_project_service.run]
    }

    GKE

    このガイドを簡素化するため、Terraform 構成を適用する間に、Terraform の外部でイベントの宛先として Google Kubernetes Engine サービスを作成します。

    1. この Google Cloud プロジェクトでトリガーを作成したことがない場合は、次のコマンドを実行して Eventarc サービス エージェントを作成します。

      gcloud beta services identity create --service eventarc.googleapis.com
    2. GKE クラスタを作成します。

      # Create an auto-pilot GKE cluster
      resource "google_container_cluster" "gke_cluster" {
        name     = "eventarc-cluster"
        location = "us-central1"
      
        enable_autopilot = true
      
        depends_on = [
          google_project_service.container
        ]
      }
    3. ビルド済みの Cloud Run イメージ us-docker.pkg.dev/cloudrun/container/hello を使用して、HTTP リクエストを受信し、イベントをログに記録する Kubernetes Service を GKE にデプロイします。

      1. クラスタとやり取りするために必要な認証情報を取得します。

        gcloud container clusters get-credentials eventarc-cluster \
           --region=us-central1
        
      2. hello-gke という名前の Deployment を作成します。

        kubectl create deployment hello-gke \
           --image=us-docker.pkg.dev/cloudrun/container/hello
        
      3. Deployment を Kubernetes Service として公開します。

        kubectl expose deployment hello-gke \
           --type ClusterIP --port 80 --target-port 8080
        
      4. Pod が実行されていることを確認します。

        kubectl get pods
        

        出力例を以下に示します。

        NAME                         READY   STATUS    RESTARTS   AGE
        hello-gke-5b6574b4db-rzzcr   1/1     Running   0          2m45s
        

        STATUSPending または ContainerCreating の場合、Pod はデプロイされています。デプロイが完了するまで 1 分ほど待ってから、もう一度ステータスを確認します。

      5. サービスが実行されていることを確認します。

        kubectl get svc
        

        出力例を以下に示します。

        NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)   AGE
        hello-gke    ClusterIP   34.118.230.123   <none>        80/TCP    4m46s
        kubernetes   ClusterIP   34.118.224.1     <none>        443/TCP   14m
        

    Workflows

    Cloud Storage バケットでオブジェクトが更新されたときに実行されるワークフローをデプロイします。

    # Create a workflow
    resource "google_workflows_workflow" "default" {
      name            = "storage-workflow-tf"
      region          = "us-central1"
      description     = "Workflow that returns information about storage events"
      service_account = google_service_account.eventarc.email
    
      deletion_protection = false # set to "true" in production
    
      # Note that $$ is needed for Terraform
      source_contents = <<EOF
      main:
        params: [event]
        steps:
          - log_event:
              call: sys.log
              args:
                text: $${event}
                severity: INFO
          - gather_data:
              assign:
                - bucket: $${event.data.bucket}
                - name: $${event.data.name}
                - message: $${"Received event " + event.type + " - " + bucket + ", " + name}
          - return_data:
              return: $${message}
      EOF
    
      depends_on = [
        google_project_service.workflows
      ]
    }

    Eventarc トリガーを定義する

    Eventarc トリガーは、イベント プロバイダからイベントの宛先にイベントを転送します。google_eventarc_trigger リソースを使用して matching_criteria で CloudEvents 属性を指定し、イベントをフィルタリングします。詳細については、特定のプロバイダ、イベントタイプ、宛先にトリガーを作成するの手順をご覧ください。すべてのフィルタに一致するイベントが宛先に送信されます。

    Cloud Run

    Cloud Storage イベントを hello-event Cloud Run サービスに転送する Eventarc トリガーを作成します。

    # Create an Eventarc trigger, routing Cloud Storage events to Cloud Run
    resource "google_eventarc_trigger" "default" {
      name     = "trigger-storage-cloudrun-tf"
      location = google_cloud_run_v2_service.default.location
    
      # Capture objects changed in the bucket
      matching_criteria {
        attribute = "type"
        value     = "google.cloud.storage.object.v1.finalized"
      }
      matching_criteria {
        attribute = "bucket"
        value     = google_storage_bucket.default.name
      }
    
      # Send events to Cloud Run
      destination {
        cloud_run_service {
          service = google_cloud_run_v2_service.default.name
          region  = google_cloud_run_v2_service.default.location
        }
      }
    
      service_account = google_service_account.eventarc.email
      depends_on = [
        google_project_service.eventarc,
        google_project_iam_member.pubsubpublisher
      ]
    }

    GKE

    Cloud Storage イベントを hello-gke GKE サービスに転送する Eventarc トリガーを作成します。

    # Create an Eventarc trigger, routing Storage events to GKE
    resource "google_eventarc_trigger" "default" {
      name     = "trigger-storage-gke-tf"
      location = "us-central1"
    
      # Capture objects changed in the bucket
      matching_criteria {
        attribute = "type"
        value     = "google.cloud.storage.object.v1.finalized"
      }
      matching_criteria {
        attribute = "bucket"
        value     = google_storage_bucket.default.name
      }
    
      # Send events to GKE service
      destination {
        gke {
          cluster   = "eventarc-cluster"
          location  = "us-central1"
          namespace = "default"
          path      = "/"
          service   = "hello-gke"
        }
      }
    
      service_account = google_service_account.eventarc_gke_trigger_sa.email
    }

    Workflows

    Cloud Storage イベントを storage-workflow-tf という名前のワークフローに転送する Eventarc トリガーを作成します。

    # Create an Eventarc trigger, routing Cloud Storage events to Workflows
    resource "google_eventarc_trigger" "default" {
      name     = "trigger-storage-workflows-tf"
      location = google_workflows_workflow.default.region
    
      # Capture objects changed in the bucket
      matching_criteria {
        attribute = "type"
        value     = "google.cloud.storage.object.v1.finalized"
      }
      matching_criteria {
        attribute = "bucket"
        value     = google_storage_bucket.default.name
      }
    
      # Send events to Workflows
      destination {
        workflow = google_workflows_workflow.default.id
      }
    
      service_account = google_service_account.eventarc.email
    
      depends_on = [
        google_project_service.eventarc,
        google_project_service.workflows,
      ]
    }

    Terraform を適用

    Terraform CLI を使用して、構成ファイルに基づいてインフラストラクチャをプロビジョニングします。

    Terraform 構成を適用または削除する方法については、基本的な Terraform コマンドをご覧ください。

    1. Terraform を初期化します。これは、ディレクトリごとに 1 回だけ行います。

      terraform init

      最新バージョンの Google プロバイダを使用する場合は、-upgrade オプションを使用します。

      terraform init -upgrade
    2. 構成を確認して、Terraform が作成または更新するリソースが想定どおりであることを確認します。

      terraform plan

      必要に応じて構成を修正します。

    3. 次のコマンドを実行し、プロンプトで「yes」と入力して、Terraform 構成を適用します。

      terraform apply

      Terraform に「Apply complete!」というメッセージが表示されるまで待ちます。

    リソースの作成を確認する

    Cloud Run

    1. サービスが作成されたことを確認します。

      gcloud run services list --region us-central1
      
    2. トリガーが作成されたことを確認します。

      gcloud eventarc triggers list --location us-central1
      

      出力例を以下に示します。

      NAME: trigger-storage-cloudrun-tf
      TYPE: google.cloud.storage.object.v1.finalized
      DESTINATION: Cloud Run service: hello-events
      ACTIVE: Yes
      LOCATION: us-central1
      

    GKE

    1. サービスが作成されたことを確認します。

      kubectl get service hello-gke
      
    2. トリガーが作成されたことを確認します。

      gcloud eventarc triggers list --location us-central1
      

      出力例を以下に示します。

      NAME: trigger-storage-gke-tf
      TYPE: google.cloud.storage.object.v1.finalized
      DESTINATION: GKE: hello-gke
      ACTIVE: Yes
      LOCATION: us-central1
      

    Workflows

    1. ワークフローが作成されたことを確認します。

      gcloud workflows list --location us-central1
      
    2. Eventarc トリガーが作成されたことを確認します。

      gcloud eventarc triggers list --location us-central1
      

      出力例を以下に示します。

      NAME: trigger-storage-workflows-tf
      TYPE: google.cloud.storage.object.v1.finalized
      DESTINATION: Workflows: storage-workflow-tf
      ACTIVE: Yes
      LOCATION: us-central1
      

    イベントを生成して表示する

    イベントを生成し、Eventarc トリガーが期待どおりに動作していることを確認します。

    1. 前に作成した Cloud Storage バケットの名前を取得します。

      gcloud storage ls
      
    2. テキスト ファイルを Cloud Storage バケットにアップロードします。

      echo "Hello World" > random.txt
      gcloud storage cp random.txt gs://BUCKET_NAME/random.txt
      

      BUCKET_NAME は、前の手順で取得した Cloud Storage バケット名に置き換えます。次に例を示します。

      gcloud storage cp random.txt gs://BUCKET_NAME/random.txt

      アップロードによりイベントが生成され、イベント レシーバ サービスはイベントのメッセージをロギングします。

    3. イベントが受信されたことを確認します。

      Cloud Run

      1. サービスによって作成されたログエントリをフィルタします。

        gcloud logging read 'jsonPayload.message: "Received event of type google.cloud.storage.object.v1.finalized."'
        
      2. 次のようなログエントリを探します。

        Received event of type google.cloud.storage.object.v1.finalized.
        Event data: { "kind": "storage#object", "id": "trigger-cloudrun-BUCKET_NAME/random.txt", ...}
        

      GKE

      1. Pod ID を見つけます。

        POD_NAME=$(kubectl get pods -o custom-columns=":metadata.name" --no-headers)
        

        このコマンドは、kubectlフォーマットされた出力を使用します。

      2. Pod のログを確認します。

        kubectl logs $POD_NAME
        
      3. 次のようなログエントリを探します。

        {"severity":"INFO","eventType":"google.cloud.storage.object.v1.finalized","message":
        "Received event of type google.cloud.storage.object.v1.finalized. Event data: ...}
        

      Workflows

      1. 直近の 5 つの実行を一覧表示して、Workflows の実行がトリガーされたことを確認します。

        gcloud workflows executions list storage-workflow-tf --limit=5
        

        出力には、NAMESTATESTART_TIMEEND_TIME の実行リストが含まれます。

      2. 最新の実行の結果を取得します。

        EXECUTION_NAME=$(gcloud workflows executions list storage-workflow-tf --limit=1 --format "value(name)")
        gcloud workflows executions describe $EXECUTION_NAME
        
      3. 出力は次のようになります。

        ...
        result: '"Received event google.cloud.storage.object.v1.finalized - BUCKET_NAME, random.txt"'
        startTime: '2024-12-13T17:23:50.451316533Z'
        state: SUCCEEDED
        ...
        

    クリーンアップ

    以前に Terraform 構成で適用されたリソースを削除するために、次のコマンドを実行してプロンプトで「yes」と入力します。

    terraform destroy

    Google Cloud プロジェクトを削除して、料金が発生しないようにすることもできます。 Google Cloud プロジェクトを削除すると、そのプロジェクト内で使用されているすべてのリソースに対する課金が停止します。

    1. In the Google Cloud console, go to the Manage resources page.

      Go to Manage resources

    2. In the project list, select the project that you want to delete, and then click Delete.
    3. In the dialog, type the project ID, and then click Shut down to delete the project.

    次のステップ