

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 設定 CloudFormation StackSets 的組態套件
<a name="cfcn-byo-cfn-stacksets"></a>

本節說明如何設定 CloudFormation StackSets 的組態套件。此程序的兩個主要部分是：(1) 準備資訊清單檔案，以及 (2) 更新資料夾結構。

## 步驟 1：編輯現有的資訊清單檔案
<a name="cfcn-byo-cfn-stacksets-step-1"></a>

將新的 CloudFormation StackSets 資訊新增至您先前編輯的資訊清單檔案。

僅供檢閱，下列程式碼片段包含先前顯示的相同自訂資訊清單檔案，用於設定 SCPs或 RCPs 的組態套件。現在您可以進一步編輯此檔案，以包含 資源的詳細資訊。

```
---
region: us-east-1
version: 2021-03-15

resources:
  
  - name: block-s3-public-access
    description: To S3 buckets to have public access
    resource_file: policies/block-s3-public.json
    deploy_method: {{scp | rcp}}
    #Apply to the following OU(s)
    deployment_targets:
    organizational_units: #array of strings
    - OUName1
    - OUName2
```

下列程式碼片段顯示已編輯的範例資訊清單檔案，其中包含`resources`詳細資訊。的順序會`resources`決定建立`resources`相依性的執行順序。您可以根據您的業務需求編輯下列範例資訊清單檔案。

```
---
region: {{your-home-region}}
version: 2021-03-15

…truncated…

resources:
  - name: stackset-1
    resource_file: templates/create-ssm-parameter-keys-1.template
    parameters:
      - parameter_key: parameter-1
        parameter_value: value-1
    deploy_method: stack_set
    deployment_targets:
      accounts: # array of strings, [0-9]{12}
        - account number or account name
        - 123456789123
      organizational_units: #array of strings, ou ids, ou-xxxx
        - OuName1
        - OUName2 
    export_outputs:
      - name: /org/member/test-ssm/app-id
        value: $[output_ApplicationId]
    regions:
      - {{region-name}}

  - name: stackset-2
    resource_file: s3://bucket-name/key-name
    parameters:
      - parameter_key: parameter-1
        parameter_value: value-1
    deploy_method: stack_set
    deployment_targets:
      accounts: # array of strings, [0-9]{12}
        - account number or account name
        - 123456789123
      organizational_units: #array of strings
        - OuName1
        - OUName2 
regions:
  - {{region-name}}
```

下列範例顯示您可以在資訊清單檔案中新增多個 CloudFormation 資源。

```
---
region: us-east-1
version: 2021-03-15

resources:
  - name: block-s3-public-access
    description: To S3 buckets to have public access
    resource_file: policies/block-s3-public.json
    deploy_method: {{scp | rcp}}
    #Apply to the following OU(s)
    deployment_targets:
      organizational_units: #array of strings
        - Custom
        - Sandbox

  - name: transit-network
    resource_file: templates/transit-gateway.template
    parameter_file: parameters/transit-gateway.json
    deploy_method: stack_set
    deployment_targets:
      accounts: # array of strings, [0-9]{12}
        - Prod
        - 123456789123 #Network
      organizational_units: #array of strings
        - Custom
    export_outputs:
      - name: /org/network/transit-gateway-id
        value: $[output_TransitGatewayID]
    regions:
      - us-east-1
```

## 步驟 2：更新資料夾結構
<a name="cfct-byo-cfn-stacksets-step-2"></a>

當您更新資料夾結構時，您可以包含資訊清單檔案中的所有支援 CloudFormation 範本檔案和 SCP 或 RCP 政策檔案。確認檔案路徑符合資訊清單檔案中提供的路徑。
+ *範本*檔案包含要在 OUs 和帳戶中部署 AWS 的資源。
+ *政策*檔案包含範本檔案中使用的輸入參數。

下列範例顯示在[步驟 1 ](#cfcn-byo-cfn-stacksets-step-1)中建立的範例資訊清單檔案的資料夾結構。

```
- manifest.yaml
- policies/
   - block-s3-public.json
- templates/
   - transit-gateway.template
```