

# Import stacks into CloudFormation StackSets
<a name="stacksets-import"></a>

A stack import operation can import existing stacks into new or existing StackSets, so that you can migrate existing stacks to a StackSet in one operation.

For *self-managed* StackSets, the import operation can import stacks in the administrator account or in different target accounts and AWS Regions. For *service-managed* StackSets, the import operation can import any stack in the same AWS Organizations as the management account. 

The following are considerations and limitations when importing stacks into StackSets:
+ The import operation can import up to 10 stacks using inline stack IDs or up to 200 stacks using an Amazon S3 object.
+  The `NoEcho` property is not supported. Stacks that contain `NoEcho` won't be imported into new StackSets through StackSet import.
+ Stacks can only belong to one StackSet.
+ You can implement stack tags to the StackSet by specifying tags explicitly as parameters in the stack import operation.
+ A stack's custom parameter overrides aren't affected during the import operation.
+ Parameters of imported stack instances can't be updated using the **Edit StackSet details** option. You must use the **Override StackSet parameters**. For more information on overriding parameters, see [Override parameters on stacks](stackinstances-override.md).
+ The StackSets quotas and stack instances apply when importing stacks. For more information about quotas, see [Understand CloudFormation quotas](cloudformation-limits.md).

**Topics**
+ [Self-managed stack import for CloudFormation StackSets](self-managed-import.md)
+ [Service-managed stack import for CloudFormation StackSets](service-managed-import.md)
+ [Revert stack imports into CloudFormation StackSets](revert-stackset-import.md)

# Self-managed stack import for CloudFormation StackSets
<a name="self-managed-import"></a>

The CloudFormation stack import operation can import existing stacks into new or existing StackSets, so that you can migrate existing stacks to a StackSet in one operation. By using stack import, you avoid downtime and outages without deleting and recreating those resources. Once the stack is imported into a StackSet, the original stack will become a stack instance of the specified stack set.

**Considerations for self-managed stack imports**
+ The stack import operation requires an administrator account in which you create a StackSet and a target account that contains a stack.
+ The target account must have permission to use the `GetTemplate` operation with the input of stack ID or ARN. Because of that, your administrator account must be granted **AWSCloudFormationStackSetAdministrationRole** or **AWSCloudFormationStackSetsExectionRole** permissions.

**Topics**
+ [Import an existing stack into a new StackSet (console)](#import-stacks-to-stack-set)
+ [Import an existing stack into an existing StackSet (console)](#import-stack-to-existing-stackset)
+ [Import a stack into a StackSet (AWS CLI)](#importing-stack-to-stackset.cli)

## Import an existing stack into a new StackSet (console)
<a name="import-stacks-to-stack-set"></a>

Before you begin, identify the stack that you want to import.

1. Sign in to the AWS Management Console and open the CloudFormation console at [https://console.aws.amazon.com/cloudformation](https://console.aws.amazon.com/cloudformation/).

1. From the navigation pane, choose **StackSets**.

1. At the top of the **StackSets** page, choose **Create StackSet**.

1. On the **Choose a template** page, specify a template by one of the following options and choose **Next**.
   + Choose **Amazon S3 URL** and specify the URL for your template in the text box.
   + Choose **Upload a template file** and browse for your template.
   + Choose **From stack ID** and enter your stack ID.

1. On the **Specify StackSet details** page, enter the name of a StackSet you want to create and choose **Next**.

   (Optional) Enter a description of the StackSet.

1. On the **Configure StackSet options** page, review your choices and choose **Next**.

1. On the **Set deployment options** page, choose **Import stacks to stack set**.

1. Enter the stack ID of the stack you want to import in the **Stacks to import** field. For example, `arn:aws:cloudformation:us-east-1:123456789012:stack/StackToImport/f449b250-b969-11e0-a185-5081d0136786`.

   (Optional) Choose **Add another stack ID** and enter the stack ID of another stack you want to import. You may add up to 10 stacks per stack import operation.

1. Review your deployment options and choose **Next**.

1. On the **Review** page, review your choices and your StackSet's properties. When you are ready to import your stack into your StackSet, choose **Submit**.

**Results**: The imported stack is now a stack instance of the specified StackSet. To learn more about the stack import status, see [StackSets status codes](stacksets-concepts.md#stackset-status-codes).

## Import an existing stack into an existing StackSet (console)
<a name="import-stack-to-existing-stackset"></a>

Before you begin, identify the stack that you want to import.

1. Sign in to the AWS Management Console and open the CloudFormation console at [https://console.aws.amazon.com/cloudformation](https://console.aws.amazon.com/cloudformation/).

1. From the navigation pane, choose **StackSets**.

1. On the **StackSets** page, choose the StackSet that you want to import a stack into.

1. With the StackSet selected, choose **Add stacks to StackSet** from the **Actions** menu.

1. On the **Set deployment options** page, choose **Import stacks to stack set** and enter the stack ID of the stack you want to import in the **Stacks to import** field. For example, `arn:aws:cloudformation:us-east-1:123456789012:stack/StackToImport/f449b250-b969-11e0-a185-5081d0136786`.

   (Optional) Choose **Add another stack ID** and enter the stack ID of another stack you want to import. You may add up to 10 stacks per stack import operation.

1. Choose **Next**.

1. On the **Specify overrides** page, review your choices and choose **Next**.

1. On the **Review** page, review your choices and your StackSet's properties. When you are ready to create your StackSet, choose **Submit**.

**Results**: The imported stack is now a stack instance of the specified StackSet. To learn more about the stack import status, see [StackSets status codes](stacksets-concepts.md#stackset-status-codes).

## Import a stack into a StackSet (AWS CLI)
<a name="importing-stack-to-stackset.cli"></a>

**To import an existing stack into a new StackSet**  
The following `create-stack-set` command creates a StackSet and imports the specified stack. The stack to import is identified by its ARN. Replace the placeholder text with your own information.

```
aws cloudformation create-stack-set \
  --stack-set-name MyStackSet \
  --stack-id arn:aws:cloudformation:us-east-1:123456789012:stack/StackToImport/466df9e0-0dff-08e3-8e2f-5088487c4896 \
  --administration-role-arn arn:aws:iam::123456789012:role/AWSCloudFormationStackSetAdministrationRole \
  --execution-role-name AWSCloudFormationStackSetExecutionRole
```

**To import an existing stack into an existing StackSet**  
The following `import-stacks-to-stack-sets` command imports the specified stack into the *MyStackSet* StackSet. The stack to import is identified by its ARN. Replace the placeholder text with your own information.

```
aws cloudformation import-stacks-to-stack-set \
  --stack-set MyStackSet \
  --stack-ids arn:aws:cloudformation:us-east-1:123456789012:stack/StackToImport/f449b250-b969-11e0-a185-5081d0136786
```

To specify more than one stack, use the following format for the value of the `--stack-ids` option.

```
--stack-ids "arn_1" "arn_2"
```

**To clone the imported stack into other Regions and accounts**  
The following `create-stack-instances` command adds stack instances to your StackSet. Replace the placeholder text with your own information.

```
aws cloudformation create-stack-instances \
  --stack-set-name MyStackSet \
  --accounts '["account_ID_1","account_ID_2"]' \
  --regions '["region_1","region_2"]'
```

# Service-managed stack import for CloudFormation StackSets
<a name="service-managed-import"></a>

The CloudFormation stack import operation can import existing stacks into new or existing StackSets, so that you can migrate existing stacks to a StackSet in one operation. StackSets extends the functionality of stacks, so you can create, update, or delete stacks across multiple accounts and Regions with a single operation.

**Considerations for service-managed stack imports**
+ The stack import operation requires a management account or delegated admin account in which you can manage the associated AWS Organizations such as enabling trust access with StackSets.
+ The target accounts must be members of the AWS Organizations managed by the management account or delegated admin account.
+ Target stack exists in one of the target OUs.
+ The target account should be a member of AWS Organizations.
+ AWS Organizations access should be in the `ACTIVATED` state for the Organizations.
+ Stacks being imported should be present in any of the member accounts, and not the management account.

**Topics**
+ [Import a service-managed stack into a new StackSet (console)](#import-service-managed-stack-to-new-stackset)
+ [Create and import a service-managed stack into an existing StackSet (console)](#import-service-managed-stack-to-existing-stackset)
+ [Import a service-managed stack into an existing StackSet (console)](#import-service-managed-stack-to-existing-stackset-console)
+ [Importing a service-managed stack into a StackSet (AWS CLI)](#import-service-managed-stack-to-stackset.cli)

## Import a service-managed stack into a new StackSet (console)
<a name="import-service-managed-stack-to-new-stackset"></a>

Import a stack into a new StackSet using the AWS Management Console

To import a new stack into a StackSet, identify a stack that contains the resource you want to import.

1. Sign in to the AWS Management Console and open the CloudFormation console at [https://console.aws.amazon.com/cloudformation](https://console.aws.amazon.com/cloudformation/).

1. From the navigation pane, choose **StackSets**.

1. At the top of the **StackSets** page, choose **Create StackSet**.

1. On the **Choose a template** page, do the following:

   1. For **StackSet permission model** choose **Service-managed permissions**.

   1. For **Prerequisite - Prepare template**, choose **Template is ready**, and choose your template by using one of the following options:
      + For **Amazon S3 URL**, enter your Amazon S3 URL in the **Amazon S3 URL** field.
      + For **Upload a template file**, choose a CloudFormation template on your local computer.

   Accept your settings and choose **Next**.

1. On the **Specify StackSet details** page, do the following:

   1. Enter a StackSet name in the **StackSet name** box.

   1. (Optional) Enter a description in the **StackSet description** section.

   On the **Configure StackSet options** page, review your choices and choose **Next**.

1. On the **Set deployment options** page, do the following:

   1. For **Add stacks to stack set**, choose **Import stacks to stack set**.

   1. For **Stacks to import**, choose your stack import method.

      1. For **Stack ID** enter your stack ID.

      1. For **Stack URL** enter the Amazon S3 URL.

1. Under **Associate organizational units**, do the following:

   1. Choose **Associate with organization** to use root OU.

   1. Choose **Associate with organizational units (OUs)** to enter parent OU IDs for the stacks to import. For example, if `Stack 1` and `Stack 2` are under `OU1`, and `Stack 3` is under `OU2`, enter `OU1` and `OU2`.

   Accept your settings and choose **Next**.

1. Review your settings on the **Review** page and choose **Submit**.

## Create and import a service-managed stack into an existing StackSet (console)
<a name="import-service-managed-stack-to-existing-stackset"></a>

To import an existing stack into a new StackSet, identify a stack that contains the resource you want to import.

**To create a StackSet and import a stack**

1. Sign in to the AWS Management Console and open the CloudFormation console at [https://console.aws.amazon.com/cloudformation](https://console.aws.amazon.com/cloudformation/).

1. From the navigation pane, choose **StackSets**.

1. At the top of the **StackSets** page, choose **Create StackSet**.

1. On the **Choose a template** page, do the following:

   1. For **StackSet permission model** choose **Service-managed permissions**.

   1. For **Prerequisite - Prepare template**, choose **Template is ready**, and choose your template by using one of the following options:
      + For **Amazon S3 URL**, enter your Amazon S3 URL in the **Amazon S3 URL** field.
      + For **Upload a template file**, choose a CloudFormation template on your local computer.

   Accept your settings and choose **Next**.

1. On the **Specify StackSet details** page, do the following:

   1. Enter a StackSet name in the **StackSet name** box.

   1. (Optional) Enter a description in the **StackSet description** section.

   On the **Configure StackSet options** page, review your choices and choose **Next**.

1. On the **Set deployment options** page, do the following:

   1. For **Add stacks to stack set**, choose **Deploy new stacks**.

1. For the **Associate organizational units** section, do the following:

   1. Choose **Associate with organization** to use root OU.

   1. Choose **Associate with organizational units (OUs)** to enter parent OU IDs for the stacks to import. For example, if `Stack 1` and `Stack 2` are under `OU1`, and `Stack 3` is under `OU2`, enter `OU1` and `OU2`.

1. For **Specify regions** and **Deployment options**, review your choices.

   Accept your settings and choose **Next**.

1. Review your settings on the **Review** page and choose **Submit**.

## Import a service-managed stack into an existing StackSet (console)
<a name="import-service-managed-stack-to-existing-stackset-console"></a>

Choose your StackSet and identify the stack you want to import.

**To import a stack to an existing StackSet**

1. Sign in to the AWS Management Console and open the CloudFormation console at [https://console.aws.amazon.com/cloudformation](https://console.aws.amazon.com/cloudformation/).

1. From the navigation pane, choose **StackSets**.

1. Choose the StackSet you want to import a stack to, and then choose **Add stacks to StackSet** from the **Actions** drop-down.

1. On the **Set deployment options** page, do the following:

   1. For **Add stacks to stack set**, choose **Import stacks to stack set**.

   1. Under **Stacks to import**, do the following

      1. For **Stack ID**, enter your stack ID.

      1. For **Stack URL**, enter the Amazon S3 URL.

   1. Under **Associate organizational units**, do the following:

      1. Choose **Associate with organization** to use root OU.

      1. Choose **Associate with organizational units (OUs)** to enter parent OU IDs for the stacks to import. For example, if `Stack 1` and `Stack 2` are under `OU1`, and `Stack 3` is under `OU2`, enter `OU1` and `OU2`.

      Accept your settings and choose **Next**.

1. Review the **Specify overrides** page and choose **Next**.

1. Confirm and review the **Review** page and choose **Submit**.

## Importing a service-managed stack into a StackSet (AWS CLI)
<a name="import-service-managed-stack-to-stackset.cli"></a>

Once a StackSet is created, you can import your stacks by passing the stack ID's of the stacks being imported. You may also pass the OU ID list to which you want to map it to.

CloudFormation will import user provided stacks within those OUs and use those OUs as deployment targets for the StackSet. Stack IDs presented in the input will map to the nearest OU in OU ID list input internally. If a stack doesn't belong to an existing OU ID in the input list, then the AWS CLI will return the `StackNotFoundException` error.

The `import-stacks-to-stack-set` operation creates stack instances for the stacks in the OU ID input. The following AWS CLI examples use the `import-stacks-to-stack-set` operation to import a stack into a StackSet.
+ To use the `import-stacks-to-stack-sets` operation, specify `stack-ids` or `stack-ids-url` you want to import to your stack set.

  ```
  aws cloudformation import-stacks-to-stack-set \
    --stack-set-name ServiceMangedStackSet \
    --stack-ids "arn:123456789012:us-east-1:Stack1" \
    --organizational-unit-ids ou-examplerootid111-exampleouid111
  ```

  ```
  aws cloudformation import-stacks-to-stack-set \
    --stack-set-name ServiceMangedStackSet \
    --stack-ids-url https://amzn-s3-demo-bucket.s3.us-west-2.amazonaws.com/file-name.json \
    --organizational-unit-ids ou-examplerootid111-exampleouid111
  ```

**Note**  
The `import-stacks-to-stack-sets` operation, requires you to specify at least one organizational unit ID (OU ID) so that it can associate the stack being imported to that particular OU. This operation doesn't create stack instances for other member accounts in the associated OUs. To update member accounts for the associated OUs, use `create-stack-instances` or `update-stack-instances`.

`create-stack-set` creates stack instances for all the accounts under the OUs with a user provided template, either from direct upload or Amazon S3. The following AWS CLI examples use the `create-stack-set` operation to import a stack into a new StackSet.
+ To use the `create-stack-set` operation, specify your StackSet name and import a stack to a newly created StackSet.

  ```
  aws cloudformation create-stack-set \
    --template-url https://amzn-s3-demo-bucket.s3.us-west-2.amazonaws.com/file-name.json \
    --permission-model SERVICE_MANAGED \
    --auto-deployment Enabled=true
  ```

# Revert stack imports into CloudFormation StackSets
<a name="revert-stackset-import"></a>

If you have unwanted changes in your stack instance, you can revert the stack instance import.

When you revert a stack instance import, CloudFormation deletes the stack instance from the StackSet but retains the stack's resources.

To revert a stack import operation, complete the following procedure.

1. Specify a `DeletionPolicy` attribute of `Retain` for each resource that you want to keep after the stack instance is deleted. For more information, see [Reverting an import operation](resource-import-revert.md).

1. Delete stack instances from your StackSet. For more information, see [Delete stacks from CloudFormation StackSets](stackinstances-delete.md).

1. Delete your StackSet. For more information, see [Delete CloudFormation StackSets](stacksets-delete.md).