App Lifecycle Manager を使用してサービス インスタンスをデプロイする
App Lifecycle Manager を使用してサービス インスタンスをデプロイする方法について説明します。このクイックスタートの例では、サービス インスタンスは 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 App Lifecycle Manager, 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 App Lifecycle Manager, 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 ランナー サービス アカウントに権限を付与する
App Lifecycle Manager は複数のサービス アカウントを使用します。前のセクションでサービス アカウントを作成しましたが、App Lifecycle Manager API を有効にすると、App Lifecycle Manager は別のサービス アカウントを作成します。
App Lifecycle Manager によって作成されたサービス アカウントは service-PROJECT-NUMBER@gcp-sa-saasservicemgmt.iam.gserviceaccount.com と呼ばれます。ここで、PROJECT-NUMBER はプロジェクト番号です。
次の操作を行って、このサービス アカウントに必要な権限を付与します。
[App Lifecycle Manager] > [Overview] > [Get Started] ページを開きます。
「App Lifecycle Manager アカウントに必要な権限が付与されていません」というメッセージが表示されたバナーで、[権限を付与] をクリックします。
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 にリポジトリを作成する
App Lifecycle Manager を使用するには、Artifact Registry にリポジトリが必要です。このリポジトリを作成する手順は次のとおりです。
コンソールで、[Artifact Registry] に移動します。
[リポジトリを作成] をクリックします。
[名前] に「
vm-quickstart-repo」と入力します。[形式] は [Docker] を選択したままにします。
[リージョン] には
us-central1 (Iowa)を選択します。[作成] をクリックします。
SaaS サービスの作成
デプロイする VM を定義する Terraform 構成とリポジトリがある。App Lifecycle Manager を使用して、デプロイ単位をモデル化し、VM をデプロイできるようになりました。
SaaS サービス リソースを作成する
コンソールで、[App Lifecycle Manager] > [SaaS Offering] に移動します。
[作成] をクリックします。
[Name of the SaaS] フィールドに「
vm-quickstart-saas-offering」と入力します。[リージョン] フィールドでリージョン
us-central1を選択し、[OK] をクリックします。[作成] をクリックします。
SaaS サービス用に選択したリージョンは、SaaS サービスのデプロイがホストされる場所です。このクイックスタートの例では、SaaS サービスは単一の VM であるため、これらのリージョンは VM がプロビジョニングされてホストされる場所です。
エンドユーザーがこれらの VM にアクセスする場合、ここで指定したリージョンにデプロイされた VM にアクセスします。
デプロイの単位をモデル化する
SaaS サービスをモデル化するには、ユニットの種類というコンポーネントを作成します。ユニットの種類によって、デプロイして管理するサービス内のコンポーネントが決まります。たとえば、VM のユニットの種類が 1 つあり、その VM で実行されているアプリケーションのユニットの種類がもう 1 つある場合があります。
このクイックスタートでは、VM 用の単位種類を 1 つ作成します。
ユニットの種類を作成するには:
コンソールで、[App Lifecycle Manager] > [Unit Kinds] に移動します。
[作成] を選択します。
[ブループリントの作成] ページで、次の操作を行います。
- [アップロード] を選択します。
- VM を定義する Terraform 構成をアップロードするには、次の操作を行います。
- [ファイル選択ツール] フィールドで、[参照] を選択します。
- 前に作成した zip アーカイブ ファイルである
terraform-files.zipに移動して選択します。 - [開く] を選択します。
- [次へ: ブループリントを構成] をクリックします。
[ブループリントの保存] ページで、次の操作を行います。
- Artifact Registry を選択します。
- [Artifact Registry からリポジトリを選択] フィールドで、[参照] を選択します。
- 以前に作成したリポジトリである
vm-quickstart-repoを選択します。 - [選択] をクリックします。
- [Artifact image name] フィールドに「
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」と入力します。[作成] をクリックします。
サービス インスタンスをプロビジョニングする
ユニットの種類に属するリソースをプロビジョニングするには、ユニットを作成します。ユニットを作成すると、App Lifecycle Manager は、ユニットの種類に関連付けられている Terraform 構成で定義されたリソースをプロビジョニングします。リソースは、SaaS サービスの一部である各リージョンにプロビジョニングされます。
このクイックスタートの例では、VM はリージョン us-central1 にプロビジョニングされます。
ユニットを作成します。
コンソールで、[App Lifecycle Manager] > [ユニット] に移動します。
[作成] を選択します。
[ユニットを作成] ページで、次の操作を行います。
- [単位名] に「
vm-quickstart-unit」と入力します。 - [SaaS サービス] で、以前に作成した SaaS サービス リソース(
vm-quickstart-saas-offering)を選択します。 - [リージョン] の下で
us-central1を選択します。 - [単位の種類] で、先ほど作成した単位の種類(
vm-quickstart-unit-kind)を選択します。 - [作成] を選択します。
- [単位名] に「
VM をプロビジョニングするには:
- [ユニットの詳細] ページで、[プロビジョニング] を選択します。
- [リリース] フィールドで、
vm-quickstart-first-releaseを選択します。 - [サービス アカウント] で、始める前にのセクションで作成したサービス アカウントを選択します。
テナント プロジェクトを追加します。
- [テナント プロジェクト変数を追加] を選択します。
- このクイックスタートで使用している Google Cloud プロジェクトを選択します。App Lifecycle Manager が VM をデプロイすると、このプロジェクトにデプロイされます。
[プロビジョニング] を選択します。
App Lifecycle Manager は、SaaS サービスで指定したリージョンに VM をプロビジョニングします。ユニットは、ユニットで指定したリージョンのいずれかに作成できます。このクイックスタートでは、1 つのリージョン(us-central1)を指定しました。このリージョンに VM がプロビジョニングされます。
デプロイされた VM を表示する
これで、App Lifecycle Manager を使用して VM をデプロイしました。
このクイックスタートでデプロイした VM を表示するには:
Google Cloud コンソールで、[App Lifecycle Manager] > [Units] > [Unit details] ページに移動します。
ユニットの名前(
vm-quickstart-unit)をクリックします。[Unit details] ページで、次の操作を行います。
状態が次のようになっていることを確認します。
- VM がプロビジョニングされている場合は Ready。
- オペレーションがまだ進行中の場合は、プロビジョニング。
[変数] セクションを開きます。
[出力変数] に、インスタンスにアクセスするために使用できる外部 IP が表示されます。
Compute Engine で VM を表示することもできます。
コンソールで、[Compute Engine] > [VM インスタンス] ページに移動します。
[VM インスタンス] に VM が表示されます。
クリーンアップ
このページで使用したリソースについて、 Google Cloud アカウントに課金されないようにするには、次の手順を実施します。
プロジェクトを削除する
ソリューションを新しい Google Cloud プロジェクトにデプロイした後、そのプロジェクトが不要になった場合は、次の手順で削除します。
- Google Cloud コンソールで [リソースの管理] ページに移動します。
- プロジェクト リストで、削除するプロジェクトを選択し、[削除] をクリックします。
- プロンプトでプロジェクト ID を入力し、[シャットダウン] をクリックします。
次のステップ
- App Lifecycle Manager の詳細については、App Lifecycle Manager の概要をご覧ください。
- App Lifecycle Manager の使用を開始するには、まず SaaS サービスを作成します。
- サービス アカウントの使用方法と、これらのアカウントにきめ細かい権限を付与する方法については、App Lifecycle Manager サービス アカウントをご覧ください。
- リリースを更新する手順については、リリースをロールアウトするをご覧ください。