Back
Terraform

Deploy Next.js to Azure App Service with Terraform in 3 Commands

From zero to a live URL in under 10 minutes. No portal clicking. No manual config. Everything is code — and it costs $13/month.

JB
Josue Barros
3 min read
Deploy Next.js to Azure App Service with Terraform in 3 Commands

I deploy every project the same way: three Terraform commands and zero portal clicking. By the end of this post, you'll do the same.

Why Terraform for Azure?

Azure Portal is great for learning. But for anything you'll touch more than once, it's a liability.

  • You click "Create Resource," configure 15 fields, and forget what you changed in 3 months.
  • Your staging environment is "probably the same" as production. Probably.
  • When the new hire asks "how do I set up the project?" the answer is a 47-step Confluence doc nobody maintains.

Terraform solves all of this. Your infrastructure is code. Code lives in Git. Git has history. History is documentation.

The Config

Here's everything you need for a production-grade Next.js deployment on Azure:

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~> 4.0"
    }
  }
}

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "this" {
  name     = "rg-my-saas"
  location = "westus2"
}

resource "azurerm_service_plan" "this" {
  name                = "plan-my-saas"
  resource_group_name = azurerm_resource_group.this.name
  location            = azurerm_resource_group.this.location
  os_type             = "Linux"
  sku_name            = "B1"
}

resource "azurerm_linux_web_app" "this" {
  name                = "app-my-saas"
  resource_group_name = azurerm_resource_group.this.name
  location            = azurerm_resource_group.this.location
  service_plan_id     = azurerm_service_plan.this.id

  site_config {
    application_stack {
      node_version = "20-lts"
    }
    app_command_line = "npm run start"
    always_on        = true
  }

  app_settings = {
    SCM_DO_BUILD_DURING_DEPLOYMENT  = "true"
    WEBSITE_NODE_DEFAULT_VERSION    = "~20"
  }
}

The 3 Commands

terraform init      # Download the Azure provider
terraform plan      # Preview what will be created
terraform apply     # Create everything (type "yes")

That's it. 90 seconds later you have a resource group, a service plan, and a web app.

Push Your Code

az webapp up --name app-my-saas --resource-group rg-my-saas --runtime "NODE|20-lts"

This zips your project, uploads it, and triggers the build on Azure's side. One command.

What This Costs

B1 tier: $13/month. That's the cheapest paid tier with always-on, custom domains, and SSL. For a SaaS landing page or early-stage product, this is more than enough.

For production with autoscaling, you'd move to B2 ($26/mo) or P1v3. But start here.

The Pattern I Use for Every Project

project/
├── app/          # Next.js application
├── infra/        # Terraform configs
│   └── main.tf
└── README.md

Infrastructure and app evolve together. One PR, one review, one deploy. When someone asks "what runs in production?" — terraform show tells you everything.

What's Next

This is Episode 2 of my 24-episode Azure series on YouTube where I build a complete SaaS infrastructure from scratch. If you prefer video, check out the full series on my channel.

If you're building a SaaS and want auth, payments, database, and 200+ features pre-built — check out BoilerForge. The landing page you'd deploy with this Terraform config? That's the BoilerForge marketing site.

#terraform#azure#nextjs#app-service#deployment

Join the Newsletter

Subscribe to get my latest content by email.

We won't send you spam. Unsubscribe at any time.