packer-cn/packer
Adrien Delorme 0785c2f6fc
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 11:25:56 +01:00
..
plugin build using HCL2 (#8423) 2019-12-17 11:25:56 +01:00
rpc build using HCL2 (#8423) 2019-12-17 11:25:56 +01:00
test-fixtures fixing interpolation 2019-06-10 11:30:52 -07:00
tmp clarify comments 2019-01-09 16:30:43 +01:00
artifact.go Expand Artifact API to expose build state 2014-09-22 11:15:47 +01:00
artifact_mock.go Add to vagrant post-processor support for Azure 2018-08-08 10:04:28 -05:00
artifact_test.go Expand Artifact API to expose build state 2014-09-22 11:15:47 +01:00
build.go build using HCL2 (#8423) 2019-12-17 11:25:56 +01:00
build_test.go build using HCL2 (#8423) 2019-12-17 11:25:56 +01:00
builder.go build using HCL2 (#8423) 2019-12-17 11:25:56 +01:00
builder_mock.go build using HCL2 (#8423) 2019-12-17 11:25:56 +01:00
builder_mock.hcl2spec.go build using HCL2 (#8423) 2019-12-17 11:25:56 +01:00
builder_test.go packer: builder prepare can return warnings 2013-11-02 22:31:12 -05:00
cache.go I use Dir instead of Base for mkdirall call 2019-03-28 13:17:15 -07:00
cache_test.go Use the hashicorp/go-getter to download files 2019-03-13 12:11:58 +01:00
communicator.go build using HCL2 (#8423) 2019-12-17 11:25:56 +01:00
communicator_mock.go Add unit test to find issue #7655 2019-05-17 22:27:19 +00:00
communicator_mock_test.go packer: Add UploadDir to the Communicator interface 2013-08-25 20:30:56 -07:00
communicator_test.go use our own copy of iochan.LineReader 2019-04-11 14:25:24 +02:00
config_file.go build using HCL2 (#8423) 2019-12-17 11:25:56 +01:00
config_file_test.go packer: remove unused test variable 2019-11-04 12:53:16 -08:00
config_file_unix.go make code of homeDir, configFile & configDir not os specific anymore 2018-11-30 15:47:43 +01:00
config_file_windows.go make code of homeDir, configFile & configDir not os specific anymore 2018-11-30 15:47:43 +01:00
core.go build using HCL2 (#8423) 2019-12-17 11:25:56 +01:00
core_test.go packer: remove unused testComponentFinder() 2019-11-04 12:50:58 -08:00
hcl2spec.go build using HCL2 (#8423) 2019-12-17 11:25:56 +01:00
hook.go add test for error-cleanup provisioner, and fix tests by fixing null builder to use an actual none communicator instead of skipping communicator generation altogether 2019-09-25 13:39:09 -07:00
hook_mock.go [Builder|Build|PostProcessor|Provisioner|Hook]Server: context cancel using a RPC cancel method 2019-04-03 15:55:55 +02:00
hook_test.go [Builder|Build|PostProcessor|Provisioner|Hook]Server: context cancel using a RPC cancel method 2019-04-03 15:55:55 +02:00
logs.go replace scrubconfig with packer.LogSecretFilter.Set 2018-08-20 15:35:55 -07:00
maps.go build using HCL2 (#8423) 2019-12-17 11:25:56 +01:00
multi_error.go WIP 2018-10-26 16:59:20 -07:00
multi_error_test.go packer: no more asserts lib 2013-10-16 21:09:27 -10:00
packer_test.go packer: Core, and template validate 2015-05-23 14:48:07 -07:00
post_processor.go build using HCL2 (#8423) 2019-12-17 11:25:56 +01:00
post_processor_mock.go build using HCL2 (#8423) 2019-12-17 11:25:56 +01:00
progressbar.go allow building packer on solaris by removing progress bar and tty imports 2019-05-07 15:58:49 +02:00
progressbar_noop.go allow building packer on solaris by removing progress bar and tty imports 2019-05-07 15:58:49 +02:00
progressbar_solaris.go allow building packer on solaris by removing progress bar and tty imports 2019-05-07 15:58:49 +02:00
progressbar_test.go Use the hashicorp/go-getter to download files 2019-03-13 12:11:58 +01:00
provisioner.go build using HCL2 (#8423) 2019-12-17 11:25:56 +01:00
provisioner_mock.go build using HCL2 (#8423) 2019-12-17 11:25:56 +01:00
provisioner_test.go TestPausedProvisionerProvision_waits: don't fail when we spend too much time. 2019-05-24 18:21:53 +02:00
provisioner_timeout.go TimeoutProvisioner: also display an error log when the context times out 2019-04-09 17:46:38 +02:00
telemetry.go Remove telemetry error reporting message. 2018-02-20 10:54:20 -08:00
telemetry_test.go add config key reporting 2017-11-14 16:30:44 -08:00
testing.go build using HCL2 (#8423) 2019-12-17 11:25:56 +01:00
tty.go Close tty on exit (#7411) 2019-03-15 11:10:30 +01:00
ui.go need to scrub sensitive variables first, to make sure we don't fail for comma-containing sensitive info 2019-08-15 16:16:11 -07:00
ui_test.go Close tty on exit (#7411) 2019-03-15 11:10:30 +01:00