For anyone else interested in the ability to impor...
# general
r
For anyone else interested in the ability to import resources (as in good old fashion import resource into Cloudformation Stack's control), a preview of
cdk import
has now landed with the latest CDK! https://github.com/aws/aws-cdk/tree/master/packages/aws-cdk#cdk-import
a
This looks like the same thing that has been in AWS Console > CloudFormation for a while, allowing import of a floating resource into a stack. Unfortunately the types of resources available to import is very limited. Hopefully they are adding more, but it's another one of those CloudFormation things that will likely always lag behind and they have a lot of catching up to do.
r
Agreed. Def one of the more neglected portions of CloudFormation
a
Can you explain why this would be nice? trying to think on use-cases.
r
Essentially allows resources created with a third party IaC tool or via manual cloudformation to be imported and managed as first class CDK constructs without resorting to lossy traditional imports (either via stack import or lookups)
a
Use case: Need to tear down a stack but keep data (like S3 bucket) and then recreate the stack attaching to the old bucket. (I generally avoid this by putting persistence resources in their own stacks.)
r
^ True too! I think there are Backup and Disaster Recovery cases that benefit too.
a
But how this differentiates from the
lookup
? is transforming the resource into code?
I did some lookups for VPC/SG due those were created before CDK, for example, without stack or anything.
r
Lookup just retrieves information about a construct, but doesn't bring it under the stacks control. So you can't make direct modifications to those constructs
a
That makes sense.
So this takes ownership of the resource?
r
Correct!
a
But how you keep track of it in the typescript code?
I mean, once imported.
r
That's the manual part at the moment. You have to write the correct TypeScript/CDK code, and then run the
cdk import
command to connect un-created constructs with existing resources.
So it's the other way around, you'd write the code and then the CDK essentially pairs that code with an existing resources rather than creating a new one. It does make it error prone however, since you have to right the exact right code or you run into Drift issues (since it doesn't generate the code for you atm)