SaaS ランタイムを使用してサービス インスタンスをデプロイする

SaaS ランタイムを使用してサービス インスタンスをデプロイする方法について説明します。このクイックスタートの例では、サービス インスタンスは VM です。

始める前に

  1. ログイン Google アカウントにログインします。

    Google アカウントをまだお持ちでない場合は、 新しいアカウントを登録します

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

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the SaaS Runtime, Artifact Registry, Infrastructure Manager, Developer Connect, Cloud Build, and Cloud Storage APIs.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the APIs

  5. Create a service account:

    1. Ensure that you have the Create Service Accounts IAM role (roles/iam.serviceAccountCreator) and the Project IAM Admin role (roles/resourcemanager.projectIamAdmin). Learn how to grant roles.
    2. In the Google Cloud console, go to the Create service account page.

      Go to Create service account
    3. Select your project.
    4. In the Service account name field, enter a name. The Google Cloud console fills in the Service account ID field based on this name.

      In the Service account description field, enter a description. For example, Service account for quickstart.

    5. Click Create and continue.
    6. Grant the Project > Owner role to the service account.

      To grant the role, find the Select a role list, then select Project > Owner.

    7. Click Continue.
    8. Click Done to finish creating the service account.

  6. Google Cloud CLI をインストールします。

  7. 外部 ID プロバイダ(IdP)を使用している場合は、まず連携 ID を使用して gcloud CLI にログインする必要があります。

  8. gcloud CLI を初期化するには、次のコマンドを実行します:

    gcloud init
  9. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  10. Verify that billing is enabled for your Google Cloud project.

  11. Enable the SaaS Runtime, Artifact Registry, Infrastructure Manager, Developer Connect, Cloud Build, and Cloud Storage APIs.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the APIs

  12. Create a service account:

    1. Ensure that you have the Create Service Accounts IAM role (roles/iam.serviceAccountCreator) and the Project IAM Admin role (roles/resourcemanager.projectIamAdmin). Learn how to grant roles.
    2. In the Google Cloud console, go to the Create service account page.

      Go to Create service account
    3. Select your project.
    4. In the Service account name field, enter a name. The Google Cloud console fills in the Service account ID field based on this name.

      In the Service account description field, enter a description. For example, Service account for quickstart.

    5. Click Create and continue.
    6. Grant the Project > Owner role to the service account.

      To grant the role, find the Select a role list, then select Project > Owner.

    7. Click Continue.
    8. Click Done to finish creating the service account.

  13. Google Cloud CLI をインストールします。

  14. 外部 ID プロバイダ(IdP)を使用している場合は、まず連携 ID を使用して gcloud CLI にログインする必要があります。

  15. gcloud CLI を初期化するには、次のコマンドを実行します:

    gcloud init

SaaS ランナー サービス アカウントに権限を付与する

SaaS ランタイムは複数のサービス アカウントを使用します。前のセクションでサービス アカウントを作成しました。SaaS ランタイム API を有効にすると、SaaS ランタイムは別のサービス アカウントを作成します。

SaaS ランタイムによって作成されたサービス アカウントは service-PROJECT-NUMBER@gcp-sa-saasservicemgmt.iam.gserviceaccount.com と呼ばれます。ここで、PROJECT-NUMBER はプロジェクト番号です。

次の操作を行って、このサービス アカウントに必要な権限を付与します。

  1. [SaaS ランタイム] > [概要] > [使ってみる] ページを開きます。

    SaaS ランタイムを使ってみるに移動

  2. メッセージ SaaS ランタイム アカウントに必要な権限が付与されていません が表示されたバナーで、 [権限を付与] をクリックします。

Terraform 構成を使用してサービス インスタンスを定義する

Terraform 構成を使用して、サービス インスタンスにデプロイするインフラストラクチャを定義する必要があります。このクイックスタートでは、VM をデプロイします。

VM を定義する Terraform 構成を作成するには:

  1. ローカルマシンに terraform-vm という名前のディレクトリを作成します。

  2. terraform-vm 内に、次の 4 つの Terraform ファイルを作成します。

    1. 次の内容の versions.tf という名前のファイル:

      terraform {
        required_version = "1.5.7"
        required_providers {
          google = {
            source  = "hashicorp/google"
            version = "~> 4.0"
          }
        }
      }
      
    2. 次の内容の outputs.tf という名前のファイル:

      output "instance_name" {
        description = "Name of the instance"
        value       = google_compute_instance.vm_instance.name
      }
      
      output "instance_external_ip" {
        description = "External IP of the instance"
        value       = google_compute_instance.vm_instance.network_interface[0].access_config[0].nat_ip
      }
      
      output "instance_self_link" {
        description = "Self-link of the instance"
        value       = google_compute_instance.vm_instance.self_link
      }
      
    3. 次の内容の variables.tf という名前のファイル:

      variable "region" {
        description = "The Google Cloud region"
        type        = string
        default     = "us-central1"
      }
      
      variable "zone" {
        description = "The Google Cloud zone"
        type        = string
        default     = "us-central1-a"
      }
      
      variable "instance_name" {
        description = "Name for the Compute Engine instance"
        type        = string
        default = "saas-runtime-vm-instance"
      }
      
      variable "machine_type" {
        description = "Machine type for the Compute Engine instance"
        type        = string
        default = "e2-medium"
      }
      
      variable "disk_size" {
        description = "Boot disk size in GB"
        type        = number
        default = 10
      }
      
      variable "actuation_sa" {
        description = "The email of the Actuation Service Account"
        type        = string
      }
      
      variable "tenant_project_id" {
        description = "The project ID of the tenant project"
        type        = string
      }
      
      variable "tenant_project_number" {
        description = "The project number of the tenant project"
        type        = number
      }
      
    4. 次の内容の main.tf という名前のファイル:

      resource "google_compute_instance" "vm_instance" {
        project      = var.tenant_project_id
        name         = var.instance_name
        machine_type = var.machine_type
        zone         = var.zone
      
        boot_disk {
          initialize_params {
            image = "debian-cloud/debian-11"
            size  = var.disk_size
          }
        }
      
        network_interface {
          network = "default"
          access_config {
            # Ephemeral public IP - empty block is okay here
          }
        }
      
        tags = ["allow-ssh"]
      }
      
  3. これら 4 つの Terraform 構成ファイルを含む zip アーカイブを作成するには、ターミナルで terraform-vm ディレクトリに移動し、次のコマンドを実行します。

    zip terraform-files.zip main.tf outputs.tf variables.tf versions.tf
    

    これで、4 つの Terraform 構成ファイルを含む terraform-files.zip という名前の zip アーカイブが作成されました。

Artifact Registry にリポジトリを作成する

SaaS ランタイムを使用するには、Artifact Registry にリポジトリが必要です。このリポジトリを作成するには、次の操作を行います。

  1. コンソールで、Artifact Registry に移動します。

    Artifact Registry に移動

  2. [リポジトリを作成] をクリックします。

  3. [名前] に「vm-quickstart-repo」と入力します。

  4. [形式] は [Docker] のままにします。

  5. [リージョン] には us-central1 (Iowa) を選択します。

  6. [作成] をクリックします。

SaaS オファリングの作成

デプロイする VM を定義する Terraform 構成とリポジトリがあります。SaaS ランタイムを使用して、デプロイの単位をモデル化し、VM をデプロイできます。

SaaS サービス リソースを作成する

  1. コンソールで、[SaaS ランタイム] > [SaaS オファリング] に移動します。

    SaaS サービスに移動

  2. [作成] をクリックします。

  3. [SaaS サービスの名前] フィールドに「vm-quickstart-saas-offering」と入力します。

  4. [リージョン] フィールドでリージョン us-central1 を選択し、[OK] をクリックします。

  5. [作成] をクリックします。

SaaS サービス用に選択したリージョンは、SaaS サービスのデプロイがホストされる場所です。このクイックスタートの例では、SaaS オファリングは単一の VM であるため、これらのリージョンは VM がプロビジョニングされてホストされる場所です。

エンドユーザーがこれらの VM にアクセスする場合、ここで指定したリージョンにデプロイされたこれらの VM にアクセスします。

デプロイの単位をモデル化する

SaaS サービスをモデル化するには、ユニットの種類と呼ばれるコンポーネントを作成します。 ユニットの種類は、デプロイして管理するサービス内のコンポーネントを定義します。 たとえば、VM 用のユニットの種類と、その VM で実行されているアプリケーション用のユニットの種類があります。

このクイックスタートでは、VM 用のユニットの種類を 1 つ作成します。

