Skip to content

Authentication

The provider authenticates with an API key that belongs to one organization, and needs that organization’s id. Both come from the environment, so neither lands in a .tf file.

In the customer panel at panel.virtscale.nl, open Settings, find the API keys card and choose Create API key. Choose the access first. The dialog starts on Read-only, which cannot apply anything: for Terraform choose Full access or Custom.

Access Scopes Use it for
Full access write Everything on these pages, projects included. Not members or API keys
Custom Pick per area A narrower key. Tick Manage compute, Manage network and Manage storage for instances, SSH keys, firewalls, public IPs, VPCs and S3
Read-only read plan and refresh only, never apply

A Custom key with only those three cannot create, rename or delete projects: that needs the write scope, which Full access carries. Reading projects needs only Manage compute.

What each resource needs:

You use The key needs
virtscale_instance, virtscale_ssh_key compute:write
virtscale_public_ip, virtscale_instance_firewall network:write
virtscale_vpc network:write, and compute:read to find its project
virtscale_s3_bucket, virtscale_s3_access_key storage:write
virtscale_project (create, rename, delete) write
Data sources compute:read; virtscale_caller needs no scope

The panel also asks for an expiry (90 days unless you choose a date or Never) and for where the key may be used from. Under Source:

Source What it does
Default Shown only for a key that can write. The key is limited to the address you create it from: one address, the one VirtScale sees, which is your router’s public address if you are behind one
Only these networks One IPv4 or IPv6 network per line. A request from any other address is refused
Any address No limit

A key that can write and was created with Default works only from the machine you created it on. For a CI runner or any other machine, choose Only these networks and list the addresses it runs from, or Any address. A key cannot be changed afterwards: to change where it works, create a new key and revoke the old one.

The panel shows the secret once and cannot show it again. Copy it before you close the dialog. If you lose it, create a new key and revoke the old one. The API operation behind the dialog is Create an API key.

VIRTSCALE_ORGANIZATION takes the organization’s id, a UUID, not its name. The panel shows only the start of it. The API returns all of it:

curl -s https://api.virtscale.nl/v1/me -H "Authorization: Bearer $VIRTSCALE_API_KEY"

The id is organizations[0].org_id in the answer. An API key names one organization, so there is one entry.

read -rs VIRTSCALE_API_KEY && export VIRTSCALE_API_KEY
export VIRTSCALE_ORGANIZATION=<organization id>

read -rs keeps the key out of your terminal and your shell history. In a pipeline, take both values from the CI system’s secret store.

Attribute Environment variable Default
api_key VIRTSCALE_API_KEY None
organization VIRTSCALE_ORGANIZATION None
endpoint VIRTSCALE_ENDPOINT https://api.virtscale.nl

A missing key or organization stops the run at once, with the attribute and the variable named.

The provider block accepts api_key and organization as attributes, and an attribute wins over the environment. Do not use them for the key: a .tf file is committed, copied and pasted. Leave the block empty:

provider "virtscale" {}

The virtscale_caller data source says who the key is. It fails early, naming the organization, when the key does not belong to the one you configured. That is easier to read than the 404 of the first resource.

data "virtscale_caller" "me" {}

output "organization_id" {
  value = data.virtscale_caller.me.organization_id
}

output "scopes" {
  value = data.virtscale_caller.me.scopes
}

Run tofu apply in a folder that holds only this block and the provider declaration. It creates nothing and prints both outputs.

Your first instance.