

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 为组织中的账户部署资源管理器
<a name="manage-service-all-org-with-stacksets"></a>

通过使用 AWS CloudFormation StackSets，您可以定义并部署到组织中由管理的所有帐户 AWS Organizations。定义堆栈集时，您可以指定要在您指定的所有目标账户 AWS 区域 和所有目标账户中创建的 AWS 资源。当所有账户都属于同一个组织时，你可以利用与 Organizations 的 CloudFormation 集成，让这些服务来处理跨账户角色的创建。您可以在组织中启用自动部署，这样可以自动将堆栈实例部署到您将来可能会添加到目标组织或组织单位（OU）的新账户。如果您从组织中移除账户，则 CloudFormation 会自动删除作为组织堆栈实例一部分部署的所有资源。有关的更多信息 StackSets，请参阅《*AWS CloudFormation 用户指南》 AWS CloudFormation StackSets*中的 “[使用](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/what-is-cfnstacksets.html)”。

您可以使用 CloudFormation StackSets 在组织 AWS 资源探索器 中的所有账户中开启和配置，在每个启用的区域中创建索引，并在需要时创建视图。

**重要**  
如果您尝试在某个区域中设置聚合器索引，则必须确保该账户在任何其他区域中都没有现有的聚合器索引。将聚合器索引降级到本地索引后，必须等待 24 小时才能将另一个索引提升为该账户的新聚合器索引。

## 先决条件
<a name="stacksets-prereqs"></a>

 CloudFormation StackSets 要使用资源管理器将资源管理器部署到组织中的账户，您或组织管理员必须先执行以下步骤以启用具有服务管理权限的堆栈：

1. 的组织必须[已启用所有功能](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_org_support-all-features.html)。如果组织仅启用了整合账单功能时，您无法创建具有服务托管权限的堆栈集。

1. [开启和 Organizations CloudFormation 之间的可信访问权限](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stacksets-orgs-enable-trusted-access.html)。这会授予在组织管理账户中创建所需角色的 CloudFormation 权限，成员账户 CloudFormation 将部署资源管理器索引和视图。

现在，您可以创建具有服务托管权限的堆栈集。

**重要**  
您必须在组织的管理账户中创建堆栈集。 CloudFormation 是一项区域服务，因此您只能在最初创建堆栈集的区域中查看和管理您创建的堆栈集。

## 为资源管理器创建堆栈集
<a name="stacksets-create"></a>

完全部署的资源管理器必须部署两个堆栈集。
+ 第一个堆栈集创建聚合器索引和默认视图，允许用户在账户中的所有区域中搜索资源。

  将此堆栈集***仅***部署到要在其中创建聚合器索引的单个区域。
+ 第二个堆栈集创建本地索引和默认视图。本地索引将其内容复制到聚合器索引。

  将此堆栈集部署到账户中***除***包含聚合器索引的区域之外的所有已启用区域。不要在部署堆栈的账户中选择任何未启用的区域。如果您这样做，则部署将失败。

以下部分中列出了这些内容中每一个的示例模板。有关如何使用这些模板创建堆栈集的 step-by-step说明，请参阅*《AWS CloudFormation 用户指南》*中的[使用服务管理权限创建堆栈集](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stacksets-getting-started-create.html#stacksets-orgs-associate-stackset-with-org)。

将这些堆栈集部署到您的组织后，您所选范围内的每个账户（组织或组织单位）在指定的区域中都有一个聚合索引，在其他每个区域都有本地索引。

## 示例 CloudFormation 模板
<a name="stacksets-sample-templates"></a>

以下示例模板创建了账户的聚合器索引和默认视图，该视图可以在部署索引的账户中跨所有区域搜索资源。

------
#### [ YAML ]

```
Description: >-
  CFN Stack setting up ResourceExplorer with an Aggregator Index, and a new Default View.
Resources:
  Index:
    Type: 'AWS::ResourceExplorer2::Index'
    Properties:
      Type: AGGREGATOR
      Tags:
        Purpose: ResourceExplorer CFN Stack
  View:
    Type: 'AWS::ResourceExplorer2::View'
    Properties:
      ViewName: DefaultView
      IncludedProperties:
        - Name: tags
      Tags:
        Purpose: ResourceExplorer CFN Stack
    DependsOn: Index
  DefaultViewAssociation:
    Type: 'AWS::ResourceExplorer2::DefaultViewAssociation'
    Properties:
      ViewArn: !Ref View
```

------
#### [ JSON ]

```
{
    "Description": "CFN Stack setting up ResourceExplorer with an Aggregator Index, and a new Default View.",
    "Resources": {
        "Index": {
            "Type": "AWS::ResourceExplorer2::Index",
            "Properties": {
                "Type": "AGGREGATOR",
                "Tags": {
                    "Purpose": "ResourceExplorer CFN Stack"
                }
            }
        },
        "View": {
            "Type": "AWS::ResourceExplorer2::View",
            "Properties": {
                "ViewName": "DefaultView",
                "IncludedProperties": [{
                    "Name": "tags"
                }],
                "Tags": {
                    "Purpose": "ResourceExplorer CFN Stack"
                }
            },
            "DependsOn": "Index"
        },
        "DefaultViewAssociation": {
            "Type": "AWS::ResourceExplorer2::DefaultViewAssociation",
            "Properties": {
                "ViewArn": {
                    "Ref": "View"
                }
            }
        }
    }
}
```

------

以下示例模板在每个已启用的区域中为除了具有聚合器索引的账户之外的所有账户创建本地索引。它还创建了一个默认视图，用户只能在该区域中搜索资源。用户必须使用聚合器区域中的视图进行搜索，才能在所有区域中搜索资源。

------
#### [ YAML ]

```
Description: >-
  CFN Stack setting up ResourceExplorer with a Local Index, and a new Default View.
Resources:
  Index:
    Type: 'AWS::ResourceExplorer2::Index'
    Properties:
      Type: LOCAL
      Tags:
        Purpose: ResourceExplorer CFN Stack
  View:
    Type: 'AWS::ResourceExplorer2::View'
    Properties:
      ViewName: DefaultView
      IncludedProperties:
        - Name: tags
      Tags:
        Purpose: ResourceExplorer CFN Stack
    DependsOn: Index
  DefaultViewAssociation:
    Type: 'AWS::ResourceExplorer2::DefaultViewAssociation'
    Properties:
      ViewArn: !Ref View
```

------
#### [ JSON ]

```
{
    "Description": "CFN Stack setting up ResourceExplorer with a Local Index, and a new Default View.",
    "Resources": {
        "Index": {
            "Type": "AWS::ResourceExplorer2::Index",
            "Properties": {
                "Type": "LOCAL",
                "Tags": {
                    "Purpose": "ResourceExplorer CFN Stack"
                }
            }
        },
        "View": {
            "Type": "AWS::ResourceExplorer2::View",
            "Properties": {
                "ViewName": "DefaultView",
                "IncludedProperties": [{
                    "Name": "tags"
                }],
                "Tags": {
                    "Purpose": "ResourceExplorer CFN Stack"
                }
            },
            "DependsOn": "Index"
        },
        "DefaultViewAssociation": {
            "Type": "AWS::ResourceExplorer2::DefaultViewAssociation",
            "Properties": {
                "ViewArn": {
                    "Ref": "View"
                }
            }
        }
    }
}
```

------