pluginschema

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package pluginschema reads a provider's schemas by launching its plugin in-process, with no cloud calls and no provider configuration.

It exists because a fourth program now needs this. tools/survey-gen and tools/estate-gen each carry a verbatim copy of it, and estate-gen's copy says why: "Duplicated rather than shared because tools/survey-gen is package main, same as every other tool in this repository." That reason is real but it has a cheap fix, which is this package - an internal package both can import. Those two are deliberately left alone here, since each has gated tests that a refactor would have to re-run against a real provider; collapsing them into this is follow-up work, not a prerequisite for the program that needed a third copy.

The two-step - "init" in a scratch directory, then go-plugin in-process - is copied rather than reinvented, including the reason for going in-process: the JSON dump from "providers schema -json" carries resource schemas and resource identity schemas but no list-resource section, while the GetProviderSchema response carries all three.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Acquire

Acquire installs the pinned provider into the work directory and reads its full GetProviderSchema response. Acquire reads a provider's schemas and closes the plugin before returning. It is AcquireSession for the caller that wants nothing but the schemas, which is most of them.

func InstalledVersion

func InstalledVersion(workDir string, provider addrs.Provider) (string, bool)

InstalledVersion reports the exact version init resolved for provider inside workDir, when a caller acquired schemas without pinning an exact version (an empty Request.Version, a Request.Constraint or neither - #211's per-provider acquisition, which cannot know in advance which release satisfies an unconstrained or ranged requirement the way a hardcoded pin can).

The answer is read from the unpacked layout itself - workDir/.terraform/providers/<host>/<namespace>/<type>/<version>/<os_arch>/<binary> - via the same symlink-following walk Acquire needed to find the plugin executable in the first place ([findProviderBinary]'s doc comment explains why a plain walk cannot see it under TF_PLUGIN_CACHE_DIR), so this only ever disagrees with what Acquire itself launched if the layout changes out from under both.

ok is false when no provider plugin is present, which after a successful Acquire call should not happen; a caller more interested in "was this acquired at all" should be checking Acquire's own error instead.

func ResourceTypes

func ResourceTypes(ctx context.Context, req Request) (map[string]providers.Schema, error)

ResourceTypes reads one provider's managed resource type schemas, in the shape internal/live/lint and internal/live/identity both take.

The provider is launched but never configured: a schema read needs no cloud and no credentials.

Types

type Request

type Request struct {
	// InitBin is the choudoufu (or terraform) binary used to install the
	// provider.
	InitBin string

	// WorkDir is a directory this may write a configuration into and run
	// init in. The caller owns it, including removing it.
	WorkDir string

	// Source and Version pin the provider, as a registry source address
	// and an exact version. Version wins when both it and Constraint are
	// set.
	Source  string
	Version string

	// Constraint is a raw version constraint expression, written verbatim
	// into the fixture's "version" argument exactly as a required_providers
	// block would carry it (e.g. "~> 5.0", ">= 3.0, < 4.0"). It exists for
	// a caller that knows what a configuration under measurement declared
	// but not which exact release satisfies it - init resolves that itself,
	// the same way it would for the configuration's own author. Empty means
	// no constraint at all: any published version is acceptable, and init
	// picks the latest. Ignored when Version is set.
	Constraint string

	// Provider is the address the schemas come back under. It must be the
	// provider Source names.
	Provider addrs.Provider

	// Log receives progress lines. Nil discards them.
	Log io.Writer
}

Request is one provider to read schemas from.

type Session

type Session struct {
	// Schema is what [Acquire] would have returned.
	Schema providers.GetProviderSchemaResponse
	// contains filtered or unexported fields
}

Session is an acquired provider whose plugin is still running.

Acquire launches a plugin, reads the schemas and closes it, which is all a caller wanting schemas needs. A caller that wants the provider to COMPUTE something needs the process to outlive the schema read, and the difference matters for one specific reason: values a configuration cannot state statically because the provider derives them at plan time.

aws_acm_certificate.domain_validation_options is the case that motivated this. Its elements - one per domain in domain_name plus subject_alternative_names - are filled by the provider during PlanResourceChange, before any cloud call, which is how stock OpenTofu can plan the canonical ACM/Route53 validation pattern that this fork's static evaluator refuses. Nothing in the configuration or in any schema states the relationship; only the provider knows it.

A Session is NOT a cloud connection. PlanResourceChange for a create needs the provider configured, not credentialed, and the local test target is floci. Keep that distinction: "offline" here has always meant no cloud calls, and a plan call makes none.

func AcquireSession

func AcquireSession(ctx context.Context, req Request) (*Session, error)

AcquireSession installs the provider, launches its plugin, reads the schemas, and leaves the plugin RUNNING for the caller to use. The caller must Close the returned Session.

func (*Session) Close

func (s *Session) Close(ctx context.Context) error

Close stops the plugin. Safe to call twice, because the ordinary shape here is a defer beside an error path that already closed.

func (*Session) Configured

func (s *Session) Configured(ctx context.Context, configVal cty.Value) (providers.Configured, tfdiags.Diagnostics)

Configured returns the running provider, configured with configVal. The caller owns nothing: closing the Session closes this too.

Jump to

Keyboard shortcuts

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