244 Commits

Author SHA1 Message Date
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
Jeff Escalante
9165be87da
packer.io prefix removal, html extension remove for in-code errors 2020-04-07 17:53:22 -04:00
Adrien Delorme
d068430abf
make sure locals are evaluated only once variables are + test this (#8918)
fix #8898
2020-03-19 15:30:34 +01:00
Adrien Delorme
ad8dafa3bd
HCL: add tests and fixes around var-file and var args (#8914) 2020-03-19 13:57:22 +01:00
Adrien Delorme
88297c796d Merge branch 'master' into hcl2_singular_blocks 2020-03-17 14:47:17 +01:00
Adrien Delorme
3beea4fb94 NameValues.CopyOn: don't instanciate a receiving map if there is nothing to copy over 2020-03-17 12:00:23 +01:00
Adrien Delorme
b5e8750f5f Change key/value to name/value to remain consistent with Terraform 2020-03-17 11:23:11 +01:00
Adrien Delorme
c845436e32 KeyValues.CopyOn: make sure a receiving nil map is set too 2020-03-16 15:46:08 +01:00
Adrien Delorme
87d6b2433f make generate 2020-03-16 15:21:29 +01:00
Adrien Delorme
6e6490d688 WIP 2020-03-13 18:04:48 +01:00
Adrien Delorme
af38430eb8 add kvfilter type that regroups very frequently used filters 2020-03-13 17:17:00 +01:00
Adrien Delorme
9e6d5da277 hcl2: add general kv store that could be used anywhere 2020-03-13 16:04:42 +01:00
Adrien Delorme
c9ec967205 better testing 2020-03-12 18:01:25 +01:00
Adrien Delorme
710ebdcef5 add more test for var files 2020-03-12 17:08:53 +01:00
Adrien Delorme
c8300b620a allow to use hcl files as var files in HCL mode
fix #8781
2020-03-12 15:41:40 +01:00
zac
79f1fab836
hcl2template/types: add spaces in error messages. (#8881) 2020-03-12 13:40:25 +01:00
Megan Marsh
e518a0a8b7
Merge branch 'master' into update_go-cty_regex 2020-03-10 10:52:42 -07:00
Adrien Delorme
0c45bd8b4f import new replace and regex replace funcs from go-cty + documentation 2020-03-10 16:14:25 +01:00
Adrien Delorme
631f402d1e Merge branch 'master' into fix_8730 2020-03-09 17:49:33 +01:00
Adrien Delorme
0ccff0d5b9 all variables must have a value.
A variable's default value can be set to null to force user to set it.
2020-03-09 17:25:56 +01:00
Adrien Delorme
6d8cce501e tweak validation & add tests 2020-03-09 16:16:59 +01:00