このページの一部またはすべての情報は、S3NS の Trusted Cloud に適用されない場合があります。
Terraform を使用して Artifact Registry リソースをプロビジョニングする
Hashicorp Terraform は、クラウド インフラストラクチャのプロビジョニングと管理に使用できる Infrastructure as Code(IaC)ツールです。Terraform には、クラウド プロバイダや他の API とやり取りできるプロバイダというプラグインが用意されています。 Trusted Cloud用の Terraform プロバイダを使用して、Artifact Registry などの Trusted Cloud by S3NS リソースをプロビジョニングして管理できます。
このページでは、Artifact Registry で Terraform を使用する方法について説明します。Terraform の仕組みの概要と、 Trusted Cloudで Terraform の使用を開始するためのリソースも紹介します。また、Artifact Registry の Terraform リファレンス ドキュメント、コード例、Terraform を使用して Artifact Registry リソースをプロビジョニングするガイドへのリンクも用意されています。
Trusted Cloud用 Terraform の使用を開始する手順については、Terraform をインストールして構成するまたは Trusted Cloud 用 Terraform クイックスタートをご覧ください。
Terraform には宣言型で構成指向の構文があり、これを使用して、 Trusted Cloud プロジェクトにプロビジョニングするインフラストラクチャを記述できます。1 つまたは複数の Terraform 構成ファイルで構成を作成し、Terraform CLI を使用して、この構成を Artifact Registry リソースに適用できます。
以降のステップでは、Terraform の仕組みについて説明します。
- プロビジョニングするインフラストラクチャを Terraform 構成ファイルに記述します。インフラストラクチャのプロビジョニング方法を記述するコードは必要ありません。Terraform がインフラストラクチャをプロビジョニングします。
terraform plan
コマンドを実行します。これにより、構成が評価され、実行プランが生成されます。プランを確認し、必要に応じて変更します。
-
次に、terraform apply
コマンドを実行します。これにより、次のアクションが実行されます。
- バックグラウンドで、対応する Artifact Registry API を呼び出し、実行プランに基づいてインフラストラクチャをプロビジョニングします。
- Terraform 状態ファイルを作成します。これは、構成ファイル内のリソースと実際のインフラストラクチャ内のリソースとのマッピングを行う JSON ファイルです。Terraform は、このファイルを使用してインフラストラクチャの最新状態を記録し、リソースを作成、更新、破棄するタイミングを決定します。
-
terraform apply
を実行すると、Terraform は状態ファイルのマッピングを使用して、既存のインフラストラクチャをコードと比較し、必要に応じて更新を行います。
- 構成ファイルで定義されたリソース オブジェクトが状態ファイルに存在しない場合、Terraform はリソース オブジェクトを作成します。
- リソース オブジェクトが状態ファイルに存在し、構成ファイルと構成が異なる場合、Terraform は構成ファイルと一致するようにリソースを更新します。
- 状態ファイル内のリソース オブジェクトが構成ファイルと一致する場合、Terraform はリソースを変更しません。
Artifact Registry の Terraform リソース
リソースは、Terraform 言語の基本要素です。各リソース ブロックは、仮想ネットワークやコンピューティング インスタンスなど、1 つ以上のインフラストラクチャ オブジェクトを記述します。
次の表に、Artifact Registry で使用可能な Terraform リソースを示します。
Artifact Registry の Terraform ベースのガイド
次の表には、Artifact Registry の Terraform ベースの入門ガイドとチュートリアルすべてが一覧表示されています。
Artifact Registry の Terraform モジュールとブループリント
モジュールとブループリントを使用すると、 Trusted Cloud リソースの大規模なプロビジョニングと管理を自動化できます。モジュールとは、Terraform リソースを論理的に抽象化する、再利用可能な一連の Terraform 構成ファイルのことです。ブループリントは、特定のソリューションを実装および文書化した、モジュールとポリシーのパッケージです。このパッケージはデプロイして再利用できます。
次の表には、Artifact Registry に関連するすべてのモジュールとブループリントが一覧表示されています。
モジュールまたはブループリント |
詳細 |
Artifact Registry |
Artifact Registry リポジトリを作成して管理する |
gcloud |
Terraform 内で Trusted Cloud by S3NS CLI コマンドを実行する |
次のステップ
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-07-24 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-07-24 UTC。"],[[["\u003cp\u003eTerraform is an infrastructure-as-code tool used to provision and manage cloud infrastructure, including Google Cloud resources like Artifact Registry, through its declarative configuration files and providers.\u003c/p\u003e\n"],["\u003cp\u003eUsing the Terraform CLI, you describe your desired infrastructure in configuration files, then use \u003ccode\u003eterraform plan\u003c/code\u003e to review an execution plan and \u003ccode\u003eterraform apply\u003c/code\u003e to provision resources and manage their state.\u003c/p\u003e\n"],["\u003cp\u003eTerraform's state file maintains a record of your infrastructure's current state, enabling it to create, update, or leave resources unchanged by comparing the existing infrastructure to your configuration code.\u003c/p\u003e\n"],["\u003cp\u003eTerraform resources for Artifact Registry include managing repositories, IAM, and VPC-SC configurations, while data sources include information on Docker images and repository IAM policies.\u003c/p\u003e\n"],["\u003cp\u003eTerraform modules and blueprints for Artifact Registry provide reusable sets of configurations to automate the provisioning and management of Google Cloud resources, allowing for standardized and efficient infrastructure deployment.\u003c/p\u003e\n"]]],[],null,["# Provision Artifact Registry resources with Terraform\n\nHashiCorp Terraform is an infrastructure-as-code (IaC) tool that lets you\nprovision and manage cloud infrastructure. Terraform provides plugins called\n*providers* that let you interact with cloud providers and other APIs. You can\nuse the *Terraform provider for Google Cloud* to provision and manage\nGoogle Cloud resources, including Artifact Registry.\n\nThis page introduces you to using Terraform with Artifact Registry, including an\nintroduction to how Terraform works and some resources to help you get started using\nTerraform with Google Cloud. You'll also find links to Terraform reference docs for\nArtifact Registry, code examples, and guides for using Terraform to provision\nArtifact Registry resources.\n\nFor instructions on how to get started with Terraform for Google Cloud, see\n[Install and configure Terraform](/docs/terraform/install-configure-terraform) or the\n[Terraform for Google Cloud quickstart](/docs/terraform/create-vm-instance).\n\nHow Terraform works\n-------------------\n\nTerraform has a declarative and configuration-oriented syntax, which you can\nuse to describe the infrastructure that you want to provision in your\nGoogle Cloud project. After you author this configuration in one or more\nTerraform configuration files, you can use the Terraform CLI to apply this\nconfiguration to your Artifact Registry resources.\n\nThe following steps explain how Terraform works:\n\n1. You describe the infrastructure you want to provision in a *Terraform\n configuration file*. You don't need to write code describing how to provision the infrastructure. Terraform provisions the infrastructure for you.\n2. You run the `terraform plan` command, which evaluates your configuration and generates an execution plan. You can review the plan and make changes as needed.\n3. You run the `terraform apply` command, which performs the following\n actions:\n\n 1. It provisions your infrastructure based on your execution plan by invoking the corresponding Artifact Registry APIs in the background.\n 2. It creates a *Terraform state file*, which is a JSON file that maps the resources in your configuration file to the resources in the real-world infrastructure. Terraform uses this file to keep a record of the most recent state of your infrastructure, and to determine when to create, update, and destroy resources.\n 3. When you run `terraform apply`, Terraform uses the mapping in\n the state file to compare the existing infrastructure to the code, and make\n updates as necessary:\n\n - If a resource object is defined in the configuration file, but doesn't exist in the state file, Terraform creates it.\n - If a resource object exists in the state file, but has a different configuration from your configuration file, Terraform updates the resource to match your configuration file.\n - If a resource object in the state file matches your configuration file, Terraform leaves the resource unchanged.\n\nTerraform resources for Artifact Registry\n-----------------------------------------\n\n*Resources* are the fundamental elements in the Terraform language. Each\nresource block describes one or more infrastructure objects, such as virtual\nnetworks or compute instances.\n\nThe following table lists the Terraform resources available for\nArtifact Registry:\n\n\n\u003cbr /\u003e\n\nTerraform-based guides for Artifact Registry\n--------------------------------------------\n\nThe following table lists Terraform-based how-to guides and tutorials for\nArtifact Registry:\n\n\n\u003cbr /\u003e\n\nTerraform modules and blueprints for Artifact Registry\n------------------------------------------------------\n\nModules and blueprints help you automate provisioning and managing of\nGoogle Cloud resources at scale. A *module* is a\nreusable set of Terraform configuration files that creates a logical abstraction\nof Terraform resources. A *blueprint* is a package of deployable and reusable\nmodules, and a policy that implements and documents a specific solution.\n\nThe following table lists modules and blueprints related to\nArtifact Registry:\n\n\n\u003cbr /\u003e\n\nWhat's next\n-----------\n\n- [Terraform code samples for Artifact Registry](/docs/samples?language=terraform)\n- [Terraform on Google Cloud documentation](/docs/terraform)\n- [Google Cloud provider documentation in HashiCorp](https://registry.terraform.io/providers/hashicorp/google/latest/docs)\n- [Infrastructure as code for Google Cloud](/docs/terraform/iac-overview)"]]