terraform

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package terraform is the format of Terraform registry repositories (decision 0040): the modules and Terraform provider packages that users store in terraform repositories, which the module registry, the provider registry and the network mirror serve. It reads the paths of what is stored, keeps the package index, computes the h1: hashes of a Terraform provider package's archives, and makes the checks a registry download runs. The Terraform backend's state is decision 0041's, under a package type of its own.

A repository's terraformType chooses what it indexes. A MODULE repository indexes each module zip at <ns>/<name>/<system>/<version>.zip as version <version> of package <ns>/<name>/<system>. A PROVIDER repository indexes the files of a Terraform provider package's release at [<folders>/]<ns>/<type>/<version>/ as version <version> of package <ns>/<type>: its archives, its SHA256SUMS, the SHA256SUMS's signature and its manifest. Any other file, a module zip in a PROVIDER repository and the reverse included, is stored and not indexed, and so is everything in a repository without terraformType. The format sets no property.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func H1

func H1(r io.ReaderAt, size int64) (h1 string, ok bool, err error)

H1 is the h1: hash of the zip in r, of size bytes, as Terraform computes it for an archive of a Terraform provider package (internal/getproviders/hash.go: dirhash.HashZip with dirhash.Hash1) and records it in its lock file: Go's module hash over every entry, directories included, by name. ok is false for content that is not a zip whose entries can all be read within maxInflated, for which the network mirror lists no hash (decision 0040). err is a failure to read r itself.

func KeyID

func KeyID(armored string) (string, error)

KeyID is the long ID, in upper-case hex, of the first key in an ASCII-armored public key block: the key_id the registry protocol lists beside the key.

func ProviderPackageName

func ProviderPackageName(ns, typ string) (string, bool)

ProviderPackageName is the package index's name, <ns>/<type>, of the Terraform provider package that a registry or network mirror request names, normalised as the index normalises the folders a release is stored under, so a request finds it in whatever case either is written. ok is false for a namespace or type that Terraform's rules refuse.

func Serves

func Serves(t repo.PackageType) bool

Serves reports whether t is the Terraform registry's package type. The backend's terraformbackend is another.

func Shasum

func Shasum(sums []byte, name string) (string, bool)

Shasum returns the SHA-256 that a SHA256SUMS document lists for the file name, as Terraform reads the document: the first field of the first line whose second field is the name. ok is false when no line names it.

Types

type Archive

type Archive struct {
	// Path is the archive's repository-relative path.
	Path string `json:"path"`
	OS   string `json:"os"`
	Arch string `json:"arch"`
	// SHA256 is the content the hash is of. A later index of the version
	// reuses the hash while the archive keeps that content, so a release
	// deployed file by file reads each archive once.
	SHA256 string `json:"sha256"`
	// H1 is the archive's h1: hash, empty for content that is no zip.
	H1 string `json:"h1,omitempty"`
}

Archive is one archive of a version of a Terraform provider package.

type Handler

type Handler struct {
	// The generic format admits writes under every package type's deploy
	// policy: a file the index cannot use is stored all the same.
	generic.Handler
}

Handler is the Terraform registry format, which the item service calls on every write and delete in a terraform repository, whichever API carried it.

func (Handler) Deleted

func (Handler) Deleted(
	ctx context.Context,
	env format.Env,
	c repo.Config,
	removed []types.Item,
) error

Deleted settles each version a delete or a move took files from: another path may now hold a place the removed file held, and a version left with none is gone already, as the item service pruned it.

func (Handler) Deleting

Deleting runs before a file is removed. The item service drops the file's version link with it, and Deleted settles the rest.

func (Handler) Deployed

func (Handler) Deployed(ctx context.Context, env format.Env, c repo.Config, it types.Item) error

Deployed settles the version of a file the repository's terraformType indexes, from the tree: a deploy may make the file its version's, or take that place from another path.

func (Handler) Inspect

func (Handler) Inspect(
	ctx context.Context,
	env format.Env,
	c repo.Config,
	w format.Write,
) (any, error)

Inspect hashes an archive of a Terraform provider package before the write's transaction, which then indexes it without decompressing anything. Other content needs no reading.

func (Handler) Reindex

func (Handler) Reindex(ctx context.Context, env format.Env, c repo.Config) error

Reindex rebuilds the repository's index from its tree: the module index of a MODULE repository, the Terraform provider package index of a PROVIDER one, and none for a repository without terraformType. A PROVIDER repository's archives are hashed anew before the transaction that rebuilds the index, so no decompression holds the store's write lock; the transaction hashes only an archive stored in between.

type Kind

type Kind int

Kind is the part a file plays in a version of a Terraform provider package.

const (
	// KindArchive is one platform's zip,
	// terraform-provider-<type>_<version>_<os>_<arch>.zip, which the
	// registry protocol calls a package and the network mirror an archive.
	KindArchive Kind = iota + 1
	// KindSums is terraform-provider-<type>_<version>_SHA256SUMS.
	KindSums
	// KindSignature is the detached GPG signature of the SHA256SUMS,
	// terraform-provider-<type>_<version>_SHA256SUMS.sig.
	KindSignature
	// KindManifest is terraform-provider-<type>_<version>_manifest.json.
	KindManifest
)

