SaaS ランタイムを使用してサービス インスタンスをデプロイする
SaaS ランタイムを使用してサービス インスタンスをデプロイする方法について説明します。このクイックスタートの例では、サービス インスタンスは VM です。
始める前に
-
ログイン Google アカウントにログインします。
Google アカウントをまだお持ちでない場合は、 新しいアカウントを登録します。
-
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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
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 theserviceusage.services.enablepermission. Learn how to grant roles.-
Create a service account:
-
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. -
In the Google Cloud console, go to the Create service account page.
Go to Create service account - Select your project.
-
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. - Click Create and continue.
-
Grant the Project > Owner role to the service account.
To grant the role, find the Select a role list, then select Project > Owner.
- Click Continue.
-
Click Done to finish creating the service account.
-
Ensure that you have the Create Service Accounts IAM role
(
-
Google Cloud CLI をインストールします。
-
外部 ID プロバイダ(IdP)を使用している場合は、まず連携 ID を使用して gcloud CLI にログインする必要があります。
-
gcloud CLI を初期化するには、次のコマンドを実行します:
gcloud init -
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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
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 theserviceusage.services.enablepermission. Learn how to grant roles.-
Create a service account:
-
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. -
In the Google Cloud console, go to the Create service account page.
Go to Create service account - Select your project.
-
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. - Click Create and continue.
-
Grant the Project > Owner role to the service account.
To grant the role, find the Select a role list, then select Project > Owner.
- Click Continue.
-
Click Done to finish creating the service account.
-
Ensure that you have the Create Service Accounts IAM role
(
-
Google Cloud CLI をインストールします。
-
外部 ID プロバイダ(IdP)を使用している場合は、まず連携 ID を使用して gcloud CLI にログインする必要があります。
-
gcloud CLI を初期化するには、次のコマンドを実行します:
gcloud init
SaaS ランナー サービス アカウントに権限を付与する
SaaS ランタイムは複数のサービス アカウントを使用します。前のセクションでサービス アカウントを作成しました。SaaS ランタイム API を有効にすると、SaaS ランタイムは別のサービス アカウントを作成します。
SaaS ランタイムによって作成されたサービス アカウントは
service-PROJECT-NUMBER@gcp-sa-saasservicemgmt.iam.gserviceaccount.com と呼ばれます。ここで、PROJECT-NUMBER はプロジェクト番号です。
次の操作を行って、このサービス アカウントに必要な権限を付与します。
[SaaS ランタイム] > [概要] > [使ってみる] ページを開きます。
メッセージ SaaS ランタイム アカウントに必要な権限が付与されていません が表示されたバナーで、 [権限を付与] をクリックします。
Terraform 構成を使用してサービス インスタンスを定義する
Terraform 構成を使用して、サービス インスタンスにデプロイするインフラストラクチャを定義する必要があります。このクイックスタートでは、VM をデプロイします。
VM を定義する Terraform 構成を作成するには:
ローカルマシンに
terraform-vmという名前のディレクトリを作成します。terraform-vm内に、次の 4 つの Terraform ファイルを作成します。次の内容の
versions.tfという名前のファイル:terraform { required_version = "1.5.7" required_providers { google = { source = "hashicorp/google" version = "~> 4.0" } } }次の内容の
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 }次の内容の
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 }次の内容の
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"] }
これら 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 にリポジトリが必要です。このリポジトリを作成するには、次の操作を行います。
コンソールで、Artifact Registry に移動します。
[リポジトリを作成] をクリックします。
[名前] に「
vm-quickstart-repo」と入力します。[形式] は [Docker] のままにします。
[リージョン] には
us-central1 (Iowa)を選択します。[作成] をクリックします。
SaaS オファリングの作成
デプロイする VM を定義する Terraform 構成とリポジトリがあります。SaaS ランタイムを使用して、デプロイの単位をモデル化し、VM をデプロイできます。
SaaS サービス リソースを作成する
コンソールで、[SaaS ランタイム] > [SaaS オファリング] に移動します。
[作成] をクリックします。
[SaaS サービスの名前] フィールドに「
vm-quickstart-saas-offering」と入力します。[リージョン] フィールドでリージョン
us-central1を選択し、[OK] をクリックします。[作成] をクリックします。
SaaS サービス用に選択したリージョンは、SaaS サービスのデプロイがホストされる場所です。このクイックスタートの例では、SaaS オファリングは単一の VM であるため、これらのリージョンは VM がプロビジョニングされてホストされる場所です。
エンドユーザーがこれらの VM にアクセスする場合、ここで指定したリージョンにデプロイされたこれらの VM にアクセスします。
デプロイの単位をモデル化する
SaaS サービスをモデル化するには、ユニットの種類と呼ばれるコンポーネントを作成します。 ユニットの種類は、デプロイして管理するサービス内のコンポーネントを定義します。 たとえば、VM 用のユニットの種類と、その VM で実行されているアプリケーション用のユニットの種類があります。
このクイックスタートでは、VM 用のユニットの種類を 1 つ作成します。
ユニットの種類を作成するには:
コンソールで、[SaaS ランタイム] > [ユニットの種類] に移動します。
[作成] を選択します。
[ブループリントを作成] ページで次の操作を行います。
- [アップロード] を選択します。
- VM を定義する Terraform 構成をアップロードするには、次の操作を行います。
- [ファイル選択ツール] フィールドで、[参照] を選択します。
- 以前に作成した zip アーカイブ ファイル
terraform-files.zipに移動して選択します。 - [開く] を選択します。
- [次へ: ブループリントの構成] をクリックします。
[ブループリントを保存] ページで次の操作を行います。
- Artifact Registry を選択します。
- [Artifact Registry からリポジトリを選択] フィールドで、 [参照] を選択します。
- 以前に作成したリポジトリ
vm-quickstart-repoを選択します。 - [選択] をクリックします。
- [アーティファクト イメージ名] フィールドに
vm-quickstart-blueprintと入力します。 - [Infrastructure Manager の Terraform バージョン] で
1.5.7を選択します。 - [Cloud Build サービス アカウント] で、始める前にで作成したサービス アカウントを選択します。
- [次へ: ユニットの種類の詳細] をクリックします。
- Artifact Registry を選択します。
[**ユニットの種類のプロパティを構成**] ページで、次の操作を行います。
- [ユニットの種類名] に
vm-quickstart-unit-kindと入力します。 - [SaaS サービス] で、以前に作成した SaaS サービス リソース
vm-quickstart-saas-offeringを選択します。 - [次へ: リリースの構成] をクリックします。
- [ユニットの種類名] に
[リリース名] に
vm-quickstart-first-releaseと入力します。[作成] をクリックします。
サービス インスタンスをプロビジョニングする
ユニットの種類の一部であるリソースをプロビジョニングするには、ユニットを作成します。 ユニットを作成すると、SaaS ランタイムは、ユニットの種類に接続されている Terraform 構成で定義されたリソースをプロビジョニングします。リソースは、SaaS サービスの一部である各リージョンにプロビジョニングされます。
このクイックスタートの例では、VM はリージョン us-central1 にプロビジョニングされます。
ユニットを作成します。
コンソールで、[SaaS ランタイム] > [ユニット] に移動します。
[作成] を選択します。
[ユニットを作成] ページで次の操作を行います。
- [ユニット名] に「
vm-quickstart-unit」と入力します。 - [SaaS サービス] で、以前に作成した SaaS サービス リソース を選択します:
vm-quickstart-saas-offering - [リージョン] で
us-central1を選択します。 - [ユニットの種類] で、以前に作成したユニットの種類
vm-quickstart-unit-kindを選択します。 - [作成] を選択します。
- [ユニット名] に「
VM をプロビジョニングするには:
- [ユニットの詳細] ページで、[プロビジョニング] を選択します。
- [リリース] フィールドで、
vm-quickstart-first-releaseを選択します。 - [**サービス アカウント**] で、始める前にで作成したサービス アカウントを選択します。
テナント プロジェクトを追加します。
- [テナント プロジェクト変数を追加] を選択します。
- この Google Cloud クイックスタートで使用する プロジェクトを選択します。SaaS ランタイムが VM をデプロイすると、このプロジェクトにデプロイされます。
[プロビジョニング] を選択します。
SaaS ランタイムは、SaaS サービスで指定したリージョンに VM をプロビジョニングします。ユニットで指定した任意のリージョンにユニットを作成できます。このクイックスタートでは、1 つのリージョン(us-central1)を指定しました。このリージョンに VM がプロビジョニングされます。
デプロイされた VM を表示する
SaaS ランタイムを使用して VM をデプロイしました。
このクイックスタートでデプロイした VM を表示するには:
コンソールで、[SaaS ランタイム] > [ユニット] > [ユニットの詳細] ページに移動します。
ユニットの名前
vm-quickstart-unitをクリックします。[ユニットの詳細] ページで次の操作を行います。
[状態] が次のようになっていることを確認します。
- VM がプロビジョニングされている場合は [準備完了]。
- オペレーションが進行中の場合は [プロビジョニング中]。
[変数] セクションを開きます。
[**出力変数**] に、インスタンスに到達するために使用できる外部 IP が表示されます。
Compute Engine で VM を表示することもできます。
コンソールで、[Compute Engine] > [VM インスタンス] ページに移動します。
[VM インスタンス] に VM が表示されます。
クリーンアップ
このページで使用したリソースについて、 Google Cloud アカウントに課金されないようにするには、 次の手順を実施します。
プロジェクトの削除
新しい Google Cloud プロジェクトにソリューションをデプロイし、 プロジェクトが不要になった場合は、次の手順で削除します。
- Google Cloud コンソールで [リソースの管理] ページに移動します。
- プロジェクト リストで、削除するプロジェクトを選択し、[削除] をクリックします。
- プロンプトでプロジェクト ID を入力し、[シャットダウン] をクリックします。
次のステップ
- SaaS ランタイムの詳細については、 SaaS ランタイムの概要をご覧ください。
- SaaS ランタイムの使用を開始するには、 SaaS オファーの作成から始めます。
- サービス アカウントの使用方法と、これらのアカウントに詳細な権限を付与する方法については、 SaaS ランタイム サービス アカウントをご覧ください。
- リリースを更新する手順については、 リリースをロールアウトするをご覧ください。