What is people's recommendation when moving from a...
# general
What is people's recommendation when moving from a large terraform base to pulumi? tf2pulumi is lacking tf 0.12 support, so I can't test its quality of output. I suspect it's going to be a rewrite from scratch?
I assume the lack of response means "rewrite from scrach"?
https://github.com/pulumi/tf2pulumi may give you a head start. There is probably some work to factor your source into logical modules. https://github.com/pulumi/pulumi-terraform can also work with existing infrastructure deployed with Pulumi if you want to keep using terraform and add new resources that reference your existing terraform resources via Pulumi.
If there is a large pile of TF, then using
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).
Yeah, we've got around 3000 lines of TF. Most of it uses just the no
syntax, so might be better to backport than waiting for tf2pulumi to support tf 0.12
Is there also an "easy" way to convert all the existing tf state to pulumi state or do we have to import all our resources one by one?
Looks like this is what is required: https://www.pulumi.com/blog/adopting-existing-cloud-resources-into-pulumi/ to get this right, we need to add
to every pulumi resource, run the program, and then remove the
statement again?
Okay, I think I'm either overcomplicating it myself or I'm not getting it. At this point moving an existing customer stack with over 200 (terraform) resources seems not feasible. I think I'll have to skip this stack and wait for the next opportunity, either a way smaller environment or green-field.
There's a shortcut you can use if you are 1:1 with Terraform (for example if you used
). By adding a little dozen line or so script in your project - you should be able to automatically
all resources from a
. 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
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
JSON file referenced in step 1 3. Create a mapping table of Pulumi type names (like
) to Terraform type names (like
) for all the different types you use (most likely only 20-30) 4. Add a call to
(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
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
in the near future - but for now it's something that is very possible with just a handful of lines of code.