generate

package
v0.0.0-...-02a33f3 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanBeforeCopy

func CleanBeforeCopy(relPath string) string

func ConvertNameToCanonical

func ConvertNameToCanonical(name string) string

ConvertNameToCanonical converts a name to canonical format. It replaces all '-' with '_'.

func IsValidDir

func IsValidDir(path string) error

IsValidDir checks if the given path is a valid directory. It returns an error if the path is not a valid directory. Or if the directory isn't a directory.

Types

type Client

type Client struct {
	Config Config
	Log    logger.Log
}

func NewGeneratorDefault

func NewGeneratorDefault() *Client

func (*Client) CreateBaseDirsIfNotExist

func (c *Client) CreateBaseDirsIfNotExist(repoRoot string) error

func (*Client) CreateTargetPath

func (c *Client) CreateTargetPath(targetPath string) error

func (*Client) GenerateFile

func (c *Client) GenerateFile(sourcePath, destPath string, funcMap template.FuncMap, data interface{}) error

GenerateFile generates a file from a template. It's a wrapper around the ProcessTemplFile function that's used from the TFTest library.

func (*Client) GenerateModule

func (c *Client) GenerateModule(templateVersion string, paths *TargetPaths) error

GenerateModule generates a canonical module from the template directory.

func (*Client) GenerateModuleExample

func (c *Client) GenerateModuleExample(templateVersion string, paths *TargetPaths) error

GenerateModuleExample generates an example module from the template directory.

func (*Client) GenerateTerraformFiles

func (c *Client) GenerateTerraformFiles(sourcePath, targetPath string) error

GenerateTerraformFiles generates files from templates, allowing individual file treatment.

func (*Client) ResolvePaths

func (c *Client) ResolvePaths(module, group string) (*TargetPaths, error)

func (*Client) Validate

func (c *Client) Validate(module, group string, options *GenOptions) error

type Config

type Config interface {
	GetDestDir() (string, error)
	GetTFTemplateDirV1() (string, error)
	GetModulesDir() string
	GetHomeDir() string
	GetCurrentDir() string
	IsGitRepo() (string, bool)
	GetRepoRoot() (string, error)
}

type DocsGenerator

type DocsGenerator interface {
	GenerateModuleReadme(targetPath string) error
	GenerateTestReadme(targetPath string) error
	GenerateExampleReadme(targetPath string) error
}

type GenOptions

type GenOptions struct {
	FailIfNotGitRepo bool
}

type Generator

type Generator struct{}

type ModuleGenerator

type ModuleGenerator interface {
	// GenerateModule GenerateCanonical generates a canonical module from the template directory.
	// 'templatedir' is the targetModulePath to the template directory.
	// 'destpath' is the targetModulePath to the destination directory.
	GenerateModule(templatedir string, paths *TargetPaths) error
	GenerateModuleExample(templatedir string, paths *TargetPaths) error
	// Validate validates the module generation.
	// 'module' is the name of the module.
	// 'group' is the group name of the module. If the group is passed, normally it refers
	// to the 'service' (cloud provider) the module is for. E.g.: /modules/s3/s3_bucket
	Validate(module, group string, options *GenOptions) error
	// ResolvePaths ResolveModuleDestPath resolves the destination targetModulePath for the module.
	// 'module' is the name of the module.
	// 'group' is the group name of the module. If the group is passed, normally it refers
	// to the 'service' (cloud provider) the module is for. E.g.: /modules/s3/s3_bucket
	ResolvePaths(module, group string) (*TargetPaths, error)
	// CreateBaseDirsIfNotExist CreateModulesDirectoryIfNotExists creates the modules directory if it does not exist.
	// 'repoRoot' is the root directory of the repository.
	CreateBaseDirsIfNotExist(repoRoot string) error
	CreateTargetPath(targetPath string) error
	GenerateTerraformFiles(sourcePath string, destPath string) error
	GenerateFile(sourcePath string, destPath string, funcMap template.FuncMap, data interface{}) error
}

type Options

type Options struct {
	// contains filtered or unexported fields
}

func (*Options) GetCurrentDir

func (o *Options) GetCurrentDir() string

func (*Options) GetDestDir

func (o *Options) GetDestDir() (string, error)

func (*Options) GetHomeDir

func (o *Options) GetHomeDir() string

func (*Options) GetModulesDir

func (o *Options) GetModulesDir() string

func (*Options) GetRepoRoot

func (o *Options) GetRepoRoot() (string, error)

func (*Options) GetTFTemplateDirV1

func (o *Options) GetTFTemplateDirV1() (string, error)

func (*Options) IsGitRepo

func (o *Options) IsGitRepo() (string, bool)

type TargetPaths

type TargetPaths struct {
	ModulePath  string
	ExamplePath string
	TestPath    string
}

type TerraformGenerator

type TerraformGenerator interface {
	GenerateProvidersFile(targetPath string) error
	GenerateMainFile(targetPath string) error
	GenerateVariablesFile(targetPath string) error
	GenerateOutputsFile(targetPath string) error
	GenerateVersionsFile(targetPath string) error
	GenerateTerraformDocsFile(targetPath string) error
}

type TerraformGeneratorImpl

type TerraformGeneratorImpl struct {
	Generator ModuleGenerator
}

Jump to

Keyboard shortcuts

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