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
Example: create a mirror-backed proxy through the API with an admin token:
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:
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:
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:
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 __:
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:
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.
Troubleshooting
Check the provider index and module discovery endpoint:
- Discovery returns HTML. Route
/.well-known/terraform.jsonat 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
404for a cached version. When refreshing metadata, Save returns an explicit upstream404even if the archive is still stored locally. - Versions are visible, but download returns
401. Checkartifacts.downloadand the sharedSECRETS_ENCRYPTION_KEYon all replicas. Runterraform initagain 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 andHOST_TERRAFORM_MAX_FILE_SIZE(default 1 GiB). Archive validation also limits packages to 10,000 entries and 4 GiB uncompressed.