ユニットの種類を作成するには:

  1. コンソールで、[SaaS ランタイム] > [ユニットの種類] に移動します。

    ユニットの種類に移動

  2. [作成] を選択します。

  3. [ブループリントを作成] ページで次の操作を行います。

    1. [アップロード] を選択します。
    2. VM を定義する Terraform 構成をアップロードするには、次の操作を行います。
      1. [ファイル選択ツール] フィールドで、[参照] を選択します。
      2. 以前に作成した zip アーカイブ ファイル terraform-files.zip に移動して選択します。
      3. [開く] を選択します。
    3. [次へ: ブループリントの構成] をクリックします。
  4. [ブループリントを保存] ページで次の操作を行います。

    1. Artifact Registry を選択します。
      1. [Artifact Registry からリポジトリを選択] フィールドで、 [参照] を選択します。
      2. 以前に作成したリポジトリ vm-quickstart-repo を選択します。
      3. [選択] をクリックします。
    2. [アーティファクト イメージ名] フィールドに vm-quickstart-blueprint と入力します。
    3. [Infrastructure Manager の Terraform バージョン] で 1.5.7 を選択します。
    4. [Cloud Build サービス アカウント] で、始める前にで作成したサービス アカウントを選択します。
    5. [次へ: ユニットの種類の詳細] をクリックします。
  5. [**ユニットの種類のプロパティを構成**] ページで、次の操作を行います。

    1. [ユニットの種類名] に vm-quickstart-unit-kind と入力します。
    2. [SaaS サービス] で、以前に作成した SaaS サービス リソース vm-quickstart-saas-offering を選択します。
    3. [次へ: リリースの構成] をクリックします。
  6. [リリース名] に vm-quickstart-first-release と入力します。

  7. [作成] をクリックします。

サービス インスタンスをプロビジョニングする

ユニットの種類の一部であるリソースをプロビジョニングするには、ユニットを作成します。 ユニットを作成すると、SaaS ランタイムは、ユニットの種類に接続されている Terraform 構成で定義されたリソースをプロビジョニングします。リソースは、SaaS サービスの一部である各リージョンにプロビジョニングされます。

このクイックスタートの例では、VM はリージョン us-central1 にプロビジョニングされます。

  1. ユニットを作成します。

    1. コンソールで、[SaaS ランタイム] > [ユニット] に移動します。

      ユニットに移動

    2. [作成] を選択します。

    3. [ユニットを作成] ページで次の操作を行います。

      1. [ユニット名] に「vm-quickstart-unit」と入力します。
      2. [SaaS サービス] で、以前に作成した SaaS サービス リソース を選択します: vm-quickstart-saas-offering
      3. [リージョン] で us-central1 を選択します。
      4. [ユニットの種類] で、以前に作成したユニットの種類 vm-quickstart-unit-kind を選択します。
      5. [作成] を選択します。
  2. VM をプロビジョニングするには:

    1. [ユニットの詳細] ページで、[プロビジョニング] を選択します。
    2. [リリース] フィールドで、vm-quickstart-first-release を選択します。
    3. [**サービス アカウント**] で、始める前にで作成したサービス アカウントを選択します。
    4. テナント プロジェクトを追加します。

      1. [テナント プロジェクト変数を追加] を選択します。
      2. この Google Cloud クイックスタートで使用する プロジェクトを選択します。SaaS ランタイムが VM をデプロイすると、このプロジェクトにデプロイされます。
    5. [プロビジョニング] を選択します。

SaaS ランタイムは、SaaS サービスで指定したリージョンに VM をプロビジョニングします。ユニットで指定した任意のリージョンにユニットを作成できます。このクイックスタートでは、1 つのリージョン(us-central1)を指定しました。このリージョンに VM がプロビジョニングされます。

デプロイされた VM を表示する

SaaS ランタイムを使用して VM をデプロイしました。

このクイックスタートでデプロイした VM を表示するには:

  1. コンソールで、[SaaS ランタイム] > [ユニット] > [ユニットの詳細] ページに移動します。

    ユニットに移動

  2. ユニットの名前 vm-quickstart-unit をクリックします。

  3. [ユニットの詳細] ページで次の操作を行います。

    1. [状態] が次のようになっていることを確認します。

      • VM がプロビジョニングされている場合は [準備完了]。
      • オペレーションが進行中の場合は [プロビジョニング中]。
    2. [変数] セクションを開きます。

    3. [**出力変数**] に、インスタンスに到達するために使用できる外部 IP が表示されます。

  4. Compute Engine で VM を表示することもできます。

    1. コンソールで、[Compute Engine] > [VM インスタンス] ページに移動します。

      [VM インスタンス] に移動

    2. [VM インスタンス] に VM が表示されます。

クリーンアップ

このページで使用したリソースについて、 Google Cloud アカウントに課金されないようにするには、 次の手順を実施します。

プロジェクトの削除

新しい Google Cloud プロジェクトにソリューションをデプロイし、 プロジェクトが不要になった場合は、次の手順で削除します。

  1. Google Cloud コンソールで [リソースの管理] ページに移動します。

    [リソースの管理] に移動

  2. プロジェクト リストで、削除するプロジェクトを選択し、[削除] をクリックします。
  3. プロンプトでプロジェクト ID を入力し、[シャットダウン] をクリックします。

次のステップ