

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# コードリポジトリ AWS Service Catalog を使用して で Terraform 製品をプロビジョニングする
<a name="provision-a-terraform-product-in-aws-service-catalog-by-using-a-code-repository"></a>

*Amazon Web Services、Rahul Sharad Gaikwad 博士、Tamilselvan P*

## 概要
<a name="provision-a-terraform-product-in-aws-service-catalog-by-using-a-code-repository-summary"></a>

AWS Service Catalog は[HashiCorp Terraform ](https://developer.hashicorp.com/terraform/tutorials/aws-get-started)設定のガバナンスによるセルフサービスプロビジョニングをサポートします。Terraform を使用する場合は、Service Catalog を単一のツールとして使用して、 内の Terraform 設定を大規模 AWS に整理、管理、配布できます。Service Catalog の主な機能には、標準化および事前承認された Infrastructure as Code (IaC) テンプレートのカタログ化、アクセスコントロール、最小特権アクセスによるクラウドリソースのプロビジョニング、バージョニング、数千の共有 AWS アカウント、タグ付けなどがあります。エンジニア、データベース管理者、データサイエンティストなどのエンドユーザーは、アクセスできる製品とバージョンのリストを表示して、1 つのアクションでデプロイできます。

このパターンは、Terraform コードを使用して AWS リソースをデプロイするのに役立ちます。GitHub リポジトリの Terraform コードには、Service Catalog からアクセスできます。この手法を用いることで、製品を既存の Terraform ワークフローと統合することもできます。管理者は、Terraform を使用して Service Catalog ポートフォリオを作成し、 AWS Launch Wizard 製品を追加できます。

この方法による利点は以下のとおりです。
+ Service Catalog のロールバック機能のため、デプロイ中に問題が発生した場合は、製品を以前のバージョンに戻すことができます。
+ 製品バージョンの違いを簡単に特定できます。これにより、デプロイ中の問題を解決できます。
+ Service Catalog で、GitHub や GitLab などとのリポジトリ接続を設定できます。製品の変更は、リポジトリから直接行うことができます。

の全体的な利点については AWS Service Catalog、[「サービスカタログとは](https://docs.aws.amazon.com/servicecatalog/latest/adminguide/introduction.html)」を参照してください。

## 前提条件と制限
<a name="provision-a-terraform-product-in-aws-service-catalog-by-using-a-code-repository-prereqs"></a>

**前提条件**
+ アクティブ AWS アカウント。
+ ZIP 形式の Terraform 設定ファイルを含む GitHub、BitBucket、またはその他のリポジトリ。
+ AWS Serverless Application Model コマンドラインインターフェイス (AWS SAM CLI) [がインストールされている](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html)。
+ AWS Command Line Interface (AWS CLI)、[インストール](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)および[設定](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)済み。
+ [インストール済み](https://go.dev/doc/install)の Go。
+ Python バージョン 3.9、[Installed](https://www.python.org/downloads/release/python-3913/). AWS SAM CLI には、このバージョンの Python が必要です。
+ Service Catalog 製品とポートフォリオにアクセスして管理するための AWS Lambda 関数とアクセス許可を記述して実行するアクセス許可。

## アーキテクチャ
<a name="provision-a-terraform-product-in-aws-service-catalog-by-using-a-code-repository-architecture"></a>

![\[コードリポジトリから Service Catalog で Terraform 製品をプロビジョニングするアーキテクチャ図\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/images/pattern-img/7d0d76e8-9485-4b3f-915f-481b6a7cdcd9/images/e83fa44a-4ca6-4438-a0d1-99f09a3541bb.png)


この図表は、次のワークフローを示しています:

1. Terraform 設定の準備ができたら、開発者はすべての Terraform コードを含む .zip ファイルを作成します。開発者は、Service Catalog に接続されているコードリポジトリに .zip ファイルをアップロードします。

1. 管理者は、Terraform 製品を Service Catalog のポートフォリオに関連付けます。管理者は、エンドユーザーが製品をプロビジョニングできるようにする起動制約も作成します。

1. Service Catalog では、エンドユーザーは Terraform 設定を使用して AWS リソースを起動します。デプロイする製品バージョンを選択できます。

## ツール
<a name="provision-a-terraform-product-in-aws-service-catalog-by-using-a-code-repository-tools"></a>

**AWS のサービス**
+ [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) は、サーバーのプロビジョニングや管理を行うことなくコードを実行できるコンピューティングサービスです。必要に応じてコードを実行し、自動的にスケーリングするため、課金は実際に使用したコンピューティング時間に対してのみ発生します。
+ [AWS Service Catalog](https://docs.aws.amazon.com/servicecatalog/latest/adminguide/introduction.html) では、承認された IT サービスのカタログを一元管理できます AWS。エンドユーザーは、組織によって設定された制約に従って、必要な承認済みの IT サービスのみをすばやくデプロイできます。

**その他のサービス**
+ [Go](https://go.dev/doc/install) は、Google がサポートするオープンソースのプログラミング言語です。
+ 「[Python](https://www.python.org/)」は汎用のコンピュータプログラミング言語です。

**コードリポジトリ**

Service Catalog を通じてデプロイできるサンプル Terraform 設定が必要な場合は、GitHub [Amazon Macie Organization Setup Using Terraform](https://github.com/aws-samples/aws-macie-customization-terraform-samples) リポジトリから取得できます。このリポジトリでコードサンプルを使用する必要はありません。

## ベストプラクティス
<a name="provision-a-terraform-product-in-aws-service-catalog-by-using-a-code-repository-best-practices"></a>
+ Terraform 設定ファイル (`terraform.tfvars`) で変数の値を指定する代わりに、Service Catalog を使用して製品を起動するときに変数値を設定します。
+ 特定のユーザーまたは管理者にのみポートフォリオへのアクセスを許可します。
+ 最小特権の原則に従い、タスクの実行に必要な最小限のアクセス許可を付与します。詳細については、 AWS Identity and Access Management (IAM) ドキュメントの[「最小特権の付与](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#grant-least-priv)」と[「セキュリティのベストプラクティス](https://docs.aws.amazon.com/IAM/latest/UserGuide/IAMBestPracticesAndUseCases.html)」を参照してください。

## エピック
<a name="provision-a-terraform-product-in-aws-service-catalog-by-using-a-code-repository-epics"></a>

### ローカルワークステーションをセットアップする
<a name="set-up-your-local-workstation"></a>


| タスク | 説明 | 必要なスキル | 
| --- | --- | --- | 
| (オプション) Docker をインストールします。 | 開発環境で AWS Lambda 関数を実行する場合は、Docker をインストールします。手順については、Docker ドキュメントの[「Docker Engine のインストール」](https://docs.docker.com/engine/install/)を参照してください。 | DevOps エンジニア | 
| Terraform 用の AWS Service Catalog エンジンをインストールします。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/provision-a-terraform-product-in-aws-service-catalog-by-using-a-code-repository.html) | DevOps エンジニア、AWS 管理者 | 

### GitHub リポジトリに接続する
<a name="connect-the-github-repository"></a>


| タスク | 説明 | 必要なスキル | 
| --- | --- | --- | 
| GitHub リポジトリの接続を作成します。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/provision-a-terraform-product-in-aws-service-catalog-by-using-a-code-repository.html) | AWS 管理者 | 

### Service Catalog で Terraform 製品を作成する
<a name="create-a-terraform-product-in-service-catalog"></a>


| タスク | 説明 | 必要なスキル | 
| --- | --- | --- | 
| Service Catalog 製品を作成します。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/provision-a-terraform-product-in-aws-service-catalog-by-using-a-code-repository.html) | AWS 管理者 | 
| ポートフォリオを作成します。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/provision-a-terraform-product-in-aws-service-catalog-by-using-a-code-repository.html) | AWS 管理者 | 
| Terraform 製品をポートフォリオに追加します。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/provision-a-terraform-product-in-aws-service-catalog-by-using-a-code-repository.html) | AWS 管理者 | 
| アクセスポリシーを作成します。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/provision-a-terraform-product-in-aws-service-catalog-by-using-a-code-repository.html) | AWS 管理者 | 
| カスタム信頼ポリシーを作成します。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/provision-a-terraform-product-in-aws-service-catalog-by-using-a-code-repository.html) | AWS 管理者 | 
| Service Catalog 製品に起動制約を追加します。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/provision-a-terraform-product-in-aws-service-catalog-by-using-a-code-repository.html) | AWS 管理者 | 
| 製品へのアクセスを許可します。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/provision-a-terraform-product-in-aws-service-catalog-by-using-a-code-repository.html) | AWS 管理者 | 
| 製品を起動します。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/provision-a-terraform-product-in-aws-service-catalog-by-using-a-code-repository.html) | DevOps エンジニア | 

### デプロイメントを確認する
<a name="verify-the-deployment"></a>


| タスク | 説明 | 必要なスキル | 
| --- | --- | --- | 
| デプロイを検証する。 | Service Catalog プロビジョニングワークフローには 2 つの AWS Step Functions ステートマシンがあります。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/provision-a-terraform-product-in-aws-service-catalog-by-using-a-code-repository.html)`ManageProvisionedProductStateMachine` ステートマシンのログをチェックして、製品がプロビジョニングされたことを確認します。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/provision-a-terraform-product-in-aws-service-catalog-by-using-a-code-repository.html) | DevOps エンジニア | 

