Commit Graph

631 Commits

Author SHA1 Message Date
Adrien Delorme f91429f256 fix goimports 2020-02-06 18:18:03 +01:00
Adrien Delorme d45eca5cdc update tests 2020-02-06 18:17:57 +01:00
Adrien Delorme a8e717ae09 ISOConfig.Prepare: fix ChecksumFromFile usage 2020-02-06 17:51:15 +01:00
Adrien Delorme 8e6bad209b try to use isos inplace whatever the os 2020-02-06 17:50:29 +01:00
Chris Cunningham e94ed9a683 update the note about Windows symlinks
GH-7534 and GH-7545 disabled the use of symlinks for copying local ISOs, 
per:

https://github.com/hashicorp/packer/blob/master/common/step_download.go#L106

Update the documentation to match, as without reading the source it is 
implied that this should work.
2020-02-06 17:38:57 +01:00
Adrien Delorme a19214afeb Allow to use isos in place 2020-02-06 17:07:58 +01:00
Megan Marsh dde7302265
Merge pull request #8689 from hashicorp/fix_8530
Add iso file name when targetPath is a directory
2020-02-04 13:43:09 -08:00
Moss f2c8e8491c Fix format 2020-02-04 18:22:43 +01:00
Moss e020da49f3 Add iso file name when targetPath is absolute 2020-02-04 18:06:47 +01:00
Wilken Rivera 561f02cc2f
builder/azure-arm: Update logic for setting subscriptionID (#8685)
* builder/azure-arm: Update logic for setting subscriptionID

Previously, when using managed identities, the Azure builder would set the SubscriptionID in the Prepare method. But would not update it after getting the updated SubscriptionID from the metadata server. This change updates the Run method to ensure a valid subscriptionID is saved to the statebag before continuing with an image build.

Co-authored-by: Paul Meyer <paul.meyer@outlook.com>
2020-02-04 10:54:58 -05:00
Sylvia Moss dc31bad539
Sharing info with post-processors via artifact (#8632) 2020-01-30 11:27:58 +01:00
Moss 0566f1f999 Extract http ip discover to a new step 2020-01-27 17:06:56 +01:00
Sylvia Moss 0b7251a4bb
Share .Device and .MountPath between builders, provisioners and post-processors (#8621) 2020-01-20 16:29:38 +01:00
Sylvia Moss 0677b02e18
Share SourceImageName with provisioners and manifest post-processor (#8603) 2020-01-16 12:04:03 +01:00
Megan Marsh 90bdcf58bd update step_download to return an ActionContinue if the URls field is empty. this allows us to simplify the hyperv builder, and is still safe because all other builders and uses of step_download already validate that the iso url is not empty if that's what they need, most of them inside of the IsoConfig prepare function. 2020-01-07 10:45:24 -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 21a849354b fix hook data loading 2019-12-16 11:22:21 -08:00
Megan Marsh a125f81fba add some more comments 2019-12-14 03:44:09 -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 ac570e0cc0 store ssh public and private keys on shared info 2019-12-13 13:15:03 -08:00
Megan Marsh 88d4ce37c9 template functioin to let Provisioners access PACKER_RUN_UUID 2019-12-13 13:03:09 -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 e1652696a6 Rather than using reflection to grab the whole SSH config, for now just use the config convenience functions to get the majority of needed values 2019-12-13 10:02:13 -08:00
Megan Marsh 3389d843f0 update all provisioners that used the winrmpassword tooling to use the new generateddata option 2019-12-12 16:42:53 -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 5d266b20d0 generated func now validates based on data provided in context, which needs to include the future values if it is to be interpolated properly. 2019-12-11 15:43:38 -08:00
Megan Marsh 528b853178 stub out generated func for validation 2019-12-11 15:43:38 -08:00
Megan Marsh 7616fbcf3f skip shell local for now 2019-12-11 15:43:38 -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 f4c3501af5 pass struct of generated data into provision() call 2019-12-11 15:43:38 -08:00
Sylvia Moss 096cab9b48 Fix floppy doc markdown typo (#8458) 2019-12-06 14:12:11 +01:00
Megan Marsh 76bfaf9da8
Merge pull request #8394 from hashicorp/fix_iso_target_path
Don't cache when TargetPath is non-nil
2019-12-02 16:24:56 -08:00
Megan Marsh a8ffa60b46 remove the already-included packer config from top level struct 2019-11-25 11:24:00 -08:00
Megan Marsh 7d4353864f use shell struct in shell-local provisioner and post-processor. 2019-11-21 16:47:29 -08:00
Megan Marsh cf0130b9ed pick up dropped error 2019-11-20 16:16:33 -08:00
Megan Marsh 9fc8ed02ae Don't cache when TargetPath is non-nil; this messes up use of the iso_target_path iso template option. 2019-11-20 16:05:24 -08:00
Megan Marsh ae184fe31d ask for VM by name to reduce looping. 2019-11-08 16:20:03 -08:00
nywilken 3522e13b1e provisioner/shell: Add `env_var_format` support to shell provisioner
* Move setting of default EnvVarFormat to the Prepare function
* Add generated hcl2 structure for the updated Shell provisioner config
* Move `EnvVarFormat` field to shared common shell type
* Add description for the `env_var_format` parameter
* Update `env_var_format` when used with `use_env_var_file`
2019-11-06 16:28:56 -05:00
Adrien Delorme c0db000dc3
Merge pull request #8310 from alrs/resuscitate-common-floppy-tests
common: Resuscitate Floppy Tests
2019-11-04 15:50:46 +01:00
Lars Lehtonen 5926997a31
common: remove unused test function getDirectory() 2019-11-02 11:37:41 -07:00
Lars Lehtonen 9a90aa67e6
common: resuscitate TestStepCreateFloppy_missing() 2019-11-02 10:12:31 -07:00
Lars Lehtonen 8e2885e626
common: resuscitate TestStepCreateFloppy_notfound() 2019-11-02 10:10:36 -07: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 a783a09ea3
Merge pull request #8269 from paulmey/paulmey/generalize-chroot
[amazon/chroot] Move common/generic chroot builder steps to common directory
2019-10-24 14:32:01 -07:00
Paul Meyer 3be7d81ce2 Move common steps together 2019-10-24 04:21:46 +00:00
Paul Meyer e6dfe301ac Move CommandWrapper & ShellCommand to common 2019-10-24 04:06:29 +00:00
Lars Lehtonen 731e0332cf common: collect dropped error 2019-10-23 13:02:08 -07:00
Megan Marsh d15f43e4eb
Merge pull request #8232 from hashicorp/artifact-tree
HCL2 configs - part one
2019-10-22 11:54:34 -07:00
Megan Marsh e5becfc854
Merge pull request #8248 from marcinbojko/master
hyper-v fix for compacting only .vhd|.vhdx files
2019-10-21 11:47:15 -07:00
Marcin Bojko 1b4ffe546f
hyper-v fix for compacting vhdx/vhd only 2019-10-19 12:46:34 +02:00
Adrien Delorme cf1555bf17 Merge remote-tracking branch 'origin/master' into artifact-tree 2019-10-16 10:22:56 +02:00
Vladimír d6994df188
Select first adapter attached to host OS's switch
If more than one vNic is attached to vmSwitch, use the first one only.
2019-10-15 15:14:22 +02:00
Adrien Delorme 078ba7c8c3 commit old code generation tool
for history
2019-10-15 12:56:42 +02:00
Adrien Delorme 7be94f41a6 common.shell-local: unexport Ctx field
so that it doesn't temper with hcl2 generation
2019-10-15 12:56:42 +02:00
Davor Kapsa 49e4a2d9ef
Add error check 2019-10-09 15:55:07 +02:00
Megan Marsh 843986c2d4 missing bracket 2019-10-04 10:41:12 -07:00
Megan Marsh 59efa0faee rename option to error-cleanup-privisoner, which I think is clearer 2019-09-25 13:43:29 -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 299544a4c7 Merge remote-tracking branch 'origin/master' into scrape_doc_to_builder_struct_config 2019-09-20 14:47:02 +02:00
Lars Lehtonen a98f2d2170
common: fix dropped errors and warnings in test 2019-09-20 05:06:25 -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
allinwait 34ba03d3cb use printf for logging 2019-09-13 01:53:42 +03:00
allinwait 171c2a9a07 add the floppy label option 2019-09-12 12:25:22 +00:00
Adrien Delorme 597a3e323b Merge remote-tracking branch 'origin/master' into scrape_doc_to_builder_struct_config 2019-09-10 13:20:07 +02:00
Adrien Delorme aa9cc919ab Merge branch 'master' into circle_ci_windows 2019-09-10 12:54:35 +02:00
Adrien Delorme 146b88ba1e Merge remote-tracking branch 'origin/master' into scrape_doc_to_builder_struct_config 2019-09-10 12:44:46 +02:00
DanHam 2b6286c31c
Fix powershell formatting. Match style for conditionals 2019-09-09 23:05:40 +01:00
Adrien Delorme 7ba91b7d25 configure_port_test.go: don't panic when error is not what we expected 2019-09-05 17:03:54 +02:00
Marcin Bojko d4ff29f6c5 hyper-v fix when management interface is not part of virtual switch
2


formatting fix
2019-08-22 07:54:50 +02: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
Megan Marsh cd3b39ad17 commit generated code 2019-08-12 15:55:43 -07:00
Stephen Fox a6830f8348 Move 'ui' variable closer to invocation. 2019-07-31 14:08:40 -04:00
Stephen Fox e362d2f3ee Use 'log.Printf()' for StepDownload debug instead of 'ui.Say()'. 2019-07-31 14:02:57 -04:00
Megan Marsh 90c5da40f2 implement abort logic and printing for the askstep implementation as well 2019-07-26 12:24:03 -07:00
Megan Marsh 54034689ef On abort, return gracefully rather than exiting so that the subprocess doesn't unexpectedly disconnect from the parent and cause a confusing EOF error in the logs 2019-07-25 16:32:16 -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 e9549d2688 add test for local fs download 2019-07-22 09:17:48 -07:00
Megan Marsh 197a283b5e actually check for filepath being present 2019-07-19 10:35:50 -07:00
Megan Marsh 64f16474f8 fix double slash conundrum 2019-07-19 10:16:40 -07:00
WilliamB aef77771c0 Correct HTTPIP == FALSE on HyperV builder 2019-07-17 03:41:41 -05:00
Megan Marsh d6d4eb2087 fix some tests and some config behavior to prevent null dereference errors and incorrect precedence between iso checksum and iso checksum url 2019-06-28 15:29:39 -07:00
Megan Marsh 998ef4053f parse checksum file so that we can use the checksums inside in the vmware-esxi builder stepuploadiso 2019-06-28 14:35:43 -07:00
Megan Marsh 88d589cc88 enable smb share double backslash pathing too 2019-06-26 13:43:05 -07:00
Megan Marsh 12471a8b06 use file getter for smb shares 2019-06-26 13:21:49 -07:00
Adrien Delorme 735b34e01f Document the virtualbox-iso builder using partials 2019-06-19 17:37:22 +02:00
Adrien Delorme 4c1abf828c
Merge branch 'master' into scrape_doc_to_builder_struct_config 2019-06-19 11:21:06 +02:00
Megan Marsh 8d25cc578f
Merge pull request #7746 from hashicorp/fix_7671
Abort hyperv build if there's a name collision
2019-06-14 10:58:22 -07:00
Adrien Delorme daa9f9d34e Merge remote-tracking branch 'origin/master' into scrape_doc_to_builder_struct_config 2019-06-14 15:17:56 +02:00
Adrien Delorme 425ad1c67e generate Shutdown command docs from strutc & use in hyperv 2019-06-14 12:43:31 +02:00
Adrien Delorme c11ef90cb6 use interpolate.NewContext() instead of testConfigTemplate(t)
because it's what's happenning there
2019-06-14 12:17:28 +02:00
Adrien Delorme 926c8bbaa6 refactor ShutdownConfig into a single struct 2019-06-14 12:17:28 +02:00
Adrien Delorme 24fad50b00 hyperv-iso: document boot config, http & floppy from partials 2019-06-14 12:17:27 +02:00
Adrien Delorme 3bb8c92902 qemu: document boot command from struct 2019-06-14 12:17:27 +02:00
Adrien Delorme b48d22b43b qemu: document FloppyConfig from struct 2019-06-14 11:52:38 +02:00
Adrien Delorme 3b66cac617 document HTTPConfig from struct 2019-06-14 11:52:38 +02:00
Megan Marsh 2e821da84b check to make sure a vm-name isn't already in use before trying to launch a vm with said name. 2019-06-13 14:09:45 -07:00
Adrien Delorme dbfadc0eea generate struct markdown from common/iso_config.go 2019-06-12 16:02:49 +02:00