CloudFormation import CDK resource, Catch-22

0

I am in the process of updating a CDK app to include several tags.

There is a Networking stack that has somehow gotten out of alignment with the deployed resources. It looks like some external process destroyed and re-created the Public subnet, so the ARN of the existing subnet did not match the ARN in the Cloudformation (CF) stack. In an attempt to bring the CloudFormation stack and the existing resources back into alignment I removed the non-existent subnet from the CF template. I am now trying to import the existing subnet into the stack following the instructions here: https://aws.amazon.com/blogs/devops/how-to-import-existing-resources-into-aws-cdk-stacks/

One solution to using existing resources in a CDK app is to use a resource lookup in the code. This isn't an option here because the app has been used to do the networking setup for many accounts, so I can't change it to be a lookup without impacting the other accounts.

The instructions state that a new template must be created that includes all existing stack resources in addition to the resource that is being imported, and that template is used to update the stack to include the new resource.

The stack was deployed using the CDK, which puts a "CDKMetadata" section into the Template.

If I include that "CDKMetadata" section in the updated "Import" template then it triggers this error: "Invalid template property or properties [CDKMetadata]"

If I remove that section, then it triggers this error: "You have modified resources [CDKMetadata] in your template that are not being imported. Update, create or delete operations cannot be executed during import operations."

It seems like this will make it impossible to import any resources, unless I separately delete the CDKMetadata section. Is that the intended workflow? Am I missing some other solution?

1 Answer
0

Hello,

To answer the question, it Is possible to import resources using cdk these are the supported resources [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resource-import-supported-resources.html],

The error “you have modified resources [CDKMetadata] in your template that are not being imported. Update, create or delete operations cannot be executed during import operations” occurs when you modify an existing resource during a resource import operation. During an import operation, you can't create, update, and delete a resource.

CDK is under the impression that you are attempting both an import and an UPDATE/CREATE on a resource. In order to troubleshoot this issue, kindly compare the currently existing stack template to the import template. If that the CDK metadata differs on both templates. Cdk will assume that you wanted to update the metadata resource.

For further troubleshooting, I recommend that you open a support case with AWS so we can analyze the two templates.

AWS
answered 2 months ago
profile picture
EXPERT
reviewed a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions