Now Reading
Changing Full Terraform Applications to Pulumi

Changing Full Terraform Applications to Pulumi

2023-06-12 18:47:37

Over the past 2 years, we’ve seen an rising development of cloud growth groups migrating to Pulumi from Terraform. These groups typically have expertise with and significant funding in Terraform, however have additionally usually run into limits of expressivity, productiveness, scalability, or reliability with their current instruments. One of many first questions we hear once they determine to maneuver to Pulumi is “how will I migrate my current Terraform tasks over?”.

At this time, we’re excited to announce new help for changing complete Terraform tasks to Pulumi through the pulumi convert command within the Pulumi CLI. The brand new Terraform converter consists of help for Terraform modules, core options of Terraform 1.4, and the vast majority of Terraform built-in features, changing to Pulumi TypeScript, Python, Go, or C#. The brand new converter can considerably scale back the period of time it takes emigrate Terraform to Pulumi. Let’s dig in to study extra in regards to the new converter and how one can use it.

Traditionally, we now have provided a separate tf2pulumi device to transform small snippets of Terraform to Pulumi. The brand new converter is not a separate device. As of v3.71.0, you possibly can run the brand new converter instantly from the Pulumi CLI with the pulumi convert --from terraform command. And you’ll convert greater than small snippets – the brand new converter helps changing full Terraform applications.

The brand new help in pulumi convert builds upon Pulumi’s CrossCode foundations for offering common infrastructure as code help throughout all kinds of programming languages and conversion tooling between them. It additionally introduces a brand new idea of converter plugin within the Pulumi engine, which permits conversion instruments from different Infrastructure as Code platforms to be built-in into the identical pulumi convert expertise sooner or later, each as a part of the core undertaking, in addition to by different ecosystem companions and contributors.

A number of widespread use instances are supported through the brand new pulumi convert --from terraform help within the Pulumi CLI:

  • Changing your group’s current Terraform tasks to Pulumi
  • Changing your group’s current Terraform modules to Pulumi, to be consumed as a part of current Pulumi tasks
  • Changing third social gathering open supply Terraform modules or tasks which tackle a use case you need to incorporate into your current Pulumi tasks

Supported Terraform Options

The next main options are supported:

  • Variables, outputs, assets, and information sources
  • Terraform modules are transformed to Pulumi elements
  • Virtually all HCL2 expression syntax

In instances the place the converter doesn’t but help a characteristic, the pulumi convert command succeeds however generates a TODO within the type of a name to a notImplemented not_implemented notImplemented NotImplemented operate that may must be crammed in manually. For many tasks, the converter ought to have the ability to convert 90-95% of the code with none TODOs, with solely a small share of things to handle manually, considerably decreasing migration time in comparison with doing a complete migration by hand. We’re actively enhancing the converter by including help for lacking options and enhancing the general high quality of the transformed code to cut back the quantity of guide fix-ups required.

Changing a Actual World Program

Let’s stroll via changing a Terraform codebase to Pulumi. Avant Terraform Vault Setup is an open supply undertaking that gives a high-availability set up of Vault utilizing a wide range of managed AWS companies. It defines a reasonably advanced set up with dozens of AWS assets in over 1,000 traces of Terraform HCL, together with the primary program and a Vault module. Let’s convert it to Pulumi.

First, clone the repo and cd into the listing containing the Terraform undertaking:

$ git clone https://github.com/avantoss/vault-infra.git
$ cd vault-infra/terraform/foremost

Subsequent, run the converter:

$ pulumi convert --from terraform --language typescript --out pulumi
$ pulumi convert --from terraform --language python --out pulumi
$ pulumi convert --from terraform --language go --out pulumi
$ pulumi convert --from terraform --language csharp --out pulumi

pulumi convert

The transformed code is generated within the specified pulumi output listing. An entire Pulumi undertaking is generated, together with two major code recordsdata particular to this this program’s conversion:

  • index.js index.ts __main__.py foremost.go Program.cs Program.fs Program.vb App.java Pulumi.yaml comprises the transformed code for the primary program
  • vault.ts vault.py vault.go vault.cs comprises the Vault Pulumi element, transformed from the Terraform module

Addressing TODOs

The file for the Vault element makes up the majority of the implementation and comprises some TODOs emitted by the converter that have to be addressed manually.

For instance, the converter doesn’t but help the change, component, and break up built-in features.

const plainDomain = notImplemented("change(component(break up(":",var.vault_dns_address),1),"////","")");
plain_domain = not_implemented("change(component(break up(":",var.vault_dns_address),1),"////","")")
plainDomain := notImplemented("change(component(break up(":",var.vault_dns_address),1),"////","")");
var plainDomain = NotImplemented("change(component(break up(":",var.vault_dns_address),1),"////","")");

We will fill in an implementation. Notice that we get to make use of the complete expressiveness of the native and acquainted string manipulation libraries in our goal programming language, as an alternative of the comparatively constrained choices of the Terraform DSL.

See Also

const plainDomain = pulumi.output(args.vaultDnsAddress)
    .apply(a => a.break up(":")[1].change("//", ""));
plain_domain = pulumi.Output.from_input(args["vaultDnsAddress"]) 
    .apply(lambda a: a.break up(":")[1].change("//", ""))
plainDomain := args.VaultDnsAddress.ToStringOutput().ApplyT(func(a string) string {
	return strings.ReplaceAll(strings.Break up(a, ":")[1], "//", "")
}).(pulumi.StringOutput)
var plainDomain = args.VaultDnsAddress
    .Apply(a => a.Break up(':')[1].Substitute("//", ""));

Wrapping Up

After addressing the remaining TODOs and another tweaks in order that the code compiles, we are able to now run the transformed program with pulumi up to provision the Vault set up with Pulumi.

The converter has saved us a ton of time, changing over 1,000 traces of Terraform to a contemporary Pulumi language, with solely a small variety of guide fix-ups required. From right here, we are able to leverage our IDE and compiler to additional refactor and enhance the code, one of many many advantages of Pulumi!

Importing State

It’s nice that the brand new converter can migrate Terraform tasks to Pulumi for brand new deployments, however what if you wish to import current useful resource states from a .tfstate file to keep away from unnecessarily recreating your infrastructure?

In case you’re utilizing TypeScript or Go, there’s some further code that may be added to your transformed Pulumi program to import useful resource states from a .tfstate file. See the Importing Resources reference documentation for extra particulars.

We’re working to make this much more seamless with built-in help for importing state from .tfstate recordsdata in a future replace coming quickly.

Get Began

Assist for the brand new pulumi convert --from terraform command is now accessible in v3.71.0 of the Pulumi CLI. Download the newest Pulumi CLI and provides the brand new converter a attempt right this moment. In case you run into any points, please let us know or attain out within the Pulumi Community Slack with any questions!

Source Link

What's Your Reaction?
Excited
0
Happy
0
In Love
0
Not Sure
0
Silly
0
View Comments (0)

Leave a Reply

Your email address will not be published.

2022 Blinking Robots.
WordPress by Doejo

Scroll To Top