Commit Graph

52 Commits

Author SHA1 Message Date
Sylvia Moss dc31bad539
Sharing info with post-processors via artifact (#8632) 2020-01-30 11:27:58 +01:00
Megan Marsh a847530a83
Update builder/vagrant/driver_2_2.go
Co-Authored-By: Wilken Rivera <dev@wilkenrivera.com>
2020-01-15 13:12:44 -08:00
Megan Marsh 48811ed4e5 replace buffer copy loop with a scanner that handles carriage returns 2020-01-15 12:05:29 -08:00
Megan Marsh 6315f69019 break out of loop once channel is read from. 2020-01-15 11:00:41 -08:00
Megan Marsh bbd64896a0 use strconv.unquote instead of DIY 2020-01-15 10:23:25 -08:00
Megan Marsh 5980d32efb remove unhelpful quotes to fix bug with reading key from a path with spaces in it. 2020-01-14 13:57:11 -08:00
Adrien Delorme a67948f155 fix config pointers 2019-12-19 17:51:57 +01:00
Adrien Delorme 4b7132c87c Merge remote-tracking branch 'origin/master' into sharing_info 2019-12-17 11:57:09 +01:00
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 0f6d1beccf add an extra string array to the Prepare() return values in the builder interfaces; this sets up the ability for builders to give the provisioners custom user-accessible build-time variables. 2019-12-16 21:23:05 -08:00
Megan Marsh 84063d2132 implement ID and Type values in the provisioner template info sharing 2019-12-13 11:57:01 -08:00
Megan Marsh 5692294a96 use absolute path for vagrantfile to avoid confusion with build directory later 2019-11-04 15:15:37 -08:00
Adrien Delorme 819329228a Change back to make sure all durations are a time.Duration
It is simply the best/simplest solution and trying to prevent users from passing and integer here would be like opening a can of worms. Because:

* we cannot make mapstructure validate our duration string ( with an UnmarshalJSON func etc.)
* we cannot make mapstructure spit a string instead of a duration and packer will decode-encode-decode config.
* the hcl2 generated code asks for a string, so this will be enforced by default.
2019-10-31 16:12:07 +01:00
Adrien Delorme bf3d9841c6 Force durations to be passed a strings
Before this commit it was possible to set a duration using an integer or a float. Go's time.Duration is an int64 internally an mapstructure will take advantage of this and load the number as a int64 but `1` means one ns which is unexpected/confusing. To avoid confusion and enforce readability this forces users to pass a string with a unit for a duration; ex "56s".
2019-10-31 11:47:19 +01:00
Megan Marsh 2fa79c6086 fix tests 2019-10-30 13:48:12 -07:00
Megan Marsh 8f996cd4de update docs 2019-10-30 13:36:56 -07:00
Megan Marsh 3b3aa562ed add insert_key option for toggling whether to add Vagrant's insecure key 2019-10-30 13:27:34 -07:00
Megan Marsh a7be0bed30 Make Vagrant driver code pass through logs as it receives them rather than buffering and returning them all at the end of the call. 2019-10-24 13:12:35 -07:00
Adrien Delorme 078ba7c8c3 commit old code generation tool
for history
2019-10-15 12:56:42 +02:00
Adrien Delorme 6fbd664b66 builder.vagrant: simplify communicator.Config field 2019-10-15 12:56:42 +02:00
Megan Marsh f0461da1a1
Merge pull request #7724 from hashicorp/scrape_doc_to_builder_struct_config
Generate builder documentation markdown from structs.
2019-09-20 16:50:39 -07:00
Adrien Delorme 3fe9d52e3f Merge remote-tracking branch 'origin/master' into scrape_doc_to_builder_struct_config 2019-09-20 11:15:44 +02:00
Megan Marsh 30f86bb778 fix ssh and package steps to use source syntax. 2019-09-18 13:15:49 -07:00
Lars Lehtonen c6212731ff builder/vagrant: fix dropped errors in code and tests 2019-09-17 05:39:23 -07:00
Miles Crabill e6d2a97e12
s/destory/destroy 2019-09-10 14:31:00 -07:00
Miles Crabill 7850bf8bc5
use GlobalID where provided, add test for `vagrant up` args generation 2019-09-10 10:46:16 -07:00
Adrien Delorme 4cb7c30987 Merge remote-tracking branch 'origin/master' into scrape_doc_to_builder_struct_config 2019-08-21 16:44:23 +02:00
Miles Crabill ff157c8a6d
vagrant builder: define source box and output box in Vagrantfile 2019-08-07 10:11:34 -07:00
Megan Marsh 327cd67557 fix tests 2019-07-09 15:42:48 -07:00
Megan Marsh 4a9d42b78f use box_name instead of source_path when generating vagrant file 2019-07-09 15:26:04 -07:00
Megan Marsh 06a0db9350 allow user to override vagrant authentication by setting ssh_username and ssh_password. 2019-06-21 16:27:34 -07:00
Adrien Delorme 8488176dae vagrant/builder.Config rewrap docs 2019-06-06 16:21:21 +02:00
Adrien Delorme e6cbb013ba add // go:generate struct-markdown to all previously edited files 2019-06-05 16:42:18 +02:00
Adrien Delorme f1917edd34 generate the comments for config struct of builders scraping doc website 2019-06-05 16:42:17 +02:00
Brian Fox d6776dc5f2 Remove unused variable 2019-06-03 11:10:01 +02:00
Adrien Delorme 783f6938cf
Update builder/vagrant/driver_2_2.go 2019-05-13 10:43:09 +02:00
Megan Marsh ff59cfdaae Work around bug in libvirt-vagrant plugin by changing directories instead of supplying absolute path to output box 2019-05-10 16:11:41 -07:00
Adrien Delorme c4f3dccc14 rename interpolation context from ctx to ictx and contexts to ctx to avoid conflicts 2019-04-03 15:56:15 +02:00
Adrien Delorme a4bf94dd3c change Builder to be passed a context for cancellation
we have to to give it to our hook
2019-04-03 15:55:55 +02:00
Esten Rye ba5385b224 Fix invalid character issue on Windows.
Output from driver includes a `\r` character.  This change adds logic to
trim `\r` and `\n` values from parsed output.

#7414
2019-03-15 20:00:27 -05:00
Megan Marsh 24c42e4a1f
Merge pull request #7397 from vhaidamaka/fix-7321
Add vagrant-cloud post-processor support for the vagrant builder
2019-03-15 16:00:05 -07:00
Adrien Delorme 9f82b75e57 Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 12:11:58 +01:00
Vadym Haidamaka 4855bc79c9 Add vagrant-cloud post-processor support for the vagrant builder 2019-03-12 05:33:46 +02:00
Megan Marsh 9f702af6d9 we lost the skip_add step somewhere 2019-02-14 14:46:14 -08:00
Megan Marsh 5057220ad2 use VAGRANT_CWD rather than changing packer run directories 2019-02-07 14:35:01 -08:00
Megan Marsh dc848ea5d7 just make vagrantfile instead of calling init 2019-02-07 12:39:56 -08:00
Megan Marsh e56d7f7234 fix tests 2019-02-05 15:34:59 -08:00
Megan Marsh 608b7cb7a3 review comments 2019-02-05 15:16:47 -08:00
Megan Marsh a7d9d62996 fix tests on windows 2019-02-04 16:11:25 -08:00
Megan Marsh af7131b169 tests, logic cleanup, docs for vagrant builder 2019-02-04 14:08:43 -08:00