packer-cn/packer/builder_mock.hcl2spec.go

210 lines
12 KiB
Go
Raw Normal View History

build using HCL2 (#8423) This follows #8232 which added the code to generate the code required to parse HCL files for each packer component. All old config files of packer will keep on working the same. Packer takes one argument. When a directory is passed, all files in the folder with a name ending with “.pkr.hcl” or “.pkr.json” will be parsed using the HCL2 format. When a file ending with “.pkr.hcl” or “.pkr.json” is passed it will be parsed using the HCL2 format. For every other case; the old packer style will be used. ## 1. the hcl2template pkg can create a packer.Build from a set of HCL (v2) files I had to make the packer.coreBuild (which is our one and only packer.Build ) a public struct with public fields ## 2. Components interfaces get a new ConfigSpec Method to read a file from an HCL file. This is a breaking change for packer plugins. a packer component can be a: builder/provisioner/post-processor each component interface now gets a `ConfigSpec() hcldec.ObjectSpec` which allows packer to tell what is the layout of the hcl2 config meant to configure that specific component. This ObjectSpec is sent through the wire (RPC) and a cty.Value is now sent through the already existing configuration entrypoints: Provisioner.Prepare(raws ...interface{}) error Builder.Prepare(raws ...interface{}) ([]string, error) PostProcessor.Configure(raws ...interface{}) error close #1768 Example hcl files: ```hcl // file amazon-ebs-kms-key/run.pkr.hcl build { sources = [ "source.amazon-ebs.first", ] provisioner "shell" { inline = [ "sleep 5" ] } post-processor "shell-local" { inline = [ "sleep 5" ] } } // amazon-ebs-kms-key/source.pkr.hcl source "amazon-ebs" "first" { ami_name = "hcl2-test" region = "us-east-1" instance_type = "t2.micro" kms_key_id = "c729958f-c6ba-44cd-ab39-35ab68ce0a6c" encrypt_boot = true source_ami_filter { filters { virtualization-type = "hvm" name = "amzn-ami-hvm-????.??.?.????????-x86_64-gp2" root-device-type = "ebs" } most_recent = true owners = ["amazon"] } launch_block_device_mappings { device_name = "/dev/xvda" volume_size = 20 volume_type = "gp2" delete_on_termination = "true" } launch_block_device_mappings { device_name = "/dev/xvdf" volume_size = 500 volume_type = "gp2" delete_on_termination = true encrypted = true } ami_regions = ["eu-central-1"] run_tags { Name = "packer-solr-something" stack-name = "DevOps Tools" } communicator = "ssh" ssh_pty = true ssh_username = "ec2-user" associate_public_ip_address = true } ```
2019-12-17 05:25:56 -05:00
// Code generated by "mapstructure-to-hcl2 -type MockBuilder,MockCommunicator,RemoteCmd,MockProvisioner,MockPostProcessor"; DO NOT EDIT.
package packer
import (
"github.com/hashicorp/hcl/v2/hcldec"
"github.com/zclconf/go-cty/cty"
"io"
)
// FlatMockBuilder is an auto-generated flat version of MockBuilder.
// Where the contents of a field with a `mapstructure:,squash` tag are bubbled up.
type FlatMockBuilder struct {
ArtifactId *string `cty:"artifact_id"`
PrepareWarnings []string `cty:"prepare_warnings"`
RunErrResult *bool `cty:"run_err_result"`
RunNilResult *bool `cty:"run_nil_result"`
PrepareCalled *bool `cty:"prepare_called"`
PrepareConfig []interface{} `cty:"prepare_config"`
RunCalled *bool `cty:"run_called"`
RunHook Hook `cty:"run_hook"`
RunUi Ui `cty:"run_ui"`
CancelCalled *bool `cty:"cancel_called"`
2019-12-17 16:49:16 -05:00
GeneratedVars []string `cty:"generated_vars"`
build using HCL2 (#8423) This follows #8232 which added the code to generate the code required to parse HCL files for each packer component. All old config files of packer will keep on working the same. Packer takes one argument. When a directory is passed, all files in the folder with a name ending with “.pkr.hcl” or “.pkr.json” will be parsed using the HCL2 format. When a file ending with “.pkr.hcl” or “.pkr.json” is passed it will be parsed using the HCL2 format. For every other case; the old packer style will be used. ## 1. the hcl2template pkg can create a packer.Build from a set of HCL (v2) files I had to make the packer.coreBuild (which is our one and only packer.Build ) a public struct with public fields ## 2. Components interfaces get a new ConfigSpec Method to read a file from an HCL file. This is a breaking change for packer plugins. a packer component can be a: builder/provisioner/post-processor each component interface now gets a `ConfigSpec() hcldec.ObjectSpec` which allows packer to tell what is the layout of the hcl2 config meant to configure that specific component. This ObjectSpec is sent through the wire (RPC) and a cty.Value is now sent through the already existing configuration entrypoints: Provisioner.Prepare(raws ...interface{}) error Builder.Prepare(raws ...interface{}) ([]string, error) PostProcessor.Configure(raws ...interface{}) error close #1768 Example hcl files: ```hcl // file amazon-ebs-kms-key/run.pkr.hcl build { sources = [ "source.amazon-ebs.first", ] provisioner "shell" { inline = [ "sleep 5" ] } post-processor "shell-local" { inline = [ "sleep 5" ] } } // amazon-ebs-kms-key/source.pkr.hcl source "amazon-ebs" "first" { ami_name = "hcl2-test" region = "us-east-1" instance_type = "t2.micro" kms_key_id = "c729958f-c6ba-44cd-ab39-35ab68ce0a6c" encrypt_boot = true source_ami_filter { filters { virtualization-type = "hvm" name = "amzn-ami-hvm-????.??.?.????????-x86_64-gp2" root-device-type = "ebs" } most_recent = true owners = ["amazon"] } launch_block_device_mappings { device_name = "/dev/xvda" volume_size = 20 volume_type = "gp2" delete_on_termination = "true" } launch_block_device_mappings { device_name = "/dev/xvdf" volume_size = 500 volume_type = "gp2" delete_on_termination = true encrypted = true } ami_regions = ["eu-central-1"] run_tags { Name = "packer-solr-something" stack-name = "DevOps Tools" } communicator = "ssh" ssh_pty = true ssh_username = "ec2-user" associate_public_ip_address = true } ```
2019-12-17 05:25:56 -05:00
}
// FlatMapstructure returns a new FlatMockBuilder.
// FlatMockBuilder is an auto-generated flat version of MockBuilder.
// Where the contents a fields with a `mapstructure:,squash` tag are bubbled up.
func (*MockBuilder) FlatMapstructure() interface{ HCL2Spec() map[string]hcldec.Spec } {
return new(FlatMockBuilder)
}
// HCL2Spec returns the hcl spec of a MockBuilder.
// This spec is used by HCL to read the fields of MockBuilder.
// The decoded values from this spec will then be applied to a FlatMockBuilder.
func (*FlatMockBuilder) HCL2Spec() map[string]hcldec.Spec {
s := map[string]hcldec.Spec{
"artifact_id": &hcldec.AttrSpec{Name: "artifact_id", Type: cty.String, Required: false},
"prepare_warnings": &hcldec.AttrSpec{Name: "prepare_warnings", Type: cty.List(cty.String), Required: false},
"run_err_result": &hcldec.AttrSpec{Name: "run_err_result", Type: cty.Bool, Required: false},
"run_nil_result": &hcldec.AttrSpec{Name: "run_nil_result", Type: cty.Bool, Required: false},
"prepare_called": &hcldec.AttrSpec{Name: "prepare_called", Type: cty.Bool, Required: false},
"prepare_config": &hcldec.AttrSpec{Name: "prepare_config", Type: cty.Bool, Required: false}, /* TODO(azr): could not find type */
"run_called": &hcldec.AttrSpec{Name: "run_called", Type: cty.Bool, Required: false},
"run_hook": &hcldec.AttrSpec{Name: "Hook", Type: cty.Bool, Required: false}, /* TODO(azr): could not find type */
"run_ui": &hcldec.AttrSpec{Name: "Ui", Type: cty.Bool, Required: false}, /* TODO(azr): could not find type */
"cancel_called": &hcldec.AttrSpec{Name: "cancel_called", Type: cty.Bool, Required: false},
2019-12-17 16:49:16 -05:00
"generated_vars": &hcldec.AttrSpec{Name: "generated_vars", Type: cty.List(cty.String), Required: false},
build using HCL2 (#8423) This follows #8232 which added the code to generate the code required to parse HCL files for each packer component. All old config files of packer will keep on working the same. Packer takes one argument. When a directory is passed, all files in the folder with a name ending with “.pkr.hcl” or “.pkr.json” will be parsed using the HCL2 format. When a file ending with “.pkr.hcl” or “.pkr.json” is passed it will be parsed using the HCL2 format. For every other case; the old packer style will be used. ## 1. the hcl2template pkg can create a packer.Build from a set of HCL (v2) files I had to make the packer.coreBuild (which is our one and only packer.Build ) a public struct with public fields ## 2. Components interfaces get a new ConfigSpec Method to read a file from an HCL file. This is a breaking change for packer plugins. a packer component can be a: builder/provisioner/post-processor each component interface now gets a `ConfigSpec() hcldec.ObjectSpec` which allows packer to tell what is the layout of the hcl2 config meant to configure that specific component. This ObjectSpec is sent through the wire (RPC) and a cty.Value is now sent through the already existing configuration entrypoints: Provisioner.Prepare(raws ...interface{}) error Builder.Prepare(raws ...interface{}) ([]string, error) PostProcessor.Configure(raws ...interface{}) error close #1768 Example hcl files: ```hcl // file amazon-ebs-kms-key/run.pkr.hcl build { sources = [ "source.amazon-ebs.first", ] provisioner "shell" { inline = [ "sleep 5" ] } post-processor "shell-local" { inline = [ "sleep 5" ] } } // amazon-ebs-kms-key/source.pkr.hcl source "amazon-ebs" "first" { ami_name = "hcl2-test" region = "us-east-1" instance_type = "t2.micro" kms_key_id = "c729958f-c6ba-44cd-ab39-35ab68ce0a6c" encrypt_boot = true source_ami_filter { filters { virtualization-type = "hvm" name = "amzn-ami-hvm-????.??.?.????????-x86_64-gp2" root-device-type = "ebs" } most_recent = true owners = ["amazon"] } launch_block_device_mappings { device_name = "/dev/xvda" volume_size = 20 volume_type = "gp2" delete_on_termination = "true" } launch_block_device_mappings { device_name = "/dev/xvdf" volume_size = 500 volume_type = "gp2" delete_on_termination = true encrypted = true } ami_regions = ["eu-central-1"] run_tags { Name = "packer-solr-something" stack-name = "DevOps Tools" } communicator = "ssh" ssh_pty = true ssh_username = "ec2-user" associate_public_ip_address = true } ```
2019-12-17 05:25:56 -05:00
}
return s
}
// FlatMockCommunicator is an auto-generated flat version of MockCommunicator.
// Where the contents of a field with a `mapstructure:,squash` tag are bubbled up.
type FlatMockCommunicator struct {
StartCalled *bool `cty:"start_called"`
StartCmd *FlatRemoteCmd `cty:"start_cmd"`
StartStderr *string `cty:"start_stderr"`
StartStdout *string `cty:"start_stdout"`
StartStdin *string `cty:"start_stdin"`
StartExitStatus *int `cty:"start_exit_status"`
UploadCalled *bool `cty:"upload_called"`
UploadPath *string `cty:"upload_path"`
UploadData *string `cty:"upload_data"`
UploadDirDst *string `cty:"upload_dir_dst"`
UploadDirSrc *string `cty:"upload_dir_src"`
UploadDirExclude []string `cty:"upload_dir_exclude"`
DownloadDirDst *string `cty:"download_dir_dst"`
DownloadDirSrc *string `cty:"download_dir_src"`
DownloadDirExclude []string `cty:"download_dir_exclude"`
DownloadCalled *bool `cty:"download_called"`
DownloadPath *string `cty:"download_path"`
DownloadData *string `cty:"download_data"`
}
// FlatMapstructure returns a new FlatMockCommunicator.
// FlatMockCommunicator is an auto-generated flat version of MockCommunicator.
// Where the contents a fields with a `mapstructure:,squash` tag are bubbled up.
func (*MockCommunicator) FlatMapstructure() interface{ HCL2Spec() map[string]hcldec.Spec } {
return new(FlatMockCommunicator)
}
// HCL2Spec returns the hcl spec of a MockCommunicator.
// This spec is used by HCL to read the fields of MockCommunicator.
// The decoded values from this spec will then be applied to a FlatMockCommunicator.
func (*FlatMockCommunicator) HCL2Spec() map[string]hcldec.Spec {
s := map[string]hcldec.Spec{
"start_called": &hcldec.AttrSpec{Name: "start_called", Type: cty.Bool, Required: false},
"start_cmd": &hcldec.BlockSpec{TypeName: "start_cmd", Nested: hcldec.ObjectSpec((*FlatRemoteCmd)(nil).HCL2Spec())},
"start_stderr": &hcldec.AttrSpec{Name: "start_stderr", Type: cty.String, Required: false},
"start_stdout": &hcldec.AttrSpec{Name: "start_stdout", Type: cty.String, Required: false},
"start_stdin": &hcldec.AttrSpec{Name: "start_stdin", Type: cty.String, Required: false},
"start_exit_status": &hcldec.AttrSpec{Name: "start_exit_status", Type: cty.Number, Required: false},
"upload_called": &hcldec.AttrSpec{Name: "upload_called", Type: cty.Bool, Required: false},
"upload_path": &hcldec.AttrSpec{Name: "upload_path", Type: cty.String, Required: false},
"upload_data": &hcldec.AttrSpec{Name: "upload_data", Type: cty.String, Required: false},
"upload_dir_dst": &hcldec.AttrSpec{Name: "upload_dir_dst", Type: cty.String, Required: false},
"upload_dir_src": &hcldec.AttrSpec{Name: "upload_dir_src", Type: cty.String, Required: false},
"upload_dir_exclude": &hcldec.AttrSpec{Name: "upload_dir_exclude", Type: cty.List(cty.String), Required: false},
"download_dir_dst": &hcldec.AttrSpec{Name: "download_dir_dst", Type: cty.String, Required: false},
"download_dir_src": &hcldec.AttrSpec{Name: "download_dir_src", Type: cty.String, Required: false},
"download_dir_exclude": &hcldec.AttrSpec{Name: "download_dir_exclude", Type: cty.List(cty.String), Required: false},
"download_called": &hcldec.AttrSpec{Name: "download_called", Type: cty.Bool, Required: false},
"download_path": &hcldec.AttrSpec{Name: "download_path", Type: cty.String, Required: false},
"download_data": &hcldec.AttrSpec{Name: "download_data", Type: cty.String, Required: false},
}
return s
}
// FlatMockPostProcessor is an auto-generated flat version of MockPostProcessor.
// Where the contents of a field with a `mapstructure:,squash` tag are bubbled up.
type FlatMockPostProcessor struct {
ArtifactId *string `cty:"artifact_id"`
Keep *bool `cty:"keep"`
ForceOverride *bool `cty:"force_override"`
Error error `cty:"error"`
ConfigureCalled *bool `cty:"configure_called"`
ConfigureConfigs []interface{} `cty:"configure_configs"`
ConfigureError error `cty:"configure_error"`
PostProcessCalled *bool `cty:"post_process_called"`
PostProcessArtifact Artifact `cty:"post_process_artifact"`
PostProcessUi Ui `cty:"post_process_ui"`
}
// FlatMapstructure returns a new FlatMockPostProcessor.
// FlatMockPostProcessor is an auto-generated flat version of MockPostProcessor.
// Where the contents a fields with a `mapstructure:,squash` tag are bubbled up.
func (*MockPostProcessor) FlatMapstructure() interface{ HCL2Spec() map[string]hcldec.Spec } {
return new(FlatMockPostProcessor)
}
// HCL2Spec returns the hcl spec of a MockPostProcessor.
// This spec is used by HCL to read the fields of MockPostProcessor.
// The decoded values from this spec will then be applied to a FlatMockPostProcessor.
func (*FlatMockPostProcessor) HCL2Spec() map[string]hcldec.Spec {
s := map[string]hcldec.Spec{
"artifact_id": &hcldec.AttrSpec{Name: "artifact_id", Type: cty.String, Required: false},
"keep": &hcldec.AttrSpec{Name: "keep", Type: cty.Bool, Required: false},
"force_override": &hcldec.AttrSpec{Name: "force_override", Type: cty.Bool, Required: false},
"error": &hcldec.AttrSpec{Name: "error", Type: cty.Bool, Required: false}, /* TODO(azr): could not find type */
"configure_called": &hcldec.AttrSpec{Name: "configure_called", Type: cty.Bool, Required: false},
"configure_configs": &hcldec.AttrSpec{Name: "configure_configs", Type: cty.Bool, Required: false}, /* TODO(azr): could not find type */
"configure_error": &hcldec.AttrSpec{Name: "error", Type: cty.Bool, Required: false}, /* TODO(azr): could not find type */
"post_process_called": &hcldec.AttrSpec{Name: "post_process_called", Type: cty.Bool, Required: false},
"post_process_artifact": &hcldec.AttrSpec{Name: "Artifact", Type: cty.Bool, Required: false}, /* TODO(azr): could not find type */
"post_process_ui": &hcldec.AttrSpec{Name: "Ui", Type: cty.Bool, Required: false}, /* TODO(azr): could not find type */
}
return s
}
// FlatMockProvisioner is an auto-generated flat version of MockProvisioner.
// Where the contents of a field with a `mapstructure:,squash` tag are bubbled up.
type FlatMockProvisioner struct {
PrepCalled *bool `cty:"prep_called"`
PrepConfigs []interface{} `cty:"prep_configs"`
ProvCalled *bool `cty:"prov_called"`
ProvCommunicator Communicator `cty:"prov_communicator"`
ProvUi Ui `cty:"prov_ui"`
}
// FlatMapstructure returns a new FlatMockProvisioner.
// FlatMockProvisioner is an auto-generated flat version of MockProvisioner.
// Where the contents a fields with a `mapstructure:,squash` tag are bubbled up.
func (*MockProvisioner) FlatMapstructure() interface{ HCL2Spec() map[string]hcldec.Spec } {
return new(FlatMockProvisioner)
}
// HCL2Spec returns the hcl spec of a MockProvisioner.
// This spec is used by HCL to read the fields of MockProvisioner.
// The decoded values from this spec will then be applied to a FlatMockProvisioner.
func (*FlatMockProvisioner) HCL2Spec() map[string]hcldec.Spec {
s := map[string]hcldec.Spec{
"prep_called": &hcldec.AttrSpec{Name: "prep_called", Type: cty.Bool, Required: false},
"prep_configs": &hcldec.AttrSpec{Name: "prep_configs", Type: cty.Bool, Required: false}, /* TODO(azr): could not find type */
"prov_called": &hcldec.AttrSpec{Name: "prov_called", Type: cty.Bool, Required: false},
"prov_communicator": &hcldec.AttrSpec{Name: "Communicator", Type: cty.Bool, Required: false}, /* TODO(azr): could not find type */
"prov_ui": &hcldec.AttrSpec{Name: "Ui", Type: cty.Bool, Required: false}, /* TODO(azr): could not find type */
}
return s
}
// FlatRemoteCmd is an auto-generated flat version of RemoteCmd.
// Where the contents of a field with a `mapstructure:,squash` tag are bubbled up.
type FlatRemoteCmd struct {
Command *string `cty:"command"`
Stdin io.Reader `cty:"stdin"`
Stdout io.Writer `cty:"stdout"`
Stderr io.Writer `cty:"stderr"`
}
// FlatMapstructure returns a new FlatRemoteCmd.
// FlatRemoteCmd is an auto-generated flat version of RemoteCmd.
// Where the contents a fields with a `mapstructure:,squash` tag are bubbled up.
func (*RemoteCmd) FlatMapstructure() interface{ HCL2Spec() map[string]hcldec.Spec } {
return new(FlatRemoteCmd)
}
// HCL2Spec returns the hcl spec of a RemoteCmd.
// This spec is used by HCL to read the fields of RemoteCmd.
// The decoded values from this spec will then be applied to a FlatRemoteCmd.
func (*FlatRemoteCmd) HCL2Spec() map[string]hcldec.Spec {
s := map[string]hcldec.Spec{
"command": &hcldec.AttrSpec{Name: "command", Type: cty.String, Required: false},
"stdin": &hcldec.AttrSpec{Name: "io.Reader", Type: cty.Bool, Required: false}, /* TODO(azr): could not find type */
"stdout": &hcldec.AttrSpec{Name: "io.Writer", Type: cty.Bool, Required: false}, /* TODO(azr): could not find type */
"stderr": &hcldec.AttrSpec{Name: "io.Writer", Type: cty.Bool, Required: false}, /* TODO(azr): could not find type */
}
return s
}