Terraform

Nitric's cloud portability is enabled through plugin interfaces known as providers. Providers allow applications built with Nitric to be deployed using a variety of Infrastructure Automation technologies, including Terraform.

Terraform Providers

The Nitric Terraform providers allow you to deploy Nitric applications using Terraform. Currently, a Terraform provider is in Preview for AWS, with support for other cloud providers coming soon. While the standard Nitric Providers deploy your application directly to the cloud, the Terraform providers act more like a Transpiler for the cloud infrastructure requirements, allowing Nitric to generate a Terraform stack using CDKTF.

The main benefits of using the Nitric Terraform provider are:

  • Infrastructure from Code: Define your application using Nitric and automatically generate the necessary Terraform code.
  • Terraform Ecosystem: Leverage the existing Terraform ecosystem for managing your cloud infrastructure.
  • Customization: Customize your cloud infrastructure using Terraform modules and resources.

You're also able to create your own Terraform provider for Nitric, this is the best option when you have existing Terraform Modules and expertise you want to reuse to deploy Nitric applications.

Enabling Nitric Terraform Providers

The Nitric Terraform providers are currently in preview, to enable them you'll need to enable beta-providers in your Nitric project. You can do this by adding the following to your project's nitric.yaml file:

preview:
  - beta-providers

Getting Started

To get started with the Nitric Terraform provider, you'll need to install the Nitric CLI and the Terraform CLI. You can find the installation instructions for both in the Nitric CLI and Terraform documentation.

Once you have the Nitric CLI and Terraform CLI installed, you can create a new Nitric project as usual, if you're new to Nitric, check out the Getting Started guide.

To use the Nitric Terraform provider, you'll need to create a new Nitric stack that uses the Terraform provider. You can do this by running the following command:

nitric stack new

This will create a new Nitric stack and prompt you to select a provider. Select the Terraform provider of your choice during this process.

Once you've created your Nitric stack, you can generate the Terraform code by running the following command:

nitric up

This will generate the Terraform code for your Nitric application. To deploy the application using Terraform, you can navigate into your Terraform stack directory and use the standard Terraform commands:

terraform init
terraform plan
terraform apply