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.
| Kind | Name | Use |
|---|---|---|
| Resource | atlas_service | Register an instance (databases, appliances, anything that can't register itself) |
| Data source | atlas_services | Every instance matching filters, e.g. to feed load balancers |
| Data source | atlas_service | One instance by ID |
| Data source | atlas_lookup | The instance Atlas would route to |
| Data source | atlas_members | Cluster members |
| Data source | atlas_node | The 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:
- Create
manziosee/terraform-provider-atlasand push this folder's contents to it. Replace thereplaceline ingo.modwith a taggedgithub.com/manziosee/atlasversion. - Create a GPG key. Add the private key and passphrase as the
GPG_PRIVATE_KEYandPASSPHRASErepository secrets. - Copy
release.yml.exampleto.github/workflows/release.ymlthere. Then push a tag such asv0.1.0; GoReleaser builds and signs the release. - 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://orgrpc(s)://URL on the address.check_interval_seconds,unhealthy_threshold,healthy_threshold(Optional) — Check tuning; needhealth_check.ttl_seconds(Optional) — Heartbeat TTL. Not withhealth_check.draining(Optional, defaultfalse) — Keep the record but send it no traffic.
Attributes
node_id,region— Owning node and its region.health—unknown,healthyorunhealthyas 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.