Skip to content

package tf

import "github.com/cloudboss/unobin/pkg/gogen/tf"

Package tf parses Terraform provider schemas (from "terraform providers schema -json") and converts them to gogen.ResourceSchema values for Go code generation.

Types

type Adapter

type Adapter struct {
    Fetcher Fetcher
    // contains filtered or unexported fields
}

Adapter implements gogen.SchemaAdapter backed by TF provider schemas. provider is the fully-qualified TF registry source (e.g. "hashicorp/aws" or "ansible/ansible"). The part after the final slash becomes the local provider name for the terraform block and the Go package name.

func NewAdapter

func NewAdapter(fetcher Fetcher, provider, version string) *Adapter

NewAdapter creates an Adapter for the given fully-qualified provider source. version is an optional TF version constraint (e.g. "~> 5.0").

func (*Adapter) FetchConfiguration

func (a *Adapter) FetchConfiguration(ctx context.Context) (*gogen.ConfigurationSchema, error)

FetchConfiguration extracts the TF provider's own configuration block (e.g. aws { region = ... }) and returns it as a generic schema for the renderer. A nil result means the provider declares no configuration attributes; the renderer then skips emitting a ProviderConfig struct and library Configuration entry.

func (*Adapter) FetchDataSources

func (a *Adapter) FetchDataSources(
    ctx context.Context,
    resources []string,
) ([]gogen.DataSourceSchema, error)

func (*Adapter) FetchResources

func (a *Adapter) FetchResources(
    ctx context.Context,
    resources []string,
) ([]gogen.ResourceSchema, error)

func (*Adapter) Name

func (a *Adapter) Name() string

type CLIFetcher

type CLIFetcher struct{}

CLIFetcher runs terraform in a temp directory.

func (CLIFetcher) FetchSchema

func (CLIFetcher) FetchSchema(
    ctx context.Context,
    source, localName, version string,
) ([]byte, error)

type Fetcher

type Fetcher interface {
    FetchSchema(ctx context.Context, source, localName, version string) ([]byte, error)
}

Fetcher abstracts terraform CLI calls for testability.