modulelist

package
v0.0.0-...-7b190fc Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: Apache-2.0 Imports: 9 Imported by: 3

README

Module List File Format

The Module List File Format is used to specify Terraform modules for the harvest CLI commands. This format allows for more efficient module management and initialization.

Overview

The client harvest commands can read Terraform files directly from a given directory path. The user is required to pre-initialize the working directory by running commands such as terraform init. This can lead to a version conflict if some of the loaded modules require incompatible provider versions.

To avoid this caveat the user may instead pass in a file containing a list of modules to be loaded. The harvest commands then process each module in a separate workspace hence avoiding any version conflicts between different modules.

In case of the module list file the CLI performs workspace initialization for each module on-the-fly. In order to improve performance it relies on the Terraform built-in plugin cache. The cache location can be controlled by terraform.plugin_cache_dir configuration variable pre-set to ~/.terraform.d/plugin-cache.

Module List File Structure

Each module entry in the list must include:

  • name: A unique identifier for the module (required).
  • source: The Terraform module source (required).
  • version: The Terraform module version (optional).
  • export: A boolean indicating if the module should be processed by the module harvest command (optional).
  • group: A string to group compatible modules for efficient initialization (optional).

Modules with the export attribute set to true are included in the user's module library. Those without it or set to false are used only for resource attribute discovery and mapping.

The group attribute allows users to specify a group name for compatible modules. Modules in the same group are initialized together, which can significantly speed up the terraform init process. This is particularly useful for large sets of modules with shared dependencies.

Example Module List File

farm:
  - name: vpc
    source: "terraform-aws-modules/vpc/aws"
    version: "4.0.2"
    export: true
    group: "group1" # Grouping modules for efficient initialization
  - name: voting-demo
    source: "github.com/cldcvr/codepipes-tutorials//voting/infra/aws/eks?ref=terrarium-sources"
    export: false
    group: "group1" # Same group as 'vpc' for shared initialization
  - name: rds
    source: "terraform-aws-modules/rds/aws"
    export: true
    group: "group2" # Different group for separate initialization

In this example, vpc and voting-demo are part of the group1 group and will be initialized together, while database is in a separate group2 group.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FarmModule

type FarmModule struct {
	Name    string `yaml:"name"`
	Source  string `yaml:"source"`
	Version string `yaml:"version,omitempty"`
}

type FarmModuleGroup

type FarmModuleGroup struct {
	Name    string
	Export  bool
	Modules []FarmModule
}

func (FarmModuleGroup) CreateTerraformFile

func (g FarmModuleGroup) CreateTerraformFile(rootDir string) (dirPath string, err error)

CreateTerraformFile writes a terraform module file. The file wil be stored in a sub-directory under a provided root directory. If the root path is empty the file will be stored in a temporary directory instead. When using a temporary directory each module-group will need to be freshly initialized by 'terraform init' every time.

func (FarmModuleGroup) PrepareDir

func (g FarmModuleGroup) PrepareDir(rootDir string) (dirPath string, err error)

func (FarmModuleGroup) ToTerraform

func (refArr FarmModuleGroup) ToTerraform() (string, error)

type FarmModuleGroupsMap

type FarmModuleGroupsMap map[string]FarmModuleGroup

func (FarmModuleGroupsMap) FilterExport

func (groups FarmModuleGroupsMap) FilterExport(wantExport bool) (filteredGroups FarmModuleGroupsMap)

FilterExport filters the FarmModuleGroupsMap based on the Export flag. It returns a new FarmModuleGroupsMap containing only the groups that match the given Export flag.

type FarmModuleList

type FarmModuleList struct {
	Farm []FarmModuleRef `yaml:"farm"`
}

func LoadFarmModules

func LoadFarmModules(listFilePath string) (FarmModuleList, error)

func (FarmModuleList) Groups

Groups organizes the FarmModuleRefs in the FarmModuleList into a FarmModuleGroupsMap. Each group in the map is identified by its name and contains an array of FarmModules. The Export flag for each group is also set based on the FarmModuleRef.

func (FarmModuleList) Validate

func (l FarmModuleList) Validate() error

Validate ensures that the FarmModuleList adheres to the following criteria: - Each module's name and source must be non-empty. - Each module's name must be unique. - Each combination of a module's source and version must be unique. - A group name must not conflict with a module name. - All modules within the same group must have the same 'export' flag value.

type FarmModuleRef

type FarmModuleRef struct {
	Name    string `yaml:"name"`
	Source  string `yaml:"source"`
	Version string `yaml:"version,omitempty"`
	Export  bool   `yaml:"export,omitempty"`
	Group   string `yaml:"group,omitempty"`
}

func (FarmModuleRef) GetGroupName

func (r FarmModuleRef) GetGroupName() string

GetGroupName returns the group name for a FarmModuleRef. If the Group field is not empty, it returns that. Otherwise, it returns the Name field.

Jump to

Keyboard shortcuts

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