Commit Graph

114 Commits

Author SHA1 Message Date
Adrien Delorme 39261f3671 add hcl2 post processor type that reprepares itself 2020-07-06 10:32:39 +02:00
Adrien Delorme db6c3adbba add hcl2 provisioner type that reprepares itself 2020-07-02 18:02:19 +02:00
Adrien Delorme 284d46a1e0 WIP 2020-07-02 15:56:49 +02:00
Adrien Delorme 7969b690de Revert "Share build info with Provisioner and Post-Processor via HCL2 variables (#9444)"
This reverts commit 99046c9178.
2020-07-02 15:07:29 +02:00
Adrien Delorme 3d371a2d5d
Add complete HCL2 examples + allow to name a singular build.source blocks (#9490)
* in the examples/hcl folder
* add possibility to name singular build.source blocks to differentiate their output and to filter on them
2020-07-02 11:07:59 +02:00
Sylvia Moss 99046c9178
Share build info with Provisioner and Post-Processor via HCL2 variables (#9444) 2020-06-29 13:44:57 +02:00
Adrien Delorme c2975140cf
HCL2: allow to use keep_input_artifact in post processors (#9477)
* HCL2: allow to use keep_input_artifact in post processors
* add basic test
* add docs
2020-06-25 09:36:48 +02:00
Adrien Delorme 6f4d79799b add thorough test 2020-06-23 15:40:54 +02:00
Adrien Delorme 51d02f8c2d hcl2: inspect command 2020-06-23 11:58:57 +02:00
Adrien Delorme a96a8f22b9 HCL2: allow to describe a build block 2020-06-23 11:58:34 +02:00
Adrien Delorme fb337f8867
hcl work on only/except (#9454)
* HCL2: allow to skip a named build block too

* test that excepting a build block works

* test only on a named build block

* add/update docs
2020-06-23 10:53:16 +02:00
Moss daaeccd8b0 Skip consecutives post-processors 2020-06-09 17:35:53 +02:00
Moss 6599e7ab05 apply goimports 2020-06-09 15:29:32 +02:00
Moss bfb9df0039 fix except flag for JSON and HCL2 2020-06-09 15:26:45 +02:00
Adrien Delorme cf6eca7e1c Revert "Add pwd function to HCL"
This reverts commit 2800043149.
2020-06-08 14:59:27 +02:00
Adrien Delorme 44dfa221de Revert "Add template_dir function to HCL"
This reverts commit 3b9a0427cd.
2020-06-08 14:59:22 +02:00
Megan Marsh d73f83a9d9
Merge pull request #9367 from jeremiahsnapp/add-template_dir-and-pwd-functions
Add template_dir() and pwd() functions to HCL
2020-06-05 12:57:04 -07:00
Wilken Rivera f672f5bd9b command/validate: Add support for HCL2 configuration files
* Update validate command to use FixConfig for checking against known
fixers
* Update validation command flag docs
* Add ConfigFixer method to PackerHandler Interface
* Implement ConfigFixer interface in PackerConfig
* Remove all stdout messaging (i.e calls to c.Ui.Say) in the validate
command. The command will only display hcl.Diagnotic messaging when there is an error or warning.

HCL2 Configs
```
⇶  packer validate docker_centos_shell_provisioner.pkr.hcl

```

JSON Configs
```
⇶  packer validate vmware-iso_ubuntu_minimal/vmware-iso_ubuntu_minimal.json
Error: Failed to prepare build: "vmware-iso"

1 error occurred:
        * Deprecated configuration key: 'iso_checksum_type'. Please call `packer fix`
against your template to update your template to be compatable with the current
version of Packer. Visit https://www.packer.io/docs/commands/fix/ for more
detail.

Warning: Fixable configuration found.
You may need to run `packer fix` to get your build to run correctly.
See debug log for more information.

  map[string]interface{}{
        "builders": []interface{}{
                map[string]interface{}{
                        ... // 3 identical entries
                        "guest_os_type":     string("ubuntu-64"),
                        "http_directory":    string("http"),
-                       "iso_checksum":
string("946a6077af6f5f95a51f82fdc44051c7aa19f9cfc5f737954845a6050543d7c2"),
+                       "iso_checksum":
string("sha256:946a6077af6f5f95a51f82fdc44051c7aa19f9cfc5f737954845a6050543d7c2"),
-                       "iso_checksum_type": string("sha256"),
                        "iso_url":
string("http://old-releases.ubuntu.com/releases/14.04.1/ubuntu-14.04.1-server-amd64.iso"),
                        "shutdown_command":  string("echo 'vagrant' | sudo -S shutdown -P now"),
                        ... // 4 identical entries
                },
        },
  }
```
2020-06-05 14:24:39 -04:00
Jeremiah Snapp 3b9a0427cd Add template_dir function to HCL
Signed-off-by: Jeremiah Snapp <jeremiah@chef.io>
2020-06-05 13:14:36 -04:00
Jeremiah Snapp 2800043149 Add pwd function to HCL
Signed-off-by: Jeremiah Snapp <jeremiah@chef.io>
2020-06-05 13:14:03 -04:00
Adrien Delorme bac9c74447
packer console for HCL2 (#9359) 2020-06-05 17:23:54 +02:00
Jeremiah Snapp 0d7c5dc670
Enable only/except for provisioners and post-processors (#9357) 2020-06-05 11:51:23 +02:00
Adrien Delorme f09fd790b7
Merge branch 'master' into master 2020-06-02 15:12:44 +02:00
Adrien Delorme 1147ef9a36
Merge pull request #9291 from hashicorp/f-singular-build-source-blocks
Allow to set source fields from a new `build.source` block
2020-06-02 12:38:45 +02:00
Adrien Delorme 6a406ffb1d
Update hcl2template/types.source.go
Co-authored-by: Megan Marsh <megan@hashicorp.com>
2020-06-02 11:52:11 +02:00
Adrien Delorme 225081c3a6
Update hcl2template/types.source.go
Co-authored-by: Wilken Rivera <dev@wilkenrivera.com>
2020-06-02 11:51:48 +02:00
Adrien Delorme b4aa71aef2 Merge remote-tracking branch 'origin/master' into pr/AdrienneCohea/9245 2020-06-02 11:36:32 +02:00
Adrien Delorme 059a782b0e remove debug log 2020-05-28 17:07:11 +02:00
Adrien Delorme 8a13dd3073 HCL2: Make the `build`.`sources` argument list optional 2020-05-28 16:38:41 +02:00
Adrien Delorme 40947c2bf6
HCL2: generate hcl tags with go-cty tags too (#9306)
This will allow to generate the config files:

```go
package main

import (
	"fmt"

	"github.com/hashicorp/hcl/v2/gohcl"
	"github.com/hashicorp/hcl/v2/hclwrite"
	"github.com/hashicorp/packer/builder/alicloud/ecs"
)

func main() {
	name := "name"
	app := ecs.FlatConfig{
		AlicloudImageName: &name,
		ECSSystemDiskMapping: &ecs.FlatAlicloudDiskDevice{
			DiskName: &name,
		},
	}

	f := hclwrite.NewEmptyFile()
	block := gohcl.EncodeAsBlock(&app, `source "something" "something"`)
	f.Body().AppendBlock(block)
	fmt.Printf("%s", f.Bytes())
}

```

Will output:

```
source "something" "something" {
  packer_user_variables      = null
  packer_sensitive_variables = null
  image_name                 = "name"
  image_share_account        = null
  image_unshare_account      = null
  image_copy_regions         = null
  image_copy_names           = null
  tags                       = null
  tag                        = null
  system_disk_mapping        = { disk_category = null, disk_delete_with_instance = null, disk_descri
ption = null, disk_device = null, disk_encrypted = null, disk_name = "name", disk_size = null, disk_
snapshot_id = null }
  image_disk_mappings        = null
  ssh_remote_tunnels         = null
  ssh_local_tunnels          = null
  ssh_public_key             = null
  ssh_private_key            = null
}
```

This is a good first step for #9015 and #9282 

fix #9304
2020-05-28 11:19:00 +02:00
Megan Marsh 3dc4ba2d68
Json vs HCL2 parity refactor (#9301)
* refactor so that json and hcl2 templates are both prepared in the same place in the build call, to make code easier to reason about. Remove overly verbose error output which isn't useful in vast majority of cases

* fix tests

* check err msg

* hcl2template.PackerConfig.GetBuilds: raise a diagnostic in case the packer core build perpare call errors

Co-authored-by: Adrien Delorme <adrien.delorme@icloud.com>
2020-05-28 10:43:58 +02:00
Adrien Delorme 125ffe36c3 Allow to override some source fields from the build section
Using `hcl.MergeBodies`
2020-05-25 17:09:37 +02:00
Megan Marsh 24dd7e9dbb
Merge pull request #9257 from hashicorp/azr-hcl2-use-source-type-and-name
HCL2: use source type and name as Name of a CoreBuild
2020-05-20 11:36:15 -07:00
Adrien Delorme 1ddf2a7d05 Update types.packer_config_test.go 2020-05-19 17:35:24 +02:00
Adrien Delorme d431db0a38 HCL2: use source type and name as Name of a CoreBuild 2020-05-19 17:22:04 +02:00
Adrienne Cohea 6c6039798c
Add test. 2020-05-17 23:27:06 -07:00
Adrienne Cohea 6aea8ead6a
Support named builds in HCL2 templates. 2020-05-17 22:13:35 -07:00
Megan Marsh ee5635722b enable force, debug, and on-error for hcl2 builds 2020-05-14 16:22:51 -07:00
Adrien Delorme 1f3e85185e Update types.packer_config.go 2020-05-08 17:19:49 +02:00
Adrien Delorme 0062160581 Update common_test.go 2020-05-08 17:01:42 +02:00
Adrien Delorme 42a05e1e80 more refactoring 2020-05-08 16:41:47 +02:00
Adrien Delorme 526d040534 document Parser.Parse better 2020-04-30 11:51:24 +02:00
Adrien Delorme 5c2b8da63b get builds from PackerConfig instead of parser
to allow just reading the config and to not start anything. This will allow to later on run `validate --syntax-only`.

Note that none of the builder/provisioner/post-processor config will be read but simply ignored. HCL2 still needs the body to be properly formatted and it should detect most syntax errors.
2020-04-29 16:36:40 +02:00
Adrien Delorme 2df21496b3 hcl2template: let PackerConfig actually start a builder/provisioner/post-processor 2020-04-29 16:15:42 +02:00
Adrien Delorme a3343c1848 Delete zz_retrocompat.go
it's dead/unused code I previously though I'd need it
2020-04-29 15:33:10 +02:00
Tom Dyas c0a6623ea2
teach HCL mode builds to honor -only and -except options (#8947) 2020-04-28 15:03:24 +02:00
Adrien Delorme 73242e8de4 make sure keyvalue and namevalue filters are using the same naming as the service being used 2020-04-16 17:22:13 +02:00
Sylvia Moss 553b1fb9f8
Add RetriedProvisioner to allow retry provisioners (#9061) 2020-04-16 11:58:54 +02:00
Adrien Delorme 840e67f775
HCL2: when we see a map generate an attribute spec instead of a block spec (#9035)
* mapstructure-to-hcl2: when we see a map generate an attribute spec and not a block spec

this will alow to do

tags = {
 key = "value"
}

instead of

tags {
  key = "value"
}

This will also enable using variables directly for those tags

* generate code

* update tests
2020-04-14 16:05:13 +02:00
Adrien Delorme 2af40c762b
HCL2: pass on builder type and name (#8956)
* sets `packer_build_name` and `packer_builder_type` variables for builder provisioners and post-processors in HCL2
* allows to use the new `${source.type}` and `${source.name}` variables in HCL2
* fixes #8932 

Note that the common.PackerConfig is used everywhere and was not set for HCL2, this had some implications: 

For #8923 you can see the issue here:

dde74232f2/builder/lxd/config.go (L61-L63)

More random examples of where this could cause an issue :

0785c2f6fc/provisioner/ansible-local/provisioner.go (L380-L381)

b4efd13a4d/builder/amazon/ebs/builder.go (L232-L236)



* [All references to PackerConfig.PackerBuildName](https://sourcegraph.com/github.com/hashicorp/packer@ff6a039d5bb45e34ff761d9c52e8b98972288447/-/blob/common/packer_config.go#L7:2&tab=references)

* [All references to PackerConfig.PackerBuilderType](https://sourcegraph.com/github.com/hashicorp/packer@ff6a039d5bb45e34ff761d9c52e8b98972288447/-/blob/common/packer_config.go#L8:2&tab=references)
2020-04-09 11:14:37 +02:00