Lucas Bajolet
962ccdfc80
packer: address gosimple lint errors
2024-07-18 10:51:17 -04:00
Lucas Bajolet
e8d3a55b5f
packer: address errcheck lint errors
...
In a couple places in the codebase we didn't check the errors from
functions we execute.
In some cases this is harmless (or at least ignorable), but others may
need to log what went wrong, so for all the reported occurrences we
either ignore explicitly or handle the error with a log.
2024-07-18 10:51:17 -04:00
IAMDAVID0920
d625694a88
refactor: remove deprecated InitializePluginVersion, replace with NewPluginVersion
2024-06-03 09:37:30 -04:00
guoguangwu
7eb6a45cd4
chore: remove refs to deprecated io/ioutil
...
Signed-off-by: guoguangwu <guoguangwu@magic-shield.com>
2023-09-26 11:13:31 -04:00
hashicorp-copywrite[bot]
19055df3ec
[COMPLIANCE] License changes ( #12568 )
...
* Updating the license from MPL to Business Source License
Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog , FAQ at https://hashi.co/license-faq , and details of the license at www.hashicorp.com/bsl.
* Update copyright file headers to BUSL-1.1
---------
Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
2023-08-10 15:53:29 -07:00
hashicorp-copywrite[bot]
b7df3ca36f
[COMPLIANCE] Add Copyright and License Headers ( #12254 )
...
Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
2023-03-02 15:37:05 -05:00
Lucas Bajolet
c99b300e3a
Add support for Env in remote shell provisioners ( #11819 )
...
* provisioner/shell: add support for Env variables
As mentioned in issue #11670 , the Shell provider did not support Env
variable declarations in the HCL templates.
This commit adds the capability to the code.
* provisioner/powershell: add support for Env vars
* provisioner/windows-shell: support Env variables
2022-05-31 09:49:38 -04:00
Adrien Delorme
0362a3ec10
all shells: Pass env vars through a key value store ( #11569 )
...
* allowing to set shell env vars from a key/value map.
* tests
This new map will work alongside the `environment_vars` but it allows using a
datasource value seamlessly. At validation, and because `environment_vars` was
an array of strings containing `KEY=value`, using datsources would not work,
because these values are not known yet and would evaluate to `<unknown>`. With
this, the value and the key can be unknown and will validate correctly for
datasources.
2022-02-16 12:05:44 +01:00
Adrien Delorme
87ba7258b3
Use packer-sdc in packer + remove mapstructure-to-hcl2 & struct-markdown ( #10913 )
...
* start using `go:generate packer-sdc struct-markdown`
* Update Makefile
remove @go install ./cmd/struct-markdown
* run go generate for struct-markdown
* use //go:generate packer-sdc mapstructure-to-hcl2
* run go generate for mapstructure-to-hcl2
* remove struct-markdown and mapstructure-to-hcl2
* vendor vendors
2021-04-16 11:52:03 +02:00
Megan Marsh
88b7b0e14a
remove sdk
2020-12-17 13:29:25 -08:00
Megan Marsh
5f34bbd56e
add extra line before package declaration so this line does not become the synopsis of a package for godoc
2020-12-16 15:14:43 -08:00
Megan Marsh
76177b50ce
Refactor provisioner acceptance tests to shell directly out to Packer rather than import the core. Modify test case formatting to more closely reflect the builder test cases.
2020-12-07 15:45:16 -08:00
Megan Marsh
8f51a8bfae
move provisioner acceptance tests into sdk alongside builder acceptance tests. Reorganize slightly to make sure no import cycles of doom get formed
2020-12-03 14:22:18 -08:00
Megan Marsh
5576bb5caa
move packer config constants next to the packer config
2020-12-03 10:17:35 -08:00
Megan Marsh
be5763ec41
move provisioner interface into sdk
2020-12-01 14:25:14 -08:00
Megan Marsh
d5971ca25e
fix tests by moving mock hooks and communicators, and BasicUi definition, into SDK
2020-11-30 14:30:30 -08:00
Megan Marsh
56a45b04ab
Move hook and communicator definitions to packer-plugin-sdk
2020-11-30 14:30:30 -08:00
Megan Marsh
c70870cb83
move multierror and multierrorappend into sdk
2020-11-30 14:29:06 -08:00
Megan Marsh
001886670d
move Ui definition into the packer plugin sdk.
2020-11-30 14:26:54 -08:00
Megan Marsh
f8f1ebf0c7
move version and useragent definitions into sdk
2020-11-18 11:42:02 -08:00
Megan Marsh
9e47696dff
move helper/config to bundle with the other template definitions
2020-11-18 10:34:59 -08:00
Megan Marsh
3f6deb8828
move multistep into the plugin sdk
2020-11-17 16:31:03 -08:00
Megan Marsh
7d658149ea
update tests and website and generated partials to reflect new package format
2020-11-17 10:36:01 -08:00
Megan Marsh
1ffc358ada
move tmp helper func into packer-plugin-sdk
2020-11-16 15:13:08 -08:00
Megan Marsh
c4d0c5505a
fix tests
...
regenerate code
regenerate code, revendor
fix website
2020-11-13 15:00:12 -08:00
Megan Marsh
e04eaa89e6
move steps and step configs from packer/common to packer/common/commonsteps
2020-11-13 11:15:04 -08:00
Megan Marsh
6402362018
create packer-plugin-sdk directory and begin moving the relevant folders into it.
2020-11-13 10:47:36 -08:00
Megan Marsh
46cf8a1602
add all provisioner version files
2020-11-10 15:01:07 -08:00
Megan Marsh
8ecd16db81
regenerate code
2020-11-10 08:16:59 -08:00
Megan Marsh
c0ce8a9414
rework fixer deprecation code so we know what plugins they relate to
2020-10-21 15:28:59 -07: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
Sylvia Moss
1c30a71d09
Replace file shared state by statebag ( #9238 )
2020-05-19 11:49:48 +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
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
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
Sylvia Moss
665330de92
Write generic Builder-Provisioner acceptance test logic ( #8963 )
2020-04-03 18:17:09 +02: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
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
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