Skip to content

Integrations

Terraform provider

Manage services as code; read services, lookups and members.

Terraform provider for Atlas

Manage Atlas service registrations as code, and read the registry, lookups and cluster membership from Terraform.

KindNameUse
Resourceatlas_serviceRegister an instance (databases, appliances, anything that can't register itself)
Data sourceatlas_servicesEvery instance matching filters, e.g. to feed load balancers
Data sourceatlas_serviceOne instance by ID
Data sourceatlas_lookupThe instance Atlas would route to
Data sourceatlas_membersCluster members
Data sourceatlas_nodeThe connected node

See docs/ and examples/main.tf.

Use it before the Registry release

Build it, then point Terraform at the binary:

cd terraform-provider-atlas
go build -o ~/go/bin/terraform-provider-atlas .
# ~/.terraformrc (on Windows: %APPDATA%/terraform.rc)
provider_installation {
  dev_overrides {
    "manziosee/atlas" = "/home/you/go/bin"
  }
  direct {}
}

Test

Unit tests run anywhere. Acceptance tests run Terraform against a live node:

go test ./...
TF_ACC=1 ATLAS_ADDR=http://127.0.0.1:8080 ATLAS_TOKEN=<admin token> go test ./...

Publishing to the Terraform Registry

The Registry only publishes from a public repository named terraform-provider-atlas, with GPG-signed GitHub releases. This folder is ready to become that repository:

  1. Create manziosee/terraform-provider-atlas and push this folder's contents to it. Replace the replace line in go.mod with a tagged github.com/manziosee/atlas version.
  2. Create a GPG key. Add the private key and passphrase as the GPG_PRIVATE_KEY and PASSPHRASE repository secrets.
  3. Copy release.yml.example to .github/workflows/release.yml there. Then push a tag such as v0.1.0; GoReleaser builds and signs the release.
  4. Sign in to registry.terraform.io with GitHub, choose Publish → Provider, and add the public GPG key.

atlas_service

A service instance registered in Atlas. The node the provider talks to owns it and runs its health check.

Use health_check for instances Terraform manages, such as databases, appliances and external endpoints. A ttl_seconds instance turns unhealthy after one missed TTL and is removed after three, unless something else sends heartbeats.

Example

resource "atlas_service" "orders_db" {
  id           = "orders-db-primary"
  name         = "orders-db"
  address      = "10.0.4.20:5432"
  version      = "16.4"
  tags         = ["primary", "postgres"]
  health_check = "tcp://10.0.4.20:5432"
}

Arguments

  • name (Required) — Service name.
  • address (Required) — host:port.
  • id (Optional) — Stable ID; generated when omitted. Changing it replaces the instance.
  • version (Optional) — Version label.
  • tags (Optional, Set of String) — Up to 16 tags.
  • health_check (Optional) — http(s)://, tcp:// or grpc(s):// URL on the address.
  • check_interval_seconds, unhealthy_threshold, healthy_threshold (Optional) — Check tuning; need health_check.
  • ttl_seconds (Optional) — Heartbeat TTL. Not with health_check.
  • draining (Optional, default false) — Keep the record but send it no traffic.

Attributes

  • node_id, region — Owning node and its region.
  • health — unknown, healthy or unhealthy as last read.
  • revision, updated_at — Revision and last change.

Behaviour

  • Updates use PUT, so settings removed from the configuration are cleared.
  • If the instance is deleted or expires outside Terraform, the next plan creates it again.

Import

terraform import atlas_service.orders_db orders-db-primary

Data sources

atlas_services

Every instance matching the filters.

data "atlas_services" "payments" {
  name   = "payments"
  health = "healthy"
  tags   = ["primary"]
}
  • Filters (all optional): name, region, health, version, node_id, tags.
  • instances — List of instances (id, name, address, node_id, region, version, tags, health, health_check, ttl_seconds, draining, revision).
  • addresses — Sorted list of their addresses.

atlas_service

One instance by id, with the same attributes as above.

atlas_lookup

The instance the node selects, using the same rules as clients and DNS.

data "atlas_lookup" "payments" {
  name   = "payments"
  region = "eu"
  key    = "user-42"
}
  • name (Required); region, key, tags, stale (include, prefer-live, exclude), latency (nearest, off), tolerance (Optional).
  • address, instance — The selected instance.

atlas_members

  • members — Every member (id, addr, api_addr, region, state).
  • alive — Sorted IDs of alive members.

atlas_node

The connected node: id, region, addr, version, commit.

Improve this pageSource: terraform-provider-atlas/README.md, terraform-provider-atlas/docs/resources/service.md, terraform-provider-atlas/docs/data-sources/services.md