Terraform provider: VPS servers, domains and DNS records as code

API & DocumentationInfrastructure & DevOps·· 9 views· 3 min read

If you already use Terraform, your Interweb VPS servers, domains and DNS records can live in the same files as everything else. You describe what you want, run terraform apply, and the provider makes the changes through our public API.

What it does

It has three resources. interwebmz_vps buys a VPS with credit, or manages one you have: power state, time zone and reverse DNS. interwebmz_domain registers a domain, or manages one you have: nameservers, transfer lock and renewal. interwebmz_dns_record handles the records of the DNS zone: A, AAAA, CNAME, MX, TXT, NS, SRV and CAA.

It also has five read-only data sources: products for sale and their prices (interwebmz_catalog_products and interwebmz_catalog_product), domain extensions (interwebmz_catalog_tlds), whether a domain can be registered (interwebmz_domain_availability) and your servers (interwebmz_servers).

What you need

Terraform, and an account with Interweb that has an API key. You create the key in the API Center of Meu Interweb. Go 1.22 or later is only needed if you want to build the provider from source.

Installing, step by step

1 In your Terraform file, declare the provider with the source interweb-mz/interwebmz, as in the example below.
2 Put your API key in the INTERWEB_API_KEY environment variable.
3 Run terraform init and then terraform apply.

The example from the README creates an A record for www:

terraform {
required_providers {
interwebmz = {
source = "interweb-mz/interwebmz"
version = "~> 1.0"
}
}
}

provider "interwebmz" {}

resource "interwebmz_dns_record" "www" {
domain = "example.co.mz"
name = "www"
type = "A"
value = "203.0.113.10"
ttl = 3600
}

export INTERWEB_API_KEY="sandbox_..."
terraform init
terraform apply

More examples and the full reference are in the provider repository. To build it yourself, download the source of the latest release and run:

go mod tidy
go build -o terraform-provider-interwebmz
go test ./...

To try your own build, point Terraform to it in ~/.terraformrc. The English README shows how.

The API key and its permissions

Purchases (a VPS, a domain registration) are paid with your account credit, within the spending limit of the key. Give the key the permissions for the areas your code will manage: see which permission each task needs.

Testing without spending

Start with a sandbox_ key. It reads your real data, but every write is simulated and nothing is charged. Once the plan does what you expect, swap it for a prod_ key.

Good to know

No double charges: each purchase goes with its own Idempotency-Key, so a retry never charges twice.

Destroy does not cancel: the API cannot cancel services or delete domains. terraform destroy only removes them from the state. You cancel in Meu Interweb.

A VPS you already bought: its purchase settings cannot change after the purchase. If you change them, the provider stops the plan instead of buying a second server.

Errors: 429 and 5xx answers are retried. Errors show the API code and the correlation_id for support.

Help

If the provider shows an error you do not understand, open a support ticket and include the correlation_id from the message. The code is in the provider repository, under the MIT license.

Ready to manage your account as code?

Download the latest release

SEE ALSO

Creating an API key

DNS through the API

Domains through the API

The repository on Interweb Git

SDKs and integrations, in the API documentation

RECOMMENDED PRODUCT

VPS server with root access

Resources of your own, the OS you choose, reinstall whenever you like. from 456,30 MT/mo (3-year plan, with coupon)

See plans
Was this answer helpful? Your answer helps us improve this article.