### インフラストラクチャをクリーンアップ
<a name="clean-up-infrastructure"></a>


| タスク | 説明 | 必要なスキル | 
| --- | --- | --- | 
| プロビジョニング済み製品を削除します。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/provision-a-terraform-product-in-aws-service-catalog-by-using-a-code-repository.html) | DevOps エンジニア | 
| Terraform AWS Service Catalog の エンジンを削除します。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/provision-a-terraform-product-in-aws-service-catalog-by-using-a-code-repository.html) | AWS 管理者 | 

## 関連リソース
<a name="provision-a-terraform-product-in-aws-service-catalog-by-using-a-code-repository-resources"></a>

**AWS ドキュメント**
+ [Terraform 製品の開始方法](https://docs.aws.amazon.com/servicecatalog/latest/adminguide/getstarted-Terraform.html)

Terraformのドキュメント
+ [Terraform のインストール](https://learn.hashicorp.com/tutorials/terraform/install-cli)
+ [Terraform のバックエンド設定](https://developer.hashicorp.com/terraform/language/backend)
+ [Terraform AWS プロバイダーのドキュメント](https://registry.terraform.io/providers/hashicorp/aws/latest/docs)

## 追加情報
<a name="provision-a-terraform-product-in-aws-service-catalog-by-using-a-code-repository-additional"></a>

**アクセスポリシー**

```
{
    "Version": "2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": "s3:GetObject",
            "Resource": "*",
            "Condition": {
                "StringEquals": {
                    "s3:ExistingObjectTag/servicecatalog:provisioning": "true"
                }
            }
        },
        {
            "Action": [
                "s3:CreateBucket*",
                "s3:DeleteBucket*",
                "s3:Get*",
                "s3:List*",
                "s3:PutBucketTagging"
            ],
            "Resource": "arn:aws:s3:::*",
            "Effect": "Allow"
        },
        {
            "Action": [
                "resource-groups:CreateGroup",
                "resource-groups:ListGroupResources",
                "resource-groups:DeleteGroup",
                "resource-groups:Tag"
            ],
            "Resource": "*",
            "Effect": "Allow"
        },
        {
            "Action": [
                "tag:GetResources",
                "tag:GetTagKeys",
                "tag:GetTagValues",
                "tag:TagResources",
                "tag:UntagResources"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}
```

**信頼ポリシー**

```
{
    "Version": "2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "GivePermissionsToServiceCatalog",
            "Effect": "Allow",
            "Principal": {
                "Service": "servicecatalog.amazonaws.com"
            },
            "Action": "sts:AssumeRole"
        },
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::account_id:root"
            },
            "Action": "sts:AssumeRole",
            "Condition": {
                "StringLike": {
                    "aws:PrincipalArn": [
                        "arn:aws:iam::accounti_id:role/TerraformEngine/TerraformExecutionRole*",
                        "arn:aws:iam::accounti_id:role/TerraformEngine/ServiceCatalogExternalParameterParserRole*",
                        "arn:aws:iam::accounti_id:role/TerraformEngine/ServiceCatalogTerraformOSParameterParserRole*"
                    ]
                }
            }
        }
    ]
}
```