cdktf-import
v0.1.1
Published
A CLI for importing terraform resources using CDKTF. Terraform can import existing infrastructure resources. This functionality lets you bring existing resources under Terraform management. We want to bring the same experience to CDKTF. This CLI is based
Downloads
4
Readme
CDKTF Import
A CLI for importing terraform resources using CDKTF. Terraform can import existing infrastructure resources. This functionality lets you bring existing resources under Terraform management. We want to bring the same experience to CDKTF. This CLI is based on the solution that comes from this comment on this Github issue.
Installation
npm i cdktf-import -g
Usage
cdktf-import <Resource_Name>.<Unique_ID> <Import_ID>
How it works
Assume resources exist, write the approximate cdktf code.
Change directory using this path
cd cdktf.out/stacks/<stack>
.Check
Unique_ID
incdk.tf.json
, as shown below:"resource": { "<Resource_Name>": { "<Unique_ID>": { "//": { "metadata": { "path": "<Path>", "uniqueId": "<Unique_ID>" } }, }, }, },
Initialize project by running command
terraform init
.Import resources using the values from the step 3
terraform import <Resource_Name>.<Unique_ID> <ID>
.Change directory to
cwd
.Run
cdktf diff <stack>
.
BIG THANKS to Xing Yahao for providing the solution.
License
CDKTF Import is distributed under the MIT License. Feel free to use, modify, and distribute this library in your projects.