mapstructure_to_hcl2

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MPL-2.0 Imports: 16 Imported by: 0

README

mapstructure-to-hcl

mapstructure-to-hcl Helps generate the code necessary for any plugin, including the core plugins to communicate the HCL2 layout of a plugin with Packer, for Example, with the following config.go file:

//go:generate packer-sdc mapstructure-to-hcl2 -type Config

// Config helps configure things
type Config struct {

Will generate a config.hcl2spec.go file containing a FlatConfig struct, which is a struct with all the mapstructure nested fields 'flattened' into the FlatConfig, so nothing is nested. The FlatConfig struct will get a HCL2Spec function that describes its HCL2 layout. This will be used to read and validate actual HCL2 files. The config.hcl2spec.go will also add a FlatMapstructure function to the Config struct. That function returns a FlatConfig. These functions together define an interface meant for a plugin component to 'speak' the HCL2 language with the Packer core.

Before HCL2, Packer JSON heavily relied on the mapstructure decoding library to load/parse user config files, making this part of the code very tested. To go to HCL2 this command was created.

Here are a few differences/gaps betweens HCL2 and mapstructure:

  • in HCL2 all basic struct fields (string/int/struct) that are not pointers are required ( must be set ). In mapstructure everything is optional.
  • mapstructure allows to 'squash' fields (ex: Field CommonStructType mapstructure:",squash") this allows to decorate structs and reuse configuration code. HCL2 parsing libs don't have anything similar.

Documentation

Overview

mapstructure-to-hcl2 fills the gaps between hcl2 and mapstructure for Packer

By generating a struct that the HCL2 ecosystem understands making use of mapstructure tags.

Packer heavily uses the mapstructure decoding library to load/parse user config files. Packer now needs to move to HCL2.

Here are a few differences/gaps betweens hcl2 and mapstructure:

  • in HCL2 all basic struct fields (string/int/struct) that are not pointers are required ( must be set ). In mapstructure everything is optional.

  • mapstructure allows to 'squash' fields (ex: Field CommonStructType `mapstructure:",squash"`) this allows to decorate structs and reuse configuration code. HCL2 parsing libs don't have anything similar.

mapstructure-to-hcl2 will parse Packer's config files and generate the HCL2 compliant code that will allow to not change any of the current builders in order to softly move to HCL2.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToSnakeCase

func ToSnakeCase(str string) string

Types

type Command

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

func (*Command) Flags

func (cmd *Command) Flags() *flag.FlagSet

func (*Command) Help

func (cmd *Command) Help() string

Usage is a replacement usage function for the flags package.

func (*Command) Run

func (cmd *Command) Run(args []string) int

func (*Command) Synopsis

func (cmd *Command) Synopsis() string

type NamePath

type NamePath struct {
	Name, Path string
}

type StructDef

type StructDef struct {
	OriginalStructName string
	FlatStructName     string
	Struct             *types.Struct
}

Jump to

Keyboard shortcuts

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