

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

# GitLab CI/CD を使用して Terraform、AWS CDK、CloudFormation テンプレートをデプロイする
<a name="using-gitlab-cicd"></a>

DPA には、Terraform をデプロイするための構成要素として使用する GitLab CI/CD テンプレートと AWS Cloud Development Kit (AWS CDK) CloudFormation IaC コードが含まれています。このセクションでは、このユースケースについて以下について説明します。
+ 標準化されたパイプライン構造
+ 再利用可能なステージとジョブ
+ パイプライン構造ルール
+ セキュリティスキャン用の統合ツール

## 前提条件
<a name="prerequisites-gitlab-cicd"></a>
+ アクティブな AWS アカウント
+ IaC テンプレートを使用してリソースをプロビジョニングするアクセス許可
+ GitLab CI/CD 機能をサポートする任意のタイプのライセンスフリー、プレミアム、またはエンタープライズバージョンの GitLab アカウント
+ 特定の Docker イメージでジョブを実行するように設定された GitLab 必須ランナー

## ツール
<a name="tools-gitlab-cicd"></a>
+ [cdk\$1nag](https://github.com/cdklabs/cdk-nag#readme) は、ルールパックを組み合わせてアプリケーションがベストプラクティスに準拠しているかどうかをチェック AWS CDK するオープンソースツールです。
+ [AWS CloudFormation Linter (cfn-lint)](https://github.com/aws-cloudformation/cfn-lint) は、CloudFormation YAML または JSON テンプレートを[AWS CloudFormation リソース仕様](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-resource-specification.html)と照合する linter です。また、リソースプロパティの有効な値の確認やベストプラクティスの遵守などの他のチェックも実行します。
+ [cfn\$1nag](https://github.com/stelligent/cfn_nag) は、パターンを検索して CloudFormation テンプレートの潜在的なセキュリティ問題を識別するオープンソースツールです。
+ [Checkov](https://www.checkov.io/1.Welcome/What%20is%20Checkov.html) は、IaC のセキュリティとコンプライアンスの設定ミスをチェックする静的コード分析ツールです。
+ [Infrastructure as Code Secure (KICS) ](https://github.com/Checkmarx/kics)は、開発サイクルの早い段階でセキュリティの脆弱性、コンプライアンスの問題、インフラストラクチャの設定ミスを特定するオープンソースツールです。
+ [tfsec](https://github.com/aquasecurity/tfsec) は、Terraform コードの設定ミスの可能性をチェックする静的コード分析ツールです。

## 指示
<a name="instructions-gitlab-cicd"></a>

1. `gitlab-ci` ディレクトリをコピーし、GitLab 組織グループにホストします。

1. アプリケーションが DPA テンプレートを含む GitLab 組織グループにアクセスできることを確認します。

1. アプリケーションの場合は、次のようにパイプラインの DPA 固有のエントリポイントを含めます。
   + Terraform

     ```
       include:
           - project: <GITLAB_GROUP_PATH/<REPOSITORY_NAME>
             ref: main # best practise to create release tag and use the same 
             file: gitlab-ci/entrypoints/gitlab/terraform-infrastructure.yml
     ```
   + AWS CDK

     ```
       include:
           - project: <GITLAB_GROUP_PATH/<REPOSITORY_NAME>
             ref: main # best practise to create release tag and use the same 
             file: gitlab-ci/entrypoints/gitlab/cdk-infrastructure.yml
     ```
   + CloudFormation

     ```
       include:
           - project: <GITLAB_GROUP_PATH/<REPOSITORY_NAME>
             ref: main # best practise to create release tag and use the same 
             file: gitlab-ci/entrypoints/gitlab/cf-infrastructure.yml
     ```

1. アプリケーションでは、 `DEV`および `INTEGRATION`環境でデプロイを有効にするために、次の変数を定義します。

   ```
     AWS_REGION: us-east-2 # region where deployment should happen
     DEV_AWS_ACCOUNT: 123456789012 # Dev environment AWS account number
     DEV_ARN_ROLE: arn:aws:iam::123456789012:role/dpa-gitlab-access-role # IAM role ARN that will be used to provision resources in Dev 
     DEV_DEPLOY: "true" # true / false to enable deployment to DEV environment
     DEV_ENV: "dev" # Dev environment name
     INT_AWS_ACCOUNT: 123456789012 # Integration environment AWS account number
     INT_ARN_ROLE: arn:aws:iam::123456789012:role/dpa-gitlab-access-role # IAM role ARN that will be used to provision resources in Integration 
     INT_DEPLOY: "true" # true / false to enable deployment to Integration environment
     INT_ENV: "int" # Integration environment name
   ```