colossal-room-15708
11/27/2019, 1:47 AMswift-painter-31084
12/01/2019, 3:57 AMwhite-balloon-205
tf2pulumi
will save you a ton of time. I would honestly consider porting back to TF 0.11 compatible syntax so you can use tf2pulumi. I’ll bet that’s net less work than rewriting from scratch (assuming thousands of lines of TF).colossal-room-15708
12/01/2019, 10:47 AM${}
syntax, so might be better to backport than waiting for tf2pulumi to support tf 0.12import
to every pulumi resource, run the program, and then remove the import
statement again?white-balloon-205
tf2pulumi
). By adding a little dozen line or so script in your project - you should be able to automatically import
all resources from a .tfstate
.
I'll see if we can get this checked in somewhere - but I've seen it used with at least one customer - here's an outline in the meantime:
1. Add a config setting to allow passing a path to a .tfstate
file to import resources from that state.
2. Write some code in your Pulumi program to extract the Terraform resource name and cloud provider id of each resource from the .tfstate
JSON file referenced in step 1
3. Create a mapping table of Pulumi type names (like aws:elasticache/cluster:Cluster
) to Terraform type names (like aws_elasticache_cluster
) for all the different types you use (most likely only 20-30)
4. Add a call to pulumi.runtime.registerStackTransformation
(https://www.pulumi.com/docs/reference/pkg/nodejs/pulumi/pulumi/runtime/#registerStackTransformation) at the beginning of your Pulumi program (before any resources are registered), which transform every resource by adding a import: <id>
to it, looking up the <id>
based on (2) and (3) above only if (1) is set.
The result is that every resource will automatically try to import the matching Terraform resource.
I'll share a working code example soon - but hopefully the above gives an idea of the technique. We plan to try to make this a "built-in" feature of tf2pulumi
in the near future - but for now it's something that is very possible with just a handful of lines of code.