Wilken Rivera
b9f1b3c8d4
Fix gosimple S1005 linting issue ( #8870 )
...
Results before change
```
⇶ golangci-lint run ./... --disable-all --enable=gosimple | grep 1005
fix/fixer_comm_config.go:48:4: S1005: should write `sshHostPortMinRaw := builders["ssh_host_port_min"]` instead of `sshHostPortMinRaw, _ := builders["ssh_host_port_min"]` (gosimple)
fix/fixer_comm_config.go:64:4: S1005: should write `sshHostPortMaxRaw := builders["ssh_host_port_max"]` instead of `sshHostPortMaxRaw, _ := builders["ssh_host_port_max"]` (gosimple)
fix/fixer_comm_config.go:81:4: S1005: should write `sshSkipNatMappingRaw := builders["ssh_skip_nat_mapping"]` instead of `sshSkipNatMappingRaw, _ := builders["ssh_skip_nat_mapping"]` (gosimple)
packer/artifact_mock.go:47:2: S1005: should write `value := a.StateValues[name]` instead of `value, _ := a.StateValues[name]` (gosimple)
packer/artifact_test.go:31:2: S1005: should write `value := a.state[name]` instead of `value, _ := a.state[name]` (gosimple)
```
Results after change
```
```
2020-03-11 10:30:08 +01:00
Sylvia Moss
2981fd627d
Avoid calling CoreBuild.Prepare(...) for HCL2 templates ( #8742 )
2020-02-14 17:39:32 +01:00
Sylvia Moss
23fa3107a3
Render variables one time on prepare method ( #8727 )
2020-02-13 17:35:23 +01:00
Megan Marsh
00dfb79c88
Merge pull request #7627 from hashicorp/inplace_isos
...
Inplace isos
2020-02-11 11:19:10 -08:00
Wilken Rivera
a684fae28f
mapstructure-to-hcl2: Update code formatter to use golang/x/tools/imports
2020-02-07 14:15:43 -05:00
Adrien Delorme
a19214afeb
Allow to use isos in place
2020-02-06 17:07:58 +01:00
Megan Marsh
6a07d76416
Merge pull request #8654 from hashicorp/fix_8583
...
Extract http ip discover to a new step
2020-01-28 08:50:48 -08:00
Sylvia Moss
328eb8ee96
Interpolate boot_command when defined by user variable ( #8640 )
2020-01-27 19:10:16 +01:00
Moss
0566f1f999
Extract http ip discover to a new step
2020-01-27 17:06:56 +01:00
Megan Marsh
76fa85fd93
Merge pull request #8613 from hashicorp/add_pp_names
...
log name of postprocessor running to disambiguate long chains of pps
2020-01-16 13:12:02 -08:00
Adrien Delorme
c905418d4e
Avoid field confusion be naming fields in packer/build_test.go
2020-01-16 16:24:33 +01:00
Adrien Delorme
2d1a67c6cb
hcl2: allow to optionnaly name provisioners and post-processors
2020-01-16 12:08:39 +01:00
Sylvia Moss
0677b02e18
Share SourceImageName with provisioners and manifest post-processor ( #8603 )
2020-01-16 12:04:03 +01:00
Megan Marsh
b5075a35c0
fix tests
2020-01-15 15:36:52 -08:00
Megan Marsh
e228a5bcb9
log name of postprocessor running to disambiguate long chains of pps
2020-01-15 14:47:56 -08:00
Adrien Delorme
731904d3d2
mapstructure-to-hcl2: use accessor for named types and not named type + go genrate + tests
2020-01-07 11:44:22 +01:00
Caleb Lemoine
9f6eb0ef65
fix: mispelled variables names in packer/build.go ( #8568 )
2020-01-06 14:02:29 +01:00
Megan Marsh
b51fca7857
regenerate builder mock
2019-12-17 13:49:16 -08:00
Megan Marsh
8490bbc45c
add tests for info sharing
2019-12-17 13:41:48 -08:00
Megan Marsh
cd7abf1f9e
clean up a few final issues with info sharing
2019-12-17 11:20:57 -08: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
18bb4ffb44
bump API version since this change makes things backwards incompatible.
2019-12-16 11:46:46 -08:00
Megan Marsh
82367a88f8
reorganize placeholder data call to live with provisioner implementation; force users to use the generated function, therefore forcing validation, for all variables except winrmpassword, by doing a simple string check against the placeholder data.
2019-12-14 03:32:38 -08:00
Megan Marsh
39fd462b56
change all provision func signatures to use map[string]interface{}
2019-12-12 15:38:32 -08:00
Megan Marsh
0ca7c9f397
fix tests
2019-12-11 16:29:35 -08:00
Megan Marsh
6f418d0e54
get data sharing to a working state with the powershell provisioner
2019-12-11 15:43:38 -08:00
Megan Marsh
601007e3e2
pas data into provisioners well
2019-12-11 15:43:38 -08:00
Megan Marsh
ee336e6d12
decode data interface into generatedData
2019-12-11 15:43:38 -08:00
Megan Marsh
f4c3501af5
pass struct of generated data into provision() call
2019-12-11 15:43:38 -08:00
Megan Marsh
2447c9b280
typo
2019-12-09 12:30:14 -08:00
Megan Marsh
8b50f03056
Only log min and max port when connecting via TCP; move port determination inside of the TCP function
2019-12-09 12:21:45 -08:00
Megan Marsh
a02a95e992
Move port logging to inside of appropriate functions; log the actual plugin being called if it is part of the main packer binary, rather than the meaningless information 'packer'.
2019-12-09 12:17:23 -08:00
Lars Lehtonen
a3ca0bc2aa
packer/rpc: remove unused cancelCalled field from testBuild{}
2019-11-04 12:59:55 -08:00
Lars Lehtonen
699614b500
packer/rpc: fix dropped error
2019-11-04 12:58:16 -08:00
Lars Lehtonen
67afbe6fb7
packer: remove bool constant comparisons
2019-11-04 12:54:52 -08:00
Lars Lehtonen
703f071b4a
packer: remove unused test variable
2019-11-04 12:53:16 -08:00
Lars Lehtonen
a709867dee
packer: remove unused testComponentFinder()
2019-11-04 12:50:58 -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
Adrien Delorme
a8b2918d0e
remote duplicate gob.Register(new(map[string]interface{}))
...
otherwise this panics
2019-10-15 12:56:42 +02:00
Megan Marsh
0683bc409b
add test for error-cleanup provisioner, and fix tests by fixing null builder to use an actual none communicator instead of skipping communicator generation altogether
2019-09-25 13:39:09 -07:00
Megan Marsh
5bd8fee708
Creates a final "cleanup" provisioner to run if an error occurs during a provisioning step, allowing users to perform any custom cleanup tasks that must happen on the VM before the VM is shut down and destroyed.
2019-09-24 16:08:15 -07:00
Adrien Delorme
3b8f3c5a8b
remove any reference to Push
2019-09-16 16:38:17 +02:00
Lars Lehtonen
f62bc25f18
packer/rpc: Fix tests that swallowed errors in goroutines
2019-09-11 05:22:01 -07:00
Megan Marsh
a82a3ccaa6
need to scrub sensitive variables first, to make sure we don't fail for comma-containing sensitive info
2019-08-15 16:16:11 -07:00
Megan Marsh
ce0f11a651
Merge pull request #7912 from hashicorp/set_config_dir
...
Set config dir
2019-08-13 16:33:00 -07:00
Megan Marsh
5d4d5a21bf
check env for a PACKER_CONFIG_DIR before defaulting to homedir for config
2019-07-25 13:06:41 -07:00
Christian Muehlhaeuser
216afbaa8b
Fixed various typos
...
Just a bunch of nit-picky typo fixes.
2019-07-25 06:49:51 +02:00
Megan Marsh
e54b1cedd9
text/template turns out to swallow custom error types.
2019-07-08 15:39:46 -07:00
Megan Marsh
2bbc3d50d7
better error handling when using interpolate funcs; don't swallow func errors
2019-07-08 13:49:14 -07:00
Adrien Delorme
c9a22b6380
Merge pull request #7745 from hashicorp/investigate_crash
...
small cleanups
2019-06-14 10:09:32 +02:00
Megan Marsh
88e5a21170
make sure machine readable logs print what's come through the UI into the logs
2019-06-13 10:51:44 -07:00
Megan Marsh
a907adb4ab
Merge pull request #7743 from hashicorp/fix_7728
...
filter machine readable UI
2019-06-12 13:00:26 -07:00
Megan Marsh
df977926ba
filter machine readable UI
2019-06-12 09:50:27 -07:00
Adrien Delorme
f097deab3b
Merge pull request #7739 from hashicorp/fix_7728
...
apply logSecretFilter to output from ui.Say
2019-06-12 11:01:25 +02:00
Adrien Delorme
2eef6a1492
Merge pull request #7726 from hashicorp/packer-interpolate
...
Packer console
2019-06-12 11:00:11 +02:00
Megan Marsh
1e5866bd2a
apply logSecretFilter to output from ui.Say
2019-06-11 14:04:36 -07:00
Adrien Delorme
ddb4d77dc8
Update packer/core.go
...
remove commented log line
2019-06-11 11:09:22 +02:00
Megan Marsh
ca99cbd2d2
remove loglines
2019-06-10 11:34:57 -07:00
Megan Marsh
1a9adc29b3
fixing interpolation
...
fix sensitive_vars test which never worked but somehow was passing before this change.
2019-06-10 11:30:52 -07:00
Megan Marsh
b8ac1a800d
implement a packer console analogous to the terraform console
2019-06-05 16:35:22 -07:00
Adrien Delorme
ce15617d05
TestPausedProvisionerProvision_waits: don't fail when we spend too much time.
2019-05-24 18:21:53 +02:00
Adrien Delorme
dc631530d2
stop using goroutines in TestPausedProvisionerProvision_waits
...
to render the test less flaky.
this should fix #7684
2019-05-24 17:56:27 +02:00
Paul Meyer
ec14ab4875
Add unit test to find issue #7655
2019-05-17 22:27:19 +00:00
Megan Marsh
70c223045e
fix race condition in hooks
2019-05-10 10:25:54 -07:00
Adrien Delorme
5f076d4328
allow building packer on solaris by removing progress bar and tty imports
...
fix #7586
2019-05-07 15:58:49 +02:00
Adrien Delorme
051f39e21d
Merge pull request #7583 from hashicorp/update_custom_plugin_docs
...
update docs defining Builders and PostProcessors
2019-04-30 11:58:53 +02:00
Megan Marsh
2e0f9223c8
remove all the extra debug lines
2019-04-29 10:33:41 -07:00
Adrien Delorme
1be337b383
update docs for definig Builders and PostProcessors
2019-04-29 13:16:46 +02: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
8565a30c69
TimeoutProvisioner: also display an error log when the context times out
2019-04-09 17:46:38 +02:00
Adrien Delorme
eadb40da91
Update communicator_test.go
...
fix tess
2019-04-08 20:09:21 +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
d8d5631dc2
allow to set provisioner timeout from buildfile
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
Adrien Delorme
f7cd2b9334
add a 5 seconds timeout to provisioner hook
2019-04-08 20:09:21 +02:00
Adrien Delorme
a81abd297b
Merge remote-tracking branch 'origin/master' into context_provisioner
2019-04-08 20:09:01 +02:00
Megan Marsh
1f7150e2ee
Merge pull request #7463 from hashicorp/default_keep_input_artifact
...
Default keep input artifact
2019-04-05 08:10:40 -07:00
Megan Marsh
96c94d2fa0
clean up code comments
2019-04-03 14:04:03 -07:00
Megan Marsh
10f47b5158
document clearly what keep_input_artifact does for each post-processor
2019-04-03 13:57:22 -07:00
Megan Marsh
056fcb7cea
fix tests and add a few new ones
2019-04-03 11:32:49 -07:00
Megan Marsh
c1960840e3
fix tests
2019-04-03 11:01:52 -07:00
Megan Marsh
a358b174a4
make sure we filter the ui as well as the logs
2019-04-03 10:43:41 -07:00
Megan Marsh
365b32eb9c
goofing
2019-04-03 09:43:39 -07:00
Adrien Delorme
82c4b76639
[Builder|Build|PostProcessor|Provisioner|Hook]Server: context cancel using a RPC cancel method
2019-04-03 15:55:55 +02:00
Adrien Delorme
14048b1e11
Revert "WIP: go towards context cancelled rpc pkg"
...
This reverts commit e4609b4a6a4ba2ec76a45ad67d50d180f1a914f9.
2019-04-03 15:55:55 +02:00
Adrien Delorme
9e3a179c0d
WIP: go towards context cancelled rpc pkg
2019-04-03 15:55:55 +02:00
Adrien Delorme
39a5e4e612
rpc server register funcs: return errors
2019-04-03 15:55:55 +02:00
Adrien Delorme
e65115a7a0
contextualize post-processor
2019-04-03 15:55:55 +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
Adrien Delorme
829851fc8a
change hooks to be passed a context for cancellation
...
we have to as it is what calls our provisioners
2019-04-03 15:55:54 +02:00
Adrien Delorme
c7ce4d598e
change Provisioner to be passed a context for cancellation
2019-04-03 15:55:54 +02:00
Adrien Delorme
dae02c0877
add context to Provisioner.Provision interface signature
2019-04-03 15:55:54 +02:00
Megan Marsh
12fc1fa751
default_keep_input_artifact
2019-04-02 16:51:58 -07:00
Megan Marsh
3aa0e51104
I use Dir instead of Base for mkdirall call
2019-03-28 13:17:15 -07:00
Adrien Delorme
42107c2b8b
CachePath: only create base path
2019-03-19 15:30:01 +01:00
Adrien Delorme
5a6dffde9a
use port as ints
2019-03-19 15:01:12 +01:00