gen

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package gen is the core of terragen, where the template generation happens.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config added in v0.6.0

type Config struct {
	// Version of terragen used for generating scaffolds. Updates only when higher version of terragen used.
	Version string `json:"version" yaml:"version"`
	// RepoGroup to which the project is part of.
	RepoGroup string `json:"repo-group" yaml:"repo-group"`
	// ProjectModule represents the module of the project
	ProjectModule string `json:"project-module" yaml:"project-module"`
	// Provider name that was scaffolded.
	Provider string `json:"provider" yaml:"provider"`
	// ProviderPath where scaffolds were created.
	ProviderPath string `json:"provider-path" yaml:"provider-path"`
	// Resources that where scaffolded.
	Resources []string `json:"resources" yaml:"resources"`
	// DataSources that where scaffolded.
	DataSources []string `json:"data-sources" yaml:"data-sources"`
	// Importers that where scaffolded.
	Importers []string `json:"importers" yaml:"importers"`
}

Config would be generated and stored by the utility for further references.

type DataSource added in v0.6.0

type DataSource struct {
	Path               string
	DryRun             bool
	Force              bool
	SkipProviderUpdate bool
	AutoGenMessage     string
	Provider           string
	DataTemp           string
	Name               []string
	// contains filtered or unexported fields
}

func NewDataSource added in v0.6.0

func NewDataSource(i *Input) *DataSource

func (*DataSource) Create added in v0.6.0

func (d *DataSource) Create() error

func (*DataSource) Get added in v0.7.0

func (d *DataSource) Get(currentContent []byte) ([]byte, error)

func (*DataSource) GetUpdated added in v0.7.0

func (d *DataSource) GetUpdated() error

func (*DataSource) Scaffolded added in v0.6.0

func (d *DataSource) Scaffolded() bool

func (*DataSource) Update added in v0.7.0

func (d *DataSource) Update() error

type Git added in v0.6.0

type Git struct {
	DryRun    bool
	Provider  string
	Path      string
	GitIgnore string
	// contains filtered or unexported fields
}

func NewGit added in v0.6.0

func NewGit(i *Input) *Git

func (*Git) Create added in v0.6.0

func (g *Git) Create() error

Create scaffolds Git as per the requirements.

func (*Git) Get added in v0.7.0

func (g *Git) Get(currentContent []byte) ([]byte, error)

func (*Git) GetUpdated added in v0.7.0

func (g *Git) GetUpdated() error

func (*Git) Scaffolded added in v0.6.0

func (g *Git) Scaffolded() bool

func (*Git) Update added in v0.7.0

func (g *Git) Update() error

type Input

type Input struct {
	// DryRun simulates scaffold creation by not creating one
	DryRun bool
	// Force will forcefully scaffold the datasource/resource by not validating the terragen version.
	// Enabling this might tamper the scaffolds.
	Force bool
	// SkipValidation will skip validating all the prerequisites such as checking go,goimports etc.
	SkipValidation bool
	// TerraformPluginFramework would generate scaffolds
	// with terraform-plugin-framework(https://github.com/hashicorp/terraform-plugin-framework).
	TerraformPluginFramework bool
	// ResourceRequired determines if resource to be created while generating scaffolds.
	// Enabling this wth no resource name is not accepted.
	ResourceRequired bool
	// DatasourceRequired determines if data_source to be created while generating scaffolds.
	// Enabling this wth no data_source name is not accepted.
	DatasourceRequired bool
	// SkipProviderUpdate when set, would skip updating the provider after generating the `data-sources` or `resources`.
	// When it is enabled, updating the provider with newer `data-sources` or `resources` has to be done manually.
	SkipProviderUpdate bool
	// ImporterRequired determines if importer to be created while generating scaffolds.
	// Enabling this wth no importer name is not accepted.
	ImporterRequired bool
	// Provider name of which the scaffolds to be created, defaults to terraform-provider-demo
	Provider string
	// Path defines where the templates has to be generated.
	Path string
	// AutoGenMessage will be configured by terragen and cannot be overwritten.
	AutoGenMessage string
	// Description to be added to resource/datasource.
	Description string
	// RepoGroup is used while creating go mod. Defaults to 'github.com/test/'
	// For a given provider, repo group would be appended.
	// Ex: For provider 'demo' the go mod would look like 'github.com/test/demo'
	// Resource to be created while generating scaffolds,
	// by passing a resource name here, it auto enabled ResourceRequired.
	// Provider name would be appended while constructing final resource name.
	// EX: resource 'create_cluster' for provider demo would become 'demo_create_cluster'.
	Resource []string
	// DataSource to be created while generating scaffolds,
	// by passing a resource name here, it auto enabled DatasourceRequired.
	// Provider name would be appended while constructing final data_source name.
	// EX: resource 'load_image' for provider demo would become 'demo_load_image'.
	DataSource []string
	// List of all the dependent packages for terraform, if not passed it picks default.
	Dependents []string
	// TemplateRaw consists of go-templates which are the core for terragen.
	TemplateRaw TerraTemplate
	// RepoGroup to which the Terraform provider is to be part. This would be used as base name to set `go.mod`
	// ex: github.com/nikshilsbhat
	RepoGroup string
	// contains filtered or unexported fields
}