The files of a Terraform provider package's release (decision 0040).

type Meta

type Meta struct {
	Archives map[string]Archive `json:"archives"`
}

Meta is the package index's metadata of a version of a Terraform provider package: its archives by platform, "<os>_<arch>". A module version has none.

func ReadMeta

func ReadMeta(b []byte) (Meta, error)

ReadMeta reads a version's Meta.

type Module

type Module struct {
	Namespace, Name, System string
	// Version is the semantic version, without the "v" a file name may
	// spell it with (jf terraform publish's tags carry one).
	Version string
	// V reports a file name that spells the version with a "v".
	V bool
}

Module is a module version's zip as the index reads its path, <ns>/<name>/<system>/<version>.zip (decision 0040). The namespace, name and system are kept as written: Terraform keeps the case of the first two and sends them as written.

func ParseModule

func ParseModule(p string) (Module, bool)

ParseModule reads a module zip's repository-relative path; ok is false for any other file, which a MODULE repository stores without indexing it.

func (Module) Package

func (m Module) Package() string

Package is the module's name in the package index, <ns>/<name>/<system>.

func (Module) Path

func (m Module) Path() string

Path is where the zip is stored.

type ProviderPackageFile

type ProviderPackageFile struct {
	// Namespace and Type are the folders' names as Terraform normalises an
	// address, which it sends in lower case: the index's package is
	// <ns>/<type> in that form, whatever case the folders are stored in.
	Namespace, Type string
	Version         string
	Kind            Kind
	// OS and Arch are an archive's platform.
	OS, Arch string
}

ProviderPackageFile is a file of a Terraform provider package's version as the index reads its path, [<folders>/]<ns>/<type>/<version>/<file> (decision 0040).

func ParseProviderPackageFile

func ParseProviderPackageFile(p string) (ProviderPackageFile, bool)

ParseProviderPackageFile reads the repository-relative path of a file of a Terraform provider package; ok is false for any other file, such as HashiCorp's key-specific _SHA256SUMS.<keyid>.sig, which a PROVIDER repository stores without indexing it. The type and version in the file name must be the folders', the type compared without regard to case. Folders before the namespace are ignored, as in JFrog's example, which adds one.

func (ProviderPackageFile) Package

func (f ProviderPackageFile) Package() string

Package is the Terraform provider package's name in the package index, <ns>/<type>.

func (ProviderPackageFile) Platform

func (f ProviderPackageFile) Platform() string

Platform is an archive's "<os>_<arch>", the key the network mirror lists it under.

type Release

type Release struct {
	// Repo is the repository's key, which the refusals name.
	Repo string
	// Archive is the archive's file name and ArchiveSHA256 its stored
	// content's SHA-256.
	Archive, ArchiveSHA256 string
	// SumsName and Sums are the SHA256SUMS file's name and content.
	SumsName string
	Sums     []byte
	// SignatureName and Signature are the signature's file name and
	// content.
	SignatureName string
	Signature     []byte
}

Release is a Terraform provider package's archive with the files a registry download is checked against (decision 0040): the stored archive, its version's SHA256SUMS and the SHA256SUMS's detached signature. Signatures are checked when an archive is downloaded through the registry, never on deploy, since the files arrive by separate PUTs in any order and the key pair may be replaced later.

type Verified

type Verified struct {
	// Shasum is the SHA-256 the SHA256SUMS lists for the archive, the
	// registry download answer's shasum.
	Shasum string
	// KeyID is the long ID, in upper-case hex, of the key that signed the
	// SHA256SUMS.
	KeyID string
}

Verified is what a release that passes Check proves.

func Check

func Check(r Release, keys []string) (Verified, error)

Check makes decision 0040's checks of a registry download of r's archive, in its order, against keys, the ASCII-armored public keys of the repository's GPG key pairs, primary first:

  1. there is a key;
  2. the SHA256SUMS lists the archive's file name with the stored archive's SHA-256, read as Terraform reads it, from the first line whose second field is the file name;
  3. the signature verifies over the SHA256SUMS with one of the keys.

A failed check is a 409 RejectionError naming what is missing or wrong. A key that cannot be read verifies nothing; one that has expired since it signed still does, as Terraform accepts it.

Directories

Path Synopsis
Package terraformtest builds Terraform registry content for tests (role 2 of epic #526: Terraform modules and Terraform provider packages that artifactweave stores): GPG key pairs, the files of a Terraform provider package's release laid out and signed as HashiCorp publishes them, and module zips.
Package terraformtest builds Terraform registry content for tests (role 2 of epic #526: Terraform modules and Terraform provider packages that artifactweave stores): GPG key pairs, the files of a Terraform provider package's release laid out and signed as HashiCorp publishes them, and module zips.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL