Terraform Advanced — Provider Alternatives

less than 1 minute read

You don’t always need a full custom provider.


The restapi Provider

Manage any REST API as a Terraform resource:

terraform {
  required_providers {
    restapi = {
      source  = "Mastercard/restapi"
      version = "~> 1.18"
    }
  }
}

resource "restapi_object" "server" {
  path         = "/api/v1/servers"
  create_method = "POST"
  data         = jsonencode({
    name = "web-1"
    size = "large"
  })
  id_attribute = "id"
}

The shell Provider

Run shell commands as resources:

resource "shell_script" "dns_record" {
  lifecycle_commands {
    create = "aws route53 ... && echo '{\"id\": \"record-123\"}'"
    read   = "aws route53 list-resource-record-sets ..."
    delete = "aws route53 ... delete"
  }

  environment = {
    DOMAIN = var.domain
  }
}

The http Data Source

Read-only data from any HTTP endpoint:

data "http" "my_ip" {
  url = "https://api.ipify.org?format=json"
}

locals {
  my_ip = jsondecode(data.http.my_ip.response_body).ip
}

Quick Decision

Read-only data?          → data "http"
Simple REST CRUD?        → restapi provider
Shell script wrapper?    → shell provider
Complex, reusable logic? → Build custom provider

What’s Next?

Practice custom provider concepts.

← Simple CRUD Provider Practice Exercises →

Updated: