Back to tutorials

Your first O42 Terraform plan

Install the signed oauth42/oauth42 provider and confirm which tenant a read-only service account can access. The plan makes no managed resource changes.

Check your Terraform and O42 versions

Use Terraform 1.14 or newer in the 1.x series. This tutorial pins provider 0.1.0. The first verified compatible backend is O42 0.2.0 built from 56abf5440fecada981310bcaad5afd0f23209db4, or a compatible later build with its migrations applied.

Have an authorized tenant administrator create a dedicated service account with read access to the intended tenant. Record the tenant UUID and the HTTPS origin of the O42 API.

Configure a read-only provider

Save this configuration as main.tf in a new directory.

terraform {
  required_version = ">= 1.14, < 2.0"
  required_providers {
    oauth42 = {
      source  = "oauth42/oauth42"
      version = "= 0.1.0"
    }
  }
}

variable "endpoint" {
  type = string
}

variable "customer_id" {
  type = string
}

variable "ca_cert" {
  type    = string
  default = null
}

provider "oauth42" {
  endpoint    = var.endpoint
  customer_id = var.customer_id
  ca_cert     = var.ca_cert
  scopes      = ["read"]
}

data "oauth42_management_context" "current" {}

output "read_context" {
  value = {
    customer_id = data.oauth42_management_context.current.customer_id
    scopes      = data.oauth42_management_context.current.scopes
  }
}

Inject O42_CLIENT_ID and O42_CLIENT_SECRET into the Terraform process from your secret manager. Set TF_VAR_endpoint to the O42 HTTPS API origin and TF_VAR_customer_id to the tenant UUID. If your deployment uses a private CA, provide its PEM contents through TF_VAR_ca_cert.

Install and verify the connection

terraform init
terraform validate
terraform plan

Check that terraform init reports oauth42/oauth42 version 0.1.0 signed by key ID DF2E09CCFFBDED49. Keep the generated .terraform.lock.hcl with your configuration.

In the plan, verify that read_context.customer_id is the intended tenant UUID and read_context.scopes contains only read. The plan may show a new output even though it proposes zero managed resource changes. The plan is enough to verify the connection.

Before any later write or explicit action, review the exact change and obtain the approval required by your workflow. Keep the credentials and any sensitive Terraform artifacts in approved storage.