Nitric Terraform Providers

Nitric enables application portability and deployments through pluggable modules known as providers. This allows applications to be deployed with many different Infrastructure Automation technologies, including Terraform. Nitric has pre-built providers that use Terraform to deploy to AWS and Google Cloud, with Azure support planned.

All pre-built Terraform providers are IaC generating providers.

Prerequisites

The Terraform CLI is required to deploy the resulting Terraform Stack that Nitric generates. You can find the installation instructions for Terraform in the Terraform documentation.

The provider is built with the Cloud Development Kit for Terraform (CDKTF). Since CDKTF relies on Node.js, you'll need to have Node.js installed, you can read about the full CDKTF prerequisites in the CDKTF documentation.

Terraform providers are currently in preview, they're not recommended for production deployments. We recommend using the Pulumi Provider for production deployments until the Terraform providers are stable.

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

Available Terraform Providers

How Nitric integrates with Terraform

Nitric uses the Cloud Development Kit for Terraform (CDKTF) to generate Terraform code for your application. This code can be deployed using the standard Terraform CLI commands.

When you run nitric up in your project directory, Nitric will generate the Terraform code for your application, outputting the result to a directory named cdktf.out by default. You can then navigate into this directory and use the standard Terraform commands to deploy your application.

terraform init
terraform plan
terraform apply

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

If you project has more than one stack you'll be prompted to select the stack you want to deploy. Choose the stack that uses the Terraform provider to generate the Terraform code.

This will generate the Terraform code for your Nitric application into a folder named cdktf.out by default. You can change this via the outdir property and inspect the code before deploying.

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
Last updated on Oct 22, 2024