Input holds the required values to generate the templates.

func (*Input) CreateOrUpdateMetadata

func (i *Input) CreateOrUpdateMetadata() error

func (*Input) Generate added in v0.6.0

func (i *Input) Generate(providerName string) error

func (*Input) GenerateDataSource added in v0.6.0

func (i *Input) GenerateDataSource(dataSources []string) error

func (*Input) GenerateResource added in v0.6.0

func (i *Input) GenerateResource(resources []string) error

func (*Input) MetadataScaffolded added in v0.6.0

func (i *Input) MetadataScaffolded() bool

func (*Input) SetLogger added in v0.7.0

func (i *Input) SetLogger(logger *logrus.Logger)

type Main added in v0.6.0

type Main struct {
	DryRun         bool
	Path           string
	RootTemp       string
	Provider       string
	AutoGenMessage string
	Dependents     []string
	// contains filtered or unexported fields
}

func NewMain added in v0.6.0

func NewMain(i *Input) *Main

func (*Main) Create added in v0.6.0

func (m *Main) Create() error

func (*Main) Get added in v0.7.0

func (m *Main) Get(currentContent []byte) ([]byte, error)

func (*Main) GetUpdated added in v0.7.0

func (m *Main) GetUpdated() error

func (*Main) Scaffolded added in v0.6.0

func (m *Main) Scaffolded() bool

func (*Main) Update added in v0.7.0

func (m *Main) Update() error

type Make added in v0.6.0

type Make struct {
	DryRun   bool
	Path     string
	Provider string
	// contains filtered or unexported fields
}

func NewMake added in v0.6.0

func NewMake(i *Input) *Make

func (*Make) Create added in v0.6.0

func (m *Make) Create() error

func (*Make) Get added in v0.7.0

func (m *Make) Get(currentContent []byte) ([]byte, error)

func (*Make) GetUpdated added in v0.7.0

func (m *Make) GetUpdated() error

func (*Make) Scaffolded added in v0.7.0

func (m *Make) Scaffolded() bool

func (*Make) Update added in v0.7.0

func (m *Make) Update() error

type Metadata

type Metadata interface {
	Get(repoGroup, mod string) *Config
}

type Provider added in v0.6.0

type Provider struct {
	Provider       string
	DryRun         bool
	Path           string
	Mod            string
	ProviderTemp   string
	MetaDataPath   string
	AutoGenMessage string
	Resource       []string
	DataSource     []string
	Importer       []string
	// contains filtered or unexported fields
}

func NewProvider added in v0.6.0

func NewProvider(i *Input) *Provider

func (*Provider) Create added in v0.6.0

func (p *Provider) Create() error

func (*Provider) Get added in v0.6.0

func (p *Provider) Get(currentContent []byte) ([]byte, error)

func (*Provider) GetUpdated added in v0.6.0

func (p *Provider) GetUpdated() error

func (*Provider) Scaffolded added in v0.6.0

func (p *Provider) Scaffolded() bool

func (*Provider) Update added in v0.6.0

func (p *Provider) Update() error

type Resource added in v0.6.0

type Resource struct {
	Path               string
	DryRun             bool
	Force              bool
	SkipProviderUpdate bool
	Importer           bool
	AutoGenMessage     string
	Provider           string
	ResourceTemp       string
	Name               []string
	// contains filtered or unexported fields
}

func NewResource added in v0.6.0

func NewResource(i *Input) *Resource

func (*Resource) Create added in v0.6.0

func (r *Resource) Create() error

func (*Resource) Get added in v0.7.0

func (r *Resource) Get(currentContent []byte) ([]byte, error)

func (*Resource) GetUpdated added in v0.7.0

func (r *Resource) GetUpdated() error

func (*Resource) Scaffolded added in v0.6.0

func (r *Resource) Scaffolded() bool

func (*Resource) Update added in v0.7.0

func (r *Resource) Update() error

type Scaffold added in v0.6.0

type Scaffold interface {
	Generate(providerName string) error
}

Scaffold implement method that generates the scaffolds for the Terraform provider.

type SupportingComponents added in v0.7.0

type SupportingComponents struct {
	DryRun           bool
	Provider         string
	Path             string
	GolangCILint     string
	GoReleaser       string
	RegistryManifest string
	// contains filtered or unexported fields
}

func NewReleaseNLinter added in v0.7.0

func NewReleaseNLinter(i *Input) *SupportingComponents

func (*SupportingComponents) Create added in v0.7.0

func (r *SupportingComponents) Create() error

func (*SupportingComponents) Get added in v0.7.0

func (r *SupportingComponents) Get(currentContent []byte) ([]byte, error)

func (*SupportingComponents) GetUpdated added in v0.7.0

func (r *SupportingComponents) GetUpdated() error

func (*SupportingComponents) Scaffolded added in v0.7.0

func (r *SupportingComponents) Scaffolded() bool

func (*SupportingComponents) Update added in v0.7.0

func (r *SupportingComponents) Update() error

type TerraTemplate

type TerraTemplate struct {
	// ProviderTemp holds the template for provider
	ProviderTemp string `json:"provider-template,omitempty" yaml:"provider-template,omitempty"`
	// RootTemp holds the template for root file
	RootTemp string `json:"root-template,omitempty" yaml:"provider-template,omitempty"`
	// DataTemp holds the template for data
	DataTemp string `json:"data-template,omitempty" yaml:"data-template,omitempty"`
	// ResourceTemp holds the template for resource
	ResourceTemp string `json:"resource-template,omitempty" yaml:"resource-template,omitempty"`
	// GitIgnore that where scaffolded.
	GitIgnore string `json:"gitignore,omitempty" yaml:"gitignore,omitempty"`
	// GolangCILint that where scaffolded.
	GolangCILint string `json:"golang-ci-lint,omitempty" yaml:"golang-ci-lint,omitempty"`
	// GoReleaser that where scaffolded.
	GoReleaser string `json:"go-releaser,omitempty" yaml:"go-releaser,omitempty"`
	// RegistryManifest is a terraform registry manifest that is to be scaffolded.
	RegistryManifest string `json:"registry-manifest,omitempty" yaml:"registry-manifest,omitempty"`
}

TerraTemplate are the collections of go-templates which are used to generate terraform provider's base template.

type Terragen added in v0.6.0

type Terragen interface {
	Create() error
	Scaffolded() bool
	Update() error
	Get(currentContent []byte) ([]byte, error)
	GetUpdated() error
}

Terragen implements methods to GET/CREATE/UPDATE the scaffolds for the Terraform provider.

Jump to

Keyboard shortcuts

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