37 Commits

Author SHA1 Message Date
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
Megan Marsh
b84b665ba3 fix race 2019-04-26 16:05:14 -07:00
Adrien Delorme
63f5bbbc73 use our own copy of iochan.LineReader 2019-04-11 14:25:24 +02:00
Adrien Delorme
2a90ce6178 packer communicator: use iochan.LineReader instead of iochan.LineReader(in)
* as it's the recommended way
2019-04-08 20:09:21 +02:00
Adrien Delorme
f555e7a9f2 allow a provisioner to timeout
* I had to contextualise Communicator.Start and RemoteCmd.StartWithUi
NOTE: Communicator.Start starts a RemoteCmd but RemoteCmd.StartWithUi will run the cmd and wait for a return, so I renamed StartWithUi to RunWithUi so that the intent is clearer.
Ideally in the future RunWithUi will be named back to StartWithUi and the exit status or wait funcs of the command will allow to wait for a return. If you do so please read carrefully https://golang.org/pkg/os/exec/#Cmd.Stdout to avoid a deadlock
* cmd.ExitStatus to cmd.ExitStatus() is now blocking to avoid race conditions
* also had to simplify StartWithUi
2019-04-08 20:09:21 +02:00
Matthew Hooker
6d997d82e0
preserve left-side whitespace in output 2017-07-24 14:24:28 -07:00
Matthew Hooker
f1175c1921
parallels/vmware: don't wait for shutdown command.
Resolves #4134

replaces/ closes #4379

Leaving Hyper-V builder alone for now until we can get a case that reproduces.
2017-01-20 01:44:18 -08:00
Matthew Hooker
892d5e82c9 expect_disconnect option
provisioner/shell: Adds option to fail if the remote server disconnects
us.
2016-10-21 11:39:03 -07:00
Vasiliy Tolstov
feee19e4ed file provisioner improvements
* allow specify source/destination as dir
* allow specify many files as source

Signed-off-by: Vasiliy Tolstov <v.tolstov@selfip.ru>
2016-02-12 11:48:28 -08:00
Chris Bednarski
408250ec76 Wrap output in if statement to catch zero values from select 2015-06-03 17:13:26 -07:00
Mitchell Hashimoto
da694a6ea8 packer: try to fix flaky test 2015-05-28 15:13:10 -07:00
Ross Smith II
d92179847d provisioner/file: set file/directory permissions
fixes #1064
2014-05-09 21:03:35 -07:00
Mitchell Hashimoto
adbb490189 provisioner/file: support uploading directories [GH-251] 2013-09-09 14:00:06 -07:00
Mitchell Hashimoto
86abf14b28 communicator/ssh: Trailing slash won't create destination dir 2013-08-25 20:47:10 -07:00
Mitchell Hashimoto
46e02209a9 packer: Add UploadDir to the Communicator interface 2013-08-25 20:30:56 -07:00
Mitchell Hashimoto
6f742cb332 packer: fix data race in communicator 2013-08-21 10:16:33 -07:00
Mitchell Hashimoto
392aba1fe7 packer: Don't output up to \r with remote command, lost anyways 2013-08-12 16:55:17 -07:00
Mitchell Hashimoto
656de901ca packer: replace stdout/stderr after StartWithUi
This just kind of shields the error with StartWithUi if we retry
2013-08-12 15:17:17 -07:00
Mitchell Hashimoto
a380c1c91e packer: Use ch for condition variable
Thanks @titanous I didnt know this worked.
2013-07-29 13:20:57 -07:00
Mitchell Hashimoto
9b0c3b28c5 communicator/ssh: use SetExited 2013-07-29 12:12:42 -07:00
Mitchell Hashimoto
26a117e36f packer: use locks/conds to avoid races on RemoteCmd.Exited [GH-42] 2013-07-29 12:04:58 -07:00
Mitchell Hashimoto
7472bbb17c packer: In the case of an error, close stdout/stderr writers 2013-07-23 22:46:51 -05:00
Mitchell Hashimoto
641c46451b packer: Preserve original stdout/stderr on StartWithUi
/cc @sit
2013-07-23 22:38:03 -05:00
Mitchell Hashimoto
425aaf2cea packer: RemoteCmd.StartWithUi thanks to @sit
I ended up working on this on my own outside your PR, sorry, but it is
basically the same as yours.
2013-07-23 22:35:05 -05:00
Mitchell Hashimoto
957ebe9234 packer: Better docs for communicator interface 2013-06-20 14:46:25 -07:00
Mitchell Hashimoto
bbc5f305e2 packer: RemoteCmd.Wait 2013-06-03 10:49:23 -07:00
Mitchell Hashimoto
532faec457 packer: New Communicator interface is much simplified 2013-06-02 21:20:27 -07:00
Mitchell Hashimoto
ade3795123 packer: RemoteCommand.StderrChan 2013-06-01 18:49:49 -07:00
Mitchell Hashimoto
e753ffe5d9 packer: Refactor on StdoutChan so it'll work for stderr easily 2013-06-01 18:31:22 -07:00
Mitchell Hashimoto
810d17c0ef packer: RemoteCommand.StdoutChan works + tests 2013-06-01 18:21:27 -07:00
Mitchell Hashimoto
ace53450b9 packer: More efficient RemoteCommand.ExitChan 2013-06-01 17:57:26 -07:00
Mitchell Hashimoto
8034e91ca3 packer: Lock in RemoteCommand.ExitChan 2013-06-01 17:45:57 -07:00
Mitchell Hashimoto
24237da32c packer: RemoteCommand.ExitChan() and tests 2013-05-28 18:12:15 -07:00
Mitchell Hashimoto
15f215d04f go fmt 2013-05-20 16:50:35 -07:00
Mitchell Hashimoto
daa431af63 packer: Communicator Upload/Download return an error 2013-05-12 16:25:40 -07:00
Mitchell Hashimoto
2799cccf4b packer: Waiting for a remote command and setting the exit status 2013-05-12 16:18:17 -07:00
Mitchell Hashimoto
88a018bf5d packer: Work on communicators... WIP 2013-05-12 14:47:55 -07:00