I want to resolve 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 CloudFormation console to import resources into an existing stack that was created outside of CloudFormation.
This error can occur when you use the CloudFormation console in the following scenarios:
- The resource that you're importing has a condition key that's associated with a condition that evaluates to false.
- You use the intrinsic function Fn::Transform or the transform template section, such as AWS::Serverless or AWS::Include, when you're importing a resource.
To resolve the error for conditional resources, the condition that's specified under the condition key must evaluate to true for the resource that you're importing.
To resolve the error for templates that use transforms, use the AWS Command Line Interface (AWS CLI) instead of the AWS CloudFormation console.
The AWS CLI requires you to explicitly provide imported resources for the create-change-set CloudFormation command.
Note: If you receive errors when you run AWS CLI commands, then see Troubleshoot AWS CLI errors. Also, make sure that you're using the most recent AWS CLI version.
Resolution
The following example uses the AWS CLI 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.
Import resources
Note: If your stack isn't in your default AWS Region, then add --region to your commands. Or, set and export the AWS_DEFAULT_REGION environment variable to change the default Region.
To import the resources, complete the following steps:
-
Create a resource import file that's named import.txt:
[
{
"ResourceType": "AWS::ECS::Cluster",
"LogicalResourceId":
"ECSCluster2"
,
"ResourceIdentifier": {
"ClusterName":"Cluster2"
}
}
]
-
To create a change set against your stack, run the 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 ARN of the change set and stores the ARN in the environment variable ID.
If your template uses transforms, then you must use CAPABILITY_AUTO_EXPAND.
-
(Optional) To wait for the change set to be created successfully, run the change-set-create-complete command:
aws cloudformation wait change-set-create-complete --change-set-name ${ID}
-
Use the AWS CloudFormation console to view the change set. Or, run the describe-change-set command:
aws cloudformation describe-change-set --change-set-name ${ID}
-
To apply the change set and import your resource into the stack, run the execute-change-set command:
aws cloudformation execute-change-set --change-set-name ${ID}
-
(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 type support