terragen

package
v0.0.0-...-14f1a73 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package terragen provides a simple way to generate Go code from a terraform provider.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPackageLocationNotEmpty = errors.New(
		"providers pkg location is not empty",
	)
	ErrProviderSchemaNotFound = errors.New("provider schema not found")
)

Functions

func GenerateGoCode

func GenerateGoCode(
	args GenerateGoArgs,
	providerSchema *tfjson.ProviderSchema,
) error

GenerateGoCode generates Go code for creating Terraform objects for the given providers and their schemas.

func GenerateProviderSchema

func GenerateProviderSchema(
	ctx context.Context,
	provider Provider,
) (*tfjson.ProviderSchema, error)

GenerateProviderSchema generates the schema for the given Terraform provider.

The provider schema is generated by calling Terraform as follows:

terraform providers schema --json

The JSON schema is then decoded and returned as a ProviderSchemas struct.

Types

type GenerateGoArgs

type GenerateGoArgs struct {
	ProviderName    string
	ProviderSource  string
	ProviderVersion string
	// OutDir is the filesystem location where the generated files will be
	// created.
	OutDir string
	// PkgPath is the Go pkg path to the generated files location, specified by
	// OutDir. E.g. if OutDir is in a module called "my-module" in a directory
	// called "gen",
	// then the PkgPath should be "my-module/gen".
	PkgPath string
	// Force enables overriding any existing generated files per-provider.
	Force bool
	// Clean enables cleaning the generated files location before generating the
	// new files.
	Clean bool
}

type Provider

type Provider struct {
	Name    string // Lack of cty tag means it is ignored
	Source  string `cty:"source"`
	Version string `cty:"version"`
}

Provider represents a single element of a map of required providers

func ParseProvider

func ParseProvider(s string) (Provider, error)

ParseProvider takes a provider as a string and returns a Provider object. An error is returned if the string could not be parsed. Example provider: aws=hashicorp/aws:4.60.0

type RequiredProviders

type RequiredProviders struct {
	Providers map[string]Provider `hcl:",remain"`
}

RequiredProviders represents the map of required providers for a Terraform stack

type TerraformBlock

type TerraformBlock struct {
	RequiredProviders RequiredProviders `hcl:"required_providers,block"`
}

TerraformBlock represents a terraform{} block in a Terraform stack

type TerraformVersions

type TerraformVersions struct {
	TerraformBlock TerraformBlock `hcl:"terraform,block"`
}

TerraformVersions ...

Jump to

Keyboard shortcuts

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