Commit Graph

54 Commits

Author SHA1 Message Date
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 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 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 f4c3501af5 pass struct of generated data into provision() call 2019-12-11 15:43:38 -08:00
Megan Marsh ad34a4551b provisioner/windows-restart: revert sleep hack now that we've fixed the underlying bug in #8369 (#8377) 2019-11-18 10:48:33 +01:00
Adrien Delorme 078ba7c8c3 commit old code generation tool
for history
2019-10-15 12:56:42 +02:00
Adrien Delorme d72040f4fa move retry code into the common/retry pkg and make retry context aware 2019-04-09 17:46:38 +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 82c4b76639 [Builder|Build|PostProcessor|Provisioner|Hook]Server: context cancel using a RPC cancel method 2019-04-03 15:55:55 +02:00
Adrien Delorme c7ce4d598e change Provisioner to be passed a context for cancellation 2019-04-03 15:55:54 +02:00
Megan Marsh d5854a9574 add option to test registry for certain keys to make sure windows is done with a reboot cycle 2018-12-12 12:52:14 -08:00
Matt Dainty 0192289d68 Drop exit code 1717 2018-12-07 09:45:50 +00:00
Matt Dainty 5fed453047 Ignore an already-scheduled reboot
If the previous provisioner already scheduled a reboot don't error we
can't schedule another one.
2018-12-05 15:43:22 +00:00
Poddo 72391f8f4d
Update provisioner.go
Remove extra break statement that made it's way into the "reboot pending" loop when some logic was rearranged in 9fa47f5dad (diff-8bb0a16231863cd1487dd9a3d3792565)
2018-10-03 00:54:31 -05:00
Megan Marsh c51cd751d1 go back to using StartWithUI to prevent weird hangs during windows reboot 2018-08-23 16:15:50 -07:00
Megan Marsh 9fa47f5dad make windows restart provisioner work with ssh communicator 2018-08-21 11:45:18 -07:00
Megan Marsh 974d9974fe add workaround for azure bug. 2018-02-07 11:34:18 -08:00
Megan Marsh 19c997cb0e revert to using UI becuase the remote command syntax breaks things on linux with vmware fusion. 2017-12-07 09:08:12 -08:00
Megan Marsh c3cb7fe9f9 read from stderr so it doesnt lock up 2017-11-09 15:52:49 -08:00
Megan Marsh 9b1ae530c3 have separate stdout and stderr buffers 2017-11-09 15:35:28 -08:00
Megan Marsh 6019e41544 dont read stderr 2017-11-09 15:18:43 -08:00
Megan Marsh 73b6247fd2 remove unnecessary boolean operator 2017-11-09 15:04:25 -08:00
Megan Marsh e56a6dc9a0 add some comments 2017-11-09 14:55:12 -08:00
Megan Marsh a739623d9b don't pipe restarted stuff through the ui 2017-11-09 14:44:26 -08:00
Megan Marsh d71bc34dfc don't need this in a loop 2017-11-09 11:49:12 -08:00
Megan Marsh d81871171c make restart command work correctly even if user has their own check command 2017-11-07 15:01:02 -08:00
Megan Marsh 959db1ac16 add echo test to winrm connection. 2017-09-01 15:26:41 -07:00
Megan Marsh b1001264ed fix windows-restart tests 2017-08-24 14:30:15 -07:00
Megan Marsh b2923b4da6 check stdout to make sure echo command actually goes through before counting computer as fully restarted 2017-08-24 12:10:27 -07:00
Matthew Hooker b1f06bbebb
fix wording 2017-06-26 12:56:55 -07:00
Matthew Hooker 67e29e1eff
disambiguates windows-restart messages. 2017-06-21 10:51:23 -07:00
Matthew Hooker 81522dced0
move packer to hashicorp 2017-04-04 13:39:01 -07:00
Matthew Hooker 0149f679de
Print instead of Printf with no dynamic first variable. 2017-03-28 20:36:20 -07:00
Matthew Hooker 230079f73a
spell fixes 2017-03-28 20:36:19 -07:00
Marc Carmier 78ab21b42f Test error messages for restart_command and restart_timeout seems to be erroneous 2017-02-12 18:17:31 +01:00
Rickard von Essen 51a9a51699 Update winrm and winrmcp dependencies
Updated winrm and winrmcp dependencies. Relevant unit and acceptance tests passed successfully.

shell.Execute didn't return a Command object.

See f1bcf36a69/winrmcp/cp.go (L167) and 54ea5d0147/winrm/shell.go (L10-L22) respectively.

Closes #3763

Original patch by: Philipp Kosel <philipp.kosel@gmail.com>
2016-10-03 13:48:29 -07:00
Mark Peek 43cb854b3e Merge pull request #2568 from pecigonzalo/f-winrm-reboot
Add reboot checks before moving out of the reboot sequence for WinRM
2015-10-26 16:57:13 -07:00
Mark Peek 1aad5cf6d5 provisioner/windows-restart: remove race in test 2015-10-12 13:20:18 -07:00
Mark Peek d87b68efe8 Syncronize cancellation in windows-restart tests
Two windows-restart tests would timeout and fail due to the cancellation
thread firing before the cancel object was created. This change syncronizes
the start of the threads to prevent this from occurring.
2015-10-10 14:32:39 -07:00
Gonzalo Peci f01f62dc88 Add specific exit codes listed on https://msdn.microsoft.com/en-us/library/windows/desktop/ms681383(v=vs.85).aspx 2015-08-28 09:55:14 +12:00
Gonzalo Peci 8bd3e62853 Because the new functionality makes the ```waitForRestart()``` function run commands it modifies the value of ```comm.StartCmd.Command``` that is being checked, we need to implement the same workaround that is being used for the ```waitForCommunicator()``` function. This should make the test work again and retain functionality. 2015-08-28 09:54:59 +12:00
Gonzalo Peci 08359e409a Revert the shutdown command with new parameters as this will return proper exit codes. This will work in the same way as restart-computer -force when using ```shutdown /r /f /t 0```.
Note:The WinRM library does not return the exit code currently, this will be implemented on https://github.com/masterzen/winrm/pull/26
2015-08-28 09:54:39 +12:00
Gonzalo Peci 70083fc869 Add reboot checks before moving out of the reboot. 2015-08-28 09:54:24 +12:00
Chris Bednarski abb67fdd79 Fix govet issues 2015-08-05 19:41:29 -07:00
Mitchell Hashimoto 7c8e86c9c5 provisioner/*: fix interpolation context 2015-06-22 12:26:54 -07:00
Mitchell Hashimoto 59766067c0 provisioner/windows-restart: make test pass on slow machines 2015-06-19 06:13:51 +02:00
Mitchell Hashimoto b2609db395 provisioner/windows-restart: fix potential panic case 2015-06-17 18:22:27 +02:00