Imagine deploying a fully working Azure infrastructure with production-ready Terraform modules directly from your application code. This isn't a dream - it's Nitric! We've just released support for generating Terraform for Azure, and in this post, I'll walk you through how it works, from code to cloud in minutes, with a special focus on using AI to enhance the development experience.
Prefer a video version? Check it out below:
Prerequisites
Before we begin, make sure you have the following installed:
# macOSbrew install nitrictech/tap/nitric# Windows (using scoop)scoop bucket add nitric https://github.com/nitrictech/scoop-bucket.gitscoop install nitric# Linuxcurl -L "https://nitric.io/install?version=latest" | bash
For more installation options and dependency information, review the full installation guide.
Initial Setup
Let's create a new Nitric project:
nitric new my-azure-app ts-starter
This will create a new project with the following structure:
my-azure-app/├── services/│ └── api.ts├── .gitignore├── nitric.yaml└── package.json
Install the project dependencies:
cd my-azure-appyarn install # or your preferred package manager
Project Setup
Let's start with a simple Nitric project. Open the services/api.ts
file and replace its contents with the following Express application code:
import { http } from '@nitric/sdk'import express from 'express'const app = express()// Health check endpointapp.get('/health', (req, res) => {res.json({ status: 'ok', timestamp: new Date().toISOString() })})// Echo endpointapp.get('/echo', (req, res) => {res.json({message: 'Echo received',data: req.query,timestamp: new Date().toISOString(),})})// Wrap the Express app with Nitric's HTTP resourcehttp(app, () => {console.log('Application started')})
This code creates an Express application with:
- A health check endpoint that returns the current status and timestamp
- An echo endpoint that returns the received query parameters along with a timestamp
The Express app is wrapped using Nitric's HTTP resource, making it deployable to the cloud. The nitric.yaml
file contains the default configuration that tells Nitric:
- Where to find services using glob patterns
- How to build them using a standard Node.js Dockerfile
Generating Terraform for Azure
To deploy our application to Azure, we'll create a new Terraform stack:
nitric stack new tf azure-tf
This generates a new stack configuration file where we can specify:
- The Azure region
- Organization details
- Subscription ID
Deploying with Terraform
Running nitric up
does all the heavy lifting:
- Builds the Docker image
- Analyzes the infrastructure needs
- Generates Terraform modules using CDKTF
The generated Terraform configuration is stored in the cdktf.out
folder, containing:
- The main
cdk.tf.json
file - All the cloud Terraform modules such as service, storage, etc.
Key Generated Modules
- HTTP Proxy Module
Location: cdktf.out/stacks/my-azure-app/assets/../nitric_modules/http_proxy
- Provisions an API Gateway
- Connects to our service
- Includes input variables
- Service Module
Location: cdktf.out/stacks/my-azure-app/assets/../nitric_modules/service
- Handles Docker image builds
- Manages container app hosting
- Sets up permissions and IAM assignments
You can find all the Nitric Azure Terraform modules in the Nitric repository.
Deploying the Infrastructure
To deploy the generated infrastructure:
cd cdktf.out/stacks/my-azure-app/terraform initterraform apply
This will create all necessary Azure resources, including:
- API Management
- Container Apps
- Resource Groups
- And more
Testing the Deployment
Once deployed, we can test our endpoints using curl:
# Health checkcurl https://your-api-url/health# Echo endpointcurl https://your-api-url/echo?message=Hello
Enhancing Development with AI
One of the most powerful features of this workflow is the ability to use AI to enhance development. For example, we can use Cursor AI to add new features to our application. Let's add a to-do list feature using Nitric's KV store:
- Open the Cursor AI chat (ctrl+l)
- Request the implementation:
use nitric KV store to manage a to-do list. use https://nitric.io/docs/keyvalue to help
- The AI will generate a full CRUD implementation including:
- Properly scoped KV resource
- Required permissions
- API endpoints
- Example curl commands
The AI-generated code can be quickly reviewed and implemented, making it easy to extend your application with new features.
Testing the New Features
Test the new to-do list endpoints:
# Create a todo, replace the data to match your generated todo structurecurl -X POST https://your-api-url/todos -d '{"title":"New Todo"}'# List todoscurl https://your-api-url/todos# Get specific todocurl https://your-api-url/todos/{id}# Delete todocurl -X DELETE https://your-api-url/todos/{id}'
Regenerating Infrastructure
After making changes with AI assistance:
- Run
nitric up
to regenerate Terraform - The new deployment will include:
- Storage account
- Storage table for KV store
- Updated permissions
- New Docker image
Cleaning Up
When you're done, clean up all resources with:
terraform destroy
Conclusion
That's how you can build Azure infrastructure using AI and Terraform with Nitric - a powerful combination that makes cloud development more efficient and accessible.
Get Started
Ready to get started?
- Browse the Nitric GitHub repository for the latest code
- Read our comprehensive documentation to learn more
- Follow our guides to build your first cloud app
Join our Discord community to ask questions or share feedback.
Checkout the latest posts

GenAI Made Terraform More Relevant Than Ever
Infrastructure as Code is more alive than ever, but it is no longer something teams should write line by line.

The Deployment Bottleneck No One Talks About
The real bottleneck might not be in your pipeline but rather in how your application interacts with cloud services.

Can AI Generate Functional Terraform?
LLMs can generate syntactically correct Terraform HCL code, but can they generate Terraform
Get the most out of Nitric
Ship your first app faster with Next-gen infrastructure automation