How do I resolve the "This template does not include any resources to import" error in AWS CloudFormation?

3 minute read
0

I receive the following error in the AWS CloudFormation console: "This template does not include any resources to import. Learn more."

Short description

You receive this error when you use the AWS CloudFormation console to import resources into an existing stack that was created outside of CloudFormation.

This error can occur when you use the AWS CloudFormation console in scenarios with any of the following:

  • Conditional resources. The resource that you're importing has a condition key associated with a condition that evaluates to false.
  • AWS Serverless Application Model (AWS SAM) templates. The AWS CloudFormation console doesn't support the Transforms section when importing resources. You can't import a resource with a template that uses the AWS::Serverless transform.
  • Fn::Transform. The AWS CloudFormation console doesn't support the use of the intrinsic function Fn::Transform when importing resources.

You can use the AWS Command Line Interface (AWS CLI) instead of the AWS CloudFormation console to resolve this error for templates using:

  • AWS SAM
  • Fn::Transform

To resolve this error for conditional resources, make sure that the condition specified under the condition key evaluates to true for the resource being imported.

The AWS CLI requires you to explicitly provide imported resources using the CloudFormation command, create-change-set.

Note: If you receive errors when running AWS CLI commands, make sure that you’re using the most recent AWS CLI version.

Resolution

In the following example, the AWS CLI is used to import an existing AWS::ECS::Cluster resource into a CloudFormation stack:

Resources:
  ...
  ECSCluster2:
    Condition: MyCondition
    Type: AWS::ECS::Cluster
    DeletionPolicy: Retain
    Properties:
      ClusterName: Cluster2

Note: Before you proceed to the next steps, make sure that the condition MyCondition evaluates to true.

To import the resource using the AWS CLI, complete the following steps:

Note: If your stack isn't in your default AWS Region, then add --region to your commands, or change the default Region by setting and exporting the AWS_DEFAULT_REGION environment variable.

1.    Create a resource import file called import.txt. For example:

[
    {
        "ResourceType": "AWS::ECS::Cluster",
        "LogicalResourceId":
            "ECSCluster2"
        ,
        "ResourceIdentifier": {
            "ClusterName":"Cluster2"
        }
    }
]

2.    To create a change set against your stack, run the following create-change-set command:

ID=$(aws cloudformation create-change-set --stack-name testStack --change-set-name testSet --resources-to-import file://import.txt --change-set-type IMPORT --template-body file://template.yaml --capabilities CAPABILITY_AUTO_EXPAND  --query 'Id' --output text)

Note: Replace testStack with your stack name and template.yaml with your CloudFormation template file name. The preceding command returns the Amazon Resource Name (ARN) of the change set and stores the ARN in the environment variable ID.

Note: You must use CAPABILITY_AUTO_EXPAND only if your template uses transformations.

3.    (Optional) To wait for the change set to be created successfully, run the following command:

aws cloudformation wait change-set-create-complete --change-set-name ${ID}

4.    View the change set using the AWS CloudFormation console. Or, use the following describe-change-set command:

aws cloudformation describe-change-set --change-set-name ${ID}

5.    To apply the change set and import your resource into the stack, run the following command:

aws cloudformation execute-change-set --change-set-name ${ID}

6.    (Optional) To verify that all properties in your template match with your resource, use drift detection on the resource.


Related information

Import an existing resource into a stack using the AWS CLI

Resources that support import and drift detection operations

AWS OFFICIAL
AWS OFFICIALUpdated 2 years ago