Working with Terraform

CodeScoring.Save supports two types of Terraform repositories:

  • Proxy — caches providers and modules from a registry, or providers from a network mirror.
  • Hosted — stores your own provider ZIPs and module archives.

Neither type stores Terraform state.

Creating a Repository

Open a project, click Create repository, and select Format: Terraform and Type: Proxy or Hosted. See Repository management for common fields. The repository page provides installation-specific URLs under Useful snippets.

Proxy Repository

Upstream typeURL to enterWhat clients can install
registry (default)Proxy URL: registry base, e.g. https://registry.terraform.ioProviders from that hostname via the Mirror or Registry API; modules via the Registry API
network_mirrorNetwork mirror root URL, e.g. https://mirror.example.com/providers/Providers via the Mirror API only; one mirror can serve several source hostnames

Example: create a mirror-backed proxy through the API with an admin token:

curl -X POST https://save.example.com/api/v1/repos \
  -H "Authorization: Bearer $ADMIN_JWT" \
  -H "Content-Type: application/json" \
  -d '{
    "project": "infra",
    "name": "terraform-proxy",
    "format": "terraform",
    "repository_type": "proxy",
    "enabled": true,
    "remote_url": "https://mirror.example.com/providers/",
    "settings": {"upstream_type": "network_mirror"}
  }'

For a registry, Save verifies provider ZIPs against SHA256SUMS signed with keys supplied by the registry. For a mirror, Save trusts the mirror's h1: or zh: hashes (h1: takes precedence); it cannot verify the publisher's signature. Upstream credentials are sent only to the configured scheme, host and port.

Cache TTL, seconds applies to metadata (default 3600). For offline installs, download each required provider platform and module version through Save in advance. Listing versions does not cache the archives.

For modules, the upstream must return an HTTP(S) ZIP or tar.gz archive, or a GitHub source with an explicit ref, e.g. git::https://github.com/acme/vpc.git?ref=v1.0.0. Save fetches GitHub archives from codeload.github.com.

Hosted Repository

Set Provider hostname to the hostname used in provider source addresses for the Registry API. The default is registry.terraform.io; for an internal registry, use a name such as registry.example.com.

Client Configuration

Put CLI settings in ~/.terraformrc (%APPDATA%\terraform.rc on Windows, or TF_CLI_CONFIG_FILE in CI). SAVE_API_KEY is a robot account API key with artifacts.read and artifacts.download.

Providers Through Network Mirror API

Use a network mirror with any Terraform repository. Enter the Save URL using HTTPS, including the trailing slash:

provider_installation {
  network_mirror {
    url = "https://save.example.com/cs-save/terraform/infra/terraform-proxy/"
  }
}

credentials "save.example.com" {
  token = "<SAVE_API_KEY>"
}

Keep provider sources unchanged, e.g. source = "hashicorp/aws", and run terraform init. Omit direct {} to install providers exclusively through Save. To lock packages for several platforms, pass the mirror explicitly:

terraform providers lock -net-mirror=https://save.example.com/cs-save/terraform/infra/terraform-proxy/ \
  -platform=linux_amd64 -platform=linux_arm64

Providers and Modules Through Registry API

Map the source hostname to one hosted repository or registry proxy to use the Provider Registry API or Module Registry API. For signed provider metadata, remove any matching mirror rule. Example with Provider hostname registry.example.com:

host "registry.example.com" {
  services = {
    "providers.v1" = "https://save.example.com/cs-save/terraform/infra/terraform-hosted/v1/providers/"
    "modules.v1"   = "https://save.example.com/cs-save/terraform/infra/terraform-hosted/v1/modules/"
  }
}

credentials "registry.example.com" {
  token = "<SAVE_API_KEY>"
}

Use source = "registry.example.com/acme/demo" for a provider or source = "registry.example.com/acme/vpc/aws" for a module. Shorthand such as acme/demo selects registry.terraform.io. Keep the credentials with the host mapping so the Save key is not sent directly to the source registry.

Hosted provider installs through this API require METADATA_SIGNING_ENABLED=true and SECRETS_ENCRYPTION_KEY. Signing is off by default; module and mirror installs do not require it. Save generates a repository GPG key on first use. To replace it, use Useful snippets → Set the signing key with repo.update permission.

Modules Through Save Discovery

Set Module alias on a hosted repository or a registry proxy and use the Save hostname in credentials. In the project's .tf file, join the alias and module namespace with __:

module "vpc" {
  source  = "save.example.com/infra-hosted__acme/vpc/aws"
  version = "1.0.0"
}

The alias is unique across Save and cannot be changed once set. UI/API creation defaults it to <project>-<repository> if available and valid (1–30 lowercase letters, digits or hyphens). Seeded repositories have no alias; set one before using discovery. Repository-specific Registry API URLs do not need it.

Publishing to a Hosted Repository

Use a robot key with artifacts.upload and a SemVer version without a leading v or build metadata. Save returns 201 for a new archive, 200 for identical bytes, and 409 for different bytes at the same coordinates.

Providers

Build one ZIP per OS/architecture. Put the terraform-provider-<type>* binary at the archive root and preserve execute permissions for Unix targets:

chmod +x terraform-provider-demo_v1.0.0
zip terraform-provider-demo_1.0.0_linux_amd64.zip terraform-provider-demo_v1.0.0
curl -H "Authorization: Bearer $SAVE_API_KEY" \
  -T terraform-provider-demo_1.0.0_linux_amd64.zip \
  https://save.example.com/cs-save/terraform/infra/terraform-hosted/v1/providers/acme/demo/1.0.0/download/linux/amd64

The URL determines the filename. If you send Content-Disposition, its filename must match terraform-provider-<type>_<version>_<os>_<arch>.zip. The keep-latest policy counts versions, not platform ZIPs. Marking one platform as a release protects the whole version from manual deletion and ordinary cleanup.

Modules

Place the module files at the root of a .tar.gz, .tgz or .zip archive. Any filename with the matching extension is accepted; Save serves it as module.tar.gz or module.zip.

tar -czf module.tar.gz -C ./module .
curl -H "Authorization: Bearer $SAVE_API_KEY" \
  -T module.tar.gz \
  https://save.example.com/cs-save/terraform/infra/terraform-hosted/v1/modules/acme/vpc/aws/1.0.0/module.tar.gz

Troubleshooting

Check the provider index and module discovery endpoint:

curl -fsS -H "Authorization: Bearer $SAVE_API_KEY" \
  https://save.example.com/cs-save/terraform/infra/terraform-proxy/registry.terraform.io/hashicorp/aws/index.json
curl -fsS https://save.example.com/.well-known/terraform.json
  • Discovery returns HTML. Route /.well-known/terraform.json at the host root to Save. With the default base path, expect {"modules.v1":"/cs-save/terraform-modules/v1/"}. Discovery serves modules only.
  • A proxy listing returns 404 for a cached version. When refreshing metadata, Save returns an explicit upstream 404 even if the archive is still stored locally.
  • Versions are visible, but download returns 401. Check artifacts.download and the shared SECRETS_ENCRYPTION_KEY on all replicas. Run terraform init again for a fresh download ticket; ticket URLs expire after 10 minutes.
  • Hosted provider package returns 503. Enable metadata signing or use the Mirror API.
  • Upload returns 413. Check the ingress limit and HOST_TERRAFORM_MAX_FILE_SIZE (default 1 GiB). Archive validation also limits packages to 10,000 entries and 4 GiB uncompressed.
Was this page helpful?