Commit Graph

56 Commits

Author SHA1 Message Date
Adrien Delorme d2964d59e9 document that the `-var-file` option still expects JSON files for now 2020-03-03 17:19:51 +01:00
Adrien Delorme 193dad46e6
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.

* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 11:49:21 +01:00
Megan Marsh 5bacd37014 fix pps 2019-12-17 16:13:21 -08:00
nywilken 3d56f8ac80 command/build: Fix URL to HCL2 syntax guide
* small typo fixes
2019-12-17 15:36:04 -05: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
Moss 7466c4fdca Return exit code 1 when builder type is not found 2019-12-10 18:55:18 +01:00
Thomas Meckel d3202497ae First working version of virtualbox/vm builder 2019-07-26 12:29:44 +02:00
Adrien Delorme 5efab58ed8 allow to have timestamped colorless ui messages 2019-06-19 15:04:13 +02:00
Adrien Delorme cb2d89af6f simplify path parsing by making at string instead of an array + add tests 2019-05-07 11:51:21 +02:00
Adrien Delorme a4b8570991 refactor arg parsing into it's own cfg maker & test it 2019-05-07 11:43:18 +02:00
Adrien Delorme 7e8c42d243 BuildCommand: put config in a local struct 2019-05-07 11:15:35 +02:00
Adrien Delorme 2890687b2b fix race condition in BuildCommand
a map[string]error was being written on unprotectedly
2019-05-06 15:42:23 +02:00
Adrien Delorme af15ed3583 nil signals are probably just a cancellation in disguise 2019-05-06 15:29:59 +02:00
Adrien Delorme dd2785ff08 BuildCommand.Run: avoid triggering a cancellation on termination 2019-05-06 12:26:22 +02:00
Adrien Delorme 0094d2878c Build: move BuildCommand.Run into a RunContext command to allow testing for cancellation, put cancellation in `Run` 2019-05-06 12:19:59 +02:00
Adrien Delorme d40d3eca88 swap semaquire and wg.Add to avoid a deadlock 2019-05-03 08:19:33 +02:00
Adrien Delorme 263f318e82 be true to docs 2019-05-02 17:48:34 +02:00
Adrien Delorme 1dca416f87 move the semacquire to the main build loop so that the build order is kept
* a goroutine could start before another !
2019-05-02 16:58:28 +02:00
Adrien Delorme 9281fada2d prevent a breaking change so that we can merge the `-parallel-builds` option first. 2019-05-02 16:24:28 +02:00
Brett Wandel aaf56ffd26 added: testing 2019-05-02 08:38:56 +10:00
Brett Wandel 76b5c1995f fixed: small changes to cancellation on ctrl-c 2019-04-19 17:10:36 +10:00
Brett Wandel 92e75f838a added the ability to limit number of builds running in parallel 2019-04-13 22:31:54 +10: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
Adrien Delorme 045f2f41bd display received signal in debug mode 2019-03-22 14:25:06 +01: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
Andrew Widdersheim a5b753820c
Fix build commands -except help message
The `-except` option needed some updates that were missed in 270f851e.
2019-03-05 10:54:35 -05:00
Josh Soref 66738ccaf4 Try to make help more consistent
Also try to synchronize the completion script
2018-10-10 21:34:35 -04:00
Adrien Delorme 626a3cc2a4 have -timestamp-ui match what's in doc
this was just an omission
also `=true` is not a necessary precision in this case

#6784
2018-10-03 14:40:13 +02:00
Ashley Lowde 2884f6fab6 improve formatting and documentation for PR#6784 2018-10-02 20:00:45 +09:30
Ashley Lowde 12496e3702 add optional timestamps to build log 2018-09-29 22:39:24 +09:30
Oleg Butuzov 079b317b62 Misaligned help entries
Descriptions for `build` subcommand aligned.
hashicorp/packer#6652
2018-09-01 10:32:23 +03:00
M. Marsh eb557af8bf
Merge branch 'master' into f-autocomplete 2018-04-26 11:18:37 -07:00
SwampDragons 997f8e4a2a
Merge pull request #5318 from hashicorp/sigtermcleanup
Gracefully clean up on SIGTERM
2018-02-02 11:56:56 -08:00
Matthew Hooker 807e88245b
trying to add context to state bag 2018-01-24 17:09:15 -08:00
Jeremy Voorhis bfc75eb9d9 Implement cli.CommandAutocomplete for most commands 2017-10-13 11:57:44 -07:00
Jeremy Voorhis a4cb8ae41b Define methods on *BuildCommand (consistency) 2017-10-13 11:57:44 -07:00
Matthew Hooker fdaf4ed8d3
Gracefully clean up on SIGTERM 2017-09-08 11:42:32 -07:00
Matthew Hooker 81522dced0
move packer to hashicorp 2017-04-04 13:39:01 -07:00
Matthew Hooker 048e316645
s/TargettedUi/TargetedUI/ 2017-03-29 12:44:42 -07:00
Matthew Hooker 230079f73a
spell fixes 2017-03-28 20:36:19 -07:00
Matthew Hooker 11354aa1b7
tidy up new line 2017-02-09 17:45:42 -08:00
Matthew Hooker 60955d8c2c
don't show ui color if we're not colorized 2017-02-09 17:41:42 -08:00
Jake Champlin 95760462a6
Update help output for build command
The `-only` flag has been around for some time now, and is documented on
our packer website, yet the help output for `packer build` lacks this
command line option.
2016-11-14 10:06:43 -05:00
Orivej Desh 4fe86244a5 Improve -on-error descriptions 2016-09-18 03:00:36 +00:00
Orivej Desh 639bf356aa Fail on unknown values of -on-error 2016-09-17 14:42:21 +00:00
Orivej Desh e9cc28565b Document -on-error on the "packer build" page 2016-09-16 12:15:00 +00:00
Orivej Desh 6762965696 Add -on-error command line argument to allow preserving artifacts on builder errors
Resolves #409
2016-09-16 12:15:00 +00:00
Christopher Boumenot ad3d674919 Do not use Fprintf, use Fprint. 2016-04-05 22:41:26 -07:00
Alvaro Miranda 6237df566f add -color to build -h command 2016-03-23 04:40:24 +13:00
Mark Peek 71ed8e4a38 Fix #2742: Include template line numbers on error 2015-10-25 12:28:06 -07:00