Commit Graph

849 Commits

Author SHA1 Message Date
Matt Kotsenas fe55494207
Add `debug_mode` to PowerShell provisioner (#8996) 2020-04-17 11:39:39 +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
Megan Marsh 73c349d09c
Merge pull request #8908 from hashicorp/fix_4795
provisioner/powershell: Add cleanup step to remove any temporarily created scripts
2020-04-09 08:56:19 -07:00
Lars Lehtonen 49f28c9439
provisioner/powershell: fix dropped error
provisioner/powershell: improve error message
2020-04-08 10:04:08 -07:00
Wilken Rivera 4a46d6ff7b docs/provisioner/powershell: Add documentation for `skip_clean` option 2020-04-08 10:23:15 -04:00
Wilken Rivera fe721d8e11 test/provisioner/powershell: Add acceptance test for powershell provisioner cleanup
Passing Tests
```
--- PASS: TestAccPowershellProvisioner_basic (282.02s)
--- PASS: TestAccPowershellProvisioner_basic/testing_amazon-ebs_builder_against_powershell_provisioner (282.01s)                               PASS
ok      github.com/hashicorp/packer/provisioner/powershell 282.046s
```

Failing tests on master
```
2020/04/08 09:59:34 Uploading file to 'c:/Windows/Temp/script.bat'
2020/04/08 09:59:36 [INFO] starting remote command: set "PACKER_BUILDER_TYPE=amazon-ebs" && set "PACKER_BUILD_NAME=amazon-ebs"
&& "c:/Windows/Temp/script.bat"
2020/04/08 09:59:36 ui:     amazon-ebs:
2020/04/08 09:59:36 ui:     amazon-ebs: C:\Users\Administrator>dir C:\Windows\Temp\packer-*.ps1
2020/04/08 09:59:36 ui:     amazon-ebs:  Volume in drive C has no label.
2020/04/08 09:59:36 [INFO] command 'set "PACKER_BUILDER_TYPE=amazon-ebs"
&& set "PACKER_BUILD_NAME=amazon-ebs" && "c:/Windows/Temp/script.bat"' exited with code: 0
2020/04/08 09:59:36 ui:     amazon-ebs:  Volume Serial Number is 46CA-4083
2020/04/08 09:59:36 ui:     amazon-ebs:
2020/04/08 09:59:36 ui:     amazon-ebs:  Directory of C:\Windows\Temp
2020/04/08 09:59:36 ui:     amazon-ebs:
2020/04/08 09:59:36 ui:     amazon-ebs: 04/08/2020  01:59 PM 102 packer-acc-test-script-test.ps1
2020/04/08 09:59:36 ui:     amazon-ebs: 04/08/2020  01:59 PM 76 packer-acc-test-vars.ps1
2020/04/08 09:59:36 ui:     amazon-ebs:                2 File(s) 178 bytes
2020/04/08 09:59:36 ui:     amazon-ebs:                0 Dir(s) 9,735,806,976 bytes free
2020/04/08 09:59:36 ui: ==> amazon-ebs: Provisioning step had errors: Running the cleanup provisioner, if present...
2020/04/08 09:59:36 ui: ==> amazon-ebs: Terminating the source AWS instance...
2020/04/08 10:00:09 ui: ==> amazon-ebs: Cleaning up any extra volumes...
2020/04/08 10:00:09 ui: ==> amazon-ebs: No volumes to clean up, skipping
2020/04/08 10:00:09 ui: ==> amazon-ebs: Deleting temporary security group...
2020/04/08 10:00:10 ui: ==> amazon-ebs: Deleting temporary keypair...
2020/04/08 10:00:11 ui error: Build 'amazon-ebs' errored: Script exited
with non-zero exit status: 0.Allowed exit codes are: [1]
2020/04/08 10:00:11 machine readable: error-count []string{"1"}
2020/04/08 10:00:11 ui error:
==> Some builds didn't complete successfully and had errors:
2020/04/08 10:00:11 machine readable: amazon-ebs,error []string{"Script
exited with non-zero exit status: 0.Allowed exit codes are: [1]"}
2020/04/08 10:00:11 ui error: --> amazon-ebs: Script exited with
non-zero exit status: 0.Allowed exit codes are: [1]
```

test: Fix windows-shell command
2020-04-08 10:05:54 -04:00
Wilken Rivera 91c8afda8e provisioner/elevated: Add cleanup logic to remove elevated user scheduled task artifacts 2020-04-08 00:23:40 -04:00
Wilken Rivera 11db6014fa provisioner/powershell: Update remote clean up logic
* Add retry logic so that the provisioner will retry if it fails to upload/execute because of some restart provisioner step
* Add a testConfigWithSkipClean for testing that the provisioner executes the correct commands
* Add a test case for toggling the "skip_clean" config option
2020-04-08 00:23:40 -04:00
Wilken Rivera f6a61e2511 provisioner/powershell: Add post clean up step to remove temp script files 2020-04-08 00:23:40 -04:00
Wilken Rivera 1eee0bca5f
Merge pull request #9011 from hashicorp/powershell-acceptance-test
provisioner/powershell: Add basic Powershell provisioner acceptance tests
2020-04-07 05:40:26 -04:00
Megan Marsh bdcc95f989
fix execution policy parser to not interfere with legit integers, and add tests (#8997) 2020-04-07 10:32:58 +02:00
Lars Lehtonen 78bb742aa5
provisioner/shell: fix dropped test error 2020-04-06 14:30:19 -07:00
Wilken Rivera 360f81b030 tests/provisioners: Add TestProvsionerPreCheck function
This function can be used to check if a Provisioner has been marked for testing within the ACC_TEST_PROVISIONERS environment variable.

While testing I found that the shell acceptance test were also running when trying to run powershell tests.

Before change
```
⇶  ACC_TEST_BUILDERS=amazon-ebs ACC_TEST_PROVISIONERS=powershell go test -v ./provisioner/shell/... -timeout=1h

=== RUN
TestShellProvisioner/testing_amazon-ebs_builder_against_shell_provisioner
2020/04/06 15:18:12 ui: amazon-ebs: output will be in this color.
2020/04/06 15:18:12 ui:
2020/04/06 15:18:12 Build debug mode: false
2020/04/06 15:18:12 Force build: false
2020/04/06 15:18:12 On error:
2020/04/06 15:18:12 Preparing build: amazon-ebs
2020/04/06 15:18:12 Waiting on builds to complete...
2020/04/06 15:18:12 Starting build run: amazon-ebs
2020/04/06 15:18:12 Running builder: amazon-ebs
```

After changes
```
⇶  ACC_TEST_BUILDERS=amazon-ebs ACC_TEST_PROVISIONERS=powershell go test -v ./provisioner/shell/... -timeout=1h
--- SKIP: TestShellProvisioner (0.00s)
    provisioners.go:88: Provisioner "shell" not defined in ACC_TEST_PROVISIONERS
```
2020-04-06 16:52:24 -04:00
Moss 185deeeb38 Fix provisioner acc-test builder and provisioner store 2020-04-06 16:52:24 -04:00
Wilken Rivera b183c5498f provisioner/powershell: Add basic Powershell provisioner acceptance tests
* Modifies the amazon-ebs builder with a windows build configuration

```
⇶  ACC_TEST_BUILDERS=amazon-ebs ACC_TEST_PROVISIONERS=powershell go test -v ./provisioner/powershell/... -run=TestPowershellProvisioner_Inline
--- PASS: TestPowershellProvisioner_Inline (256.50s)
--- PASS: TestPowershellProvisioner_Inline/testing_amazon-ebs_builder_against_powershell_provisioner (256.50s)
PASS
ok      github.com/hashicorp/packer/provisioner/powershell 256.525s
```
2020-04-06 16:52:05 -04:00
Megan Marsh b804e5a8f5
Merge pull request #8987 from VaijanathB/azure-devtestlabs-take2
Building Azure devtestlabs Images using Packer - update
2020-04-03 11:14:31 -07:00
Megan Marsh 8840b4a830
Merge pull request #8625 from hashicorp/remove_ansible_proxy
Remove ansible proxy
2020-04-03 09:23:10 -07:00
Sylvia Moss 665330de92
Write generic Builder-Provisioner acceptance test logic (#8963) 2020-04-03 18:17:09 +02:00
Vaijanath Angadihiremath b7d85b8a23 Added acceptance tests for DTL. Fixed couple of issues with DTL root resource group not set to new directory 2020-04-02 17:23:21 -07:00
Vaijanath Angadihiremath 69015b1870 Fixing the linting errors 2020-04-02 17:22:39 -07:00
Vaijanath Angadihiremath e726902116 Fixing the latest changes from the merge 2020-04-02 17:16:31 -07:00
Vaijanath Angadihiremath 645cdf1a59 Updating the modules to include update to autorest 12.4 2020-04-02 17:13:36 -07:00
Megan Marsh b66e49223d extract the building of command args into a testable helper function 2020-04-01 16:07:14 -07:00
Megan Marsh 91906b688c regenerate code 2020-04-01 11:37:25 -07:00
Megan Marsh 73c87044fd fix tests 2020-04-01 11:31:48 -07:00
Megan Marsh 64b706983e docs and cleanup 2020-04-01 11:31:48 -07:00
Megan Marsh d45ffe73d0 fix default ssh-extra-args flag 2020-04-01 11:31:48 -07:00
Megan Marsh d57809bcda pass ansible_password on command line instead of inside inventory file 2020-04-01 11:31:48 -07:00
Megan Marsh eda9ce70e7 update tests 2020-04-01 11:31:48 -07:00
Megan Marsh 9a40403433 clean up tests 2020-04-01 11:31:48 -07:00
Megan Marsh e155d2a1c8 add mock so we can test full provision flow 2020-04-01 11:31:48 -07:00
Megan Marsh 6c756a7b31 fix tests 2020-04-01 11:31:48 -07:00
Megan Marsh 19d49f8b78 templatize inventory files; implement inventory for winrm 2020-04-01 11:31:48 -07:00
Megan Marsh ca5814ab74 move proxy behind feature flag 2020-04-01 11:31:48 -07:00
Adrien Delorme b94937c05c
Update provisioner_test.go (#8900) 2020-03-18 11:51:54 +01:00
Adrien Delorme 569c802630 Update provisioner_test.go
fix TestProvisioner_RemoteFileDefaultsToScriptnnnn
2020-03-17 17:10:43 +01:00
Adrien Delorme f1c0a9cdbd see what's wrong with that weird test 2020-03-17 17:02:18 +01:00
Moss 112d4daa3d Fix linter 2020-03-13 17:52:33 +01:00
Moss 5a8c628880 Add acc test validation to avoid running with unit tests 2020-03-13 17:50:05 +01:00
Moss 3f49b7c66e Fix linter 2020-03-13 17:17:42 +01:00
Moss 0cc1092222 Fix format 2020-03-13 17:11:13 +01:00
Moss 2ca6804827 Move shell prov acc test to the same folder 2020-03-13 17:10:51 +01:00
Moss 7fbbbffd5c Interpolate file provisioner and add integration tests 2020-03-13 16:17:40 +01:00
Moss 6c06a2a048 Fix format 2020-03-12 17:59:34 +01:00
Moss a3740bb9be Interpolate shell inline config 2020-03-12 17:54:31 +01:00
Wilken Rivera e1a46ec293
Fix gosimple S1025 linting errors (#8838)
Remove unneeded use of fmt.Sprintf for variables that are already strings.
2020-03-04 15:31:30 -05:00
Sylvia Moss ce674ff272
Add exclude mapstructure tag to exclude from hcl2spec struct (#8785) 2020-03-03 17:13:39 +01:00
Paschalis Tsilias beca6de71b Add packer.ExpandUser() function to support tilde in usage of config.ValidationKeyPath (#8657) 2020-01-28 14:33:42 +01:00
nywilken b80882f3b8 provisioner/shell: Fix envVarFile clean up issue
This change ensures the deletion of the external envVarFile (use_env_var_file = true) occurs after all script files have been executed and deleted.

Build results before change
```
> packer build build.pkr.hcl                                                                                                                                                             [~0]
docker: output will be in this color.

==> docker: Creating a temporary directory for sharing data...
==> docker: Pulling Docker image: ubuntu:bionic
    docker: bionic: Pulling from library/ubuntu
    docker: Digest: sha256:8d31dad0c58f552e890d68bbfb735588b6b820a46e459672d96e585871acc110
    docker: Status: Image is up to date for ubuntu:bionic
    docker: docker.io/library/ubuntu:bionic
==> docker: Starting docker container...
    docker: Run command: docker run -v /home/wilken/.packer.d/tmp476880774:/packer-files -d -i -t --entrypoint=/bin/sh -- ubuntu:bionic
    docker: Container ID: 812069b4d70746a6d4592a8f75c06867c6774b8b0bd81ade76eae7926a30f64b
==> docker: Using docker communicator to connect: 172.17.0.2
==> docker: Provisioning with shell script: sample.sh
    docker: Sample Script
    docker: wilken is NotForSale!
==> docker: Provisioning with shell script: foobar.sh
==> docker: /bin/sh: 1: .: Can't open /tmp/varfile_2555.sh
==> docker: Provisioning step had errors: Running the cleanup provisioner, if present...
==> docker: Killing the container: 812069b4d70746a6d4592a8f75c06867c6774b8b0bd81ade76eae7926a30f64b
Build 'docker' errored: Script exited with non-zero exit status: 2.Allowed exit codes are: [0]

==> Some builds didn't complete successfully and had errors:
--> docker: Script exited with non-zero exit status: 2.Allowed exit codes are: [0]

==> Builds finished but no artifacts were created.
```

Build results after change
```
> packer build build.pkr.hcl
docker: output will be in this color.

==> docker: Creating a temporary directory for sharing data...
==> docker: Pulling Docker image: ubuntu:bionic
    docker: bionic: Pulling from library/ubuntu
    docker: Digest: sha256:8d31dad0c58f552e890d68bbfb735588b6b820a46e459672d96e585871acc110
    docker: Status: Image is up to date for ubuntu:bionic
    docker: docker.io/library/ubuntu:bionic
==> docker: Starting docker container...
    docker: Run command: docker run -v /home/wilken/.packer.d/tmp819845000:/packer-files -d -i -t --entrypoint=/bin/sh -- ubuntu:bionic
    docker: Container ID: d8ed9100ff5017379bfc0d80703b2b2d10c4104941663aa5ddbbf18f6dcf74a5
==> docker: Using docker communicator to connect: 172.17.0.2
==> docker: Provisioning with shell script: sample.sh
    docker: Sample Script
    docker: wilken is NotForSale!
==> docker: Provisioning with shell script: foobar.sh
    docker: FooBar Script
    docker: wilken is NotForSale!
==> docker: Committing the container
    docker: Image ID: sha256:a412e43f134431f2049a7d06d5d691aad3717d91dd2ee5e2575e05b89384a4b3
==> docker: Killing the container: d8ed9100ff5017379bfc0d80703b2b2d10c4104941663aa5ddbbf18f6dcf74a5
Build 'docker' finished.

==> Builds finished. The artifacts of successful builds are:
--> docker: Imported Docker image: sha256:a412e43f134431f2049a7d06d5d691aad3717d91dd2ee5e2575e05b89384a4b3
```
2020-01-23 14:59:36 -05:00