1
0
mirror of https://github.com/hashicorp/packer.git synced 2026-02-06 15:45:19 +01:00
Commit Graph

34 Commits

Author SHA1 Message Date
anshulSharma
e8d5ddb38a formatting multiple hcl files (#13362)
* formatting multiple hcl files

* recursive formating

* test case fixing

* test case fix

* removed not required code

* existing test code fix

* go formatting

* more test cases for new cases

* doc changes

* added additional check on error message in negative test case
2025-05-02 10:16:00 +05:30
Tanmay Jain
cceac7f462 UPDATE: Removing the UseSequentialEvaluation flag from Fix subcommand 2025-03-11 16:52:48 -04:00
Tanmay Jain
0e8668eb5f BUG: Fixed Packer Console's UseSequentialEval flag 2025-03-11 16:52:48 -04:00
Lucas Bajolet
cd74430e0c command: add use-sequential options for commands
For all the commands that call Initialise, we introduce a new flag:
UseSequential.

This disables DAG scheduling for evaluating datasources and locals as a
fallback to the newly introduced DAG scheduling approach.

`hcl2_upgrade` is a special case here, as the template is always JSON,
there cannot be any datasource, so the DAG in this case becomes
meaningless, and is not integrated in this code path.
2024-10-29 16:10:29 -04:00
Devashish
aa6c5f8405 feat: Phase 2 Extension of Build Metadata (#13092) 2024-07-22 23:08:14 +05:30
Wilken Rivera
bd0423d793 Add ignore-prerelease-flag to command help text 2024-03-12 13:19:21 -04:00
Lucas Bajolet
b5848b9913 command: add --release-only flag to validate/build
Since we added the capability for the plugin discovery to ignore
installed pre-releases of plugins, we give that capacity to the validate
and build commands, through a new command-line flag: release-only.
2024-03-01 09:04:15 -05:00
Lucas Bajolet
a2d9c9dce4 command: add --force option to init/install
The --force option for packer init and packer plugins install enforces
installation of a plugin, even if it is already locally installed.

This will become useful if for some reason a pre-existing plugin
binary/version is already installed, and we want to overwrite it.
2023-12-04 16:34:31 -05: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
bb2384c56a command/validate: add option to eval datasources
When packer validate is invoked, it does not try to evaluate the
datasources before attempting to decide if the template is valid.

In many cases, this works, but sometimes it will fail as the value is
unknown by the validation code.

Since the validation code for all the elements of a Packer template is
left to be implemented by plugins, we cannot rely on checking for
unknown values everywhere, especially since the unknown references are
replaced automatically by a value of the right type for the
configuration expected.

So, in order for such configurations to be validable, we add an extra
option to packer validate, that will let users evaluate the datasources
from a template.
2022-11-17 09:29:55 -05:00
Wilken Rivera
57cbe4e203 core: Update validation options for undeclared variables (#12104)
* Update validation options for undeclared variables

In an effort to help users move from JSON to HCL2 templates the support for
variable definitions files are being updated to ignore undeclared
variable warnings on build execution. For legacy JSON templates builds no
warnings are displayed when var-files contain undeclared variables.

Since preferred mode HCL2 templates is to be explicit with variable
declarations - they must be declared to be used - validation for
undeclared variables still warns when running `packer validate`. A new
flag has been added to the validate command that can be used to disable
undeclared variable warnings.

* Update validation test for unused variables

Example Run
```
~>  go run . validate -no-warn-undeclared-var -var-file
command/test-fixtures/validate/var-file-tests/undeclared.pkrvars.hcl
command/test-fixtures/validate/var-file-tests/basic.pkr.hcl
The configuration is valid.

~>  go run . validate -var-file
command/test-fixtures/validate/var-file-tests/undeclared.pkrvars.hcl
command/test-fixtures/validate/var-file-tests/basic.pkr.hcl
Warning: Undefined variable

The variable "unused" was set but was not declared as an input variable.
To declare variable "unused" place this block in one of your .pkr.hcl
files,
such as variables.pkr.hcl

variable "unused" {
  type    = string
  default = null

}

The configuration is valid.

~>  go run . build -var-file
command/test-fixtures/validate/var-file-tests/undeclared.pkrvars.hcl
command/test-fixtures/validate/var-file-tests/basic.pkr.hcl
file.chocolate: output will be in this color.

Build 'file.chocolate' finished after 744 microseconds.

==> Wait completed after 798 microseconds

==> Builds finished. The artifacts of successful builds are:
--> file.chocolate: Stored file: chocolate.txt
```

* Rename Strict field to WarnOnUndeclaredVar

The field name Strict is a bit vague since it is only used for
checking against undeclared variables within a var-file definition.
To mitigate against potential overloading of this field it is
being renamed to be more explicit on its usage.

* command/build: Add warn-on-undeclared-var flag

Now that the default behaviour is to not display warnings for undeclared variables
an optional flag has been added to toggle the old behaviour.

```
~>  go run . build -warn-on-undeclared-var -var-file command/test-fixtures/validate/var-file-tests/undeclared.pkrvars.hcl command/test-fixtures/validate/var-file-tests/basic.pkr.hcl
Warning: Undefined variable

The variable "unused" was set but was not declared as an input variable.
To declare variable "unused" place this block in one of your .pkr.hcl files,
such as variables.pkr.hcl

variable "unused" {
  type    = string
  default = null

}

file.chocolate: output will be in this color.

Build 'file.chocolate' finished after 762 microseconds.

==> Wait completed after 799 microseconds

==> Builds finished. The artifacts of successful builds are:
--> file.chocolate: Stored file: chocolate.txt
```
2022-11-14 17:06:45 -05:00
Adrien Delorme
9f4a1281dd Add packer plugins command and subcommands to interact with plugins (#11553)
* add basic docs for plugins command

* refactor docs

Co-Authored-By: Wilken Rivera <1749304+nywilken@users.noreply.github.com>

* add plugins command

* add plugins subcommands

they do nothing for now

* add plugins installed command + tests

* add plugins install command

* add remove plugin command

* better docs for the plugins install command

* remove duplicate content

* better output for installed plugins

* add plugins required command

* Update plugins_install.go

* add newline after `Usage:`

* Update plugins_remove.go

* Update plugins_required.go

* Update plugins_remove.go

* Update plugins_installed.go

* Update plugins_install.go

* add docs

* Update plugins_install.go

* fix typos

* Update plugins_test.go

* fix typos

Co-Authored-By: Wilken Rivera <1749304+nywilken@users.noreply.github.com>

* Update core_wrapper.go

Co-Authored-By: Wilken Rivera <1749304+nywilken@users.noreply.github.com>

* Update website/content/docs/commands/plugins/remove.mdx

Co-authored-by: Wilken Rivera <wilken@hashicorp.com>

* Update website/content/docs/commands/plugins/required.mdx

Co-authored-by: Wilken Rivera <wilken@hashicorp.com>

* Update website/content/docs/commands/plugins/required.mdx

Co-authored-by: Wilken Rivera <wilken@hashicorp.com>

* Update plugins_required.go

* Update install.mdx

* Update required.mdx

* plugins requirement, warn when no plugin was found

* Update website/content/docs/commands/plugins/required.mdx

Co-authored-by: Wilken Rivera <wilken@hashicorp.com>

Co-authored-by: Wilken Rivera <1749304+nywilken@users.noreply.github.com>
Co-authored-by: Wilken Rivera <wilken@hashicorp.com>
2022-02-10 16:53:50 -05:00
Adrien Delorme
4e22147909 Merge remote-tracking branch 'origin/master' into pr/teddylear/10457 2021-03-12 10:38:04 +01:00
sylviamoss
855ba9775a add docs 2021-02-12 15:31:13 +01:00
sylviamoss
76e3d57cae add with-annotation flag to hcl2_upgrade 2021-02-12 15:18:53 +01:00
teddylear
d85286e228 Merging in master 2021-02-10 17:44:11 -05:00
teddylear
261abe0cae Setting recursive fmt to false, updatting recursive fmt test to validate
formatted files
2021-02-06 18:02:26 -05:00
teddylear
ab4b3a8465 Adding recursive flag to formatter to format subdirectories 2021-02-06 18:02:23 -05:00
Adrien Delorme
ed091163be HCL2 Parse packer.required_plugins block + packer init (#10304)
This adds the new `required_plugins` block to be nested under the packer block.

Example:
```hcl
packer {
  required_plugins {
    aws = {
      version = ">= 2.7.0"
      source = "azr/aws"
    }
    azure = ">= 2.7.0"
  }
}
```

For example on darwin_amd64 Packer will install those under :
* "${PACKER_HOME_DIR}/plugin/github.com/azr/amazon/packer-plugin-amazon_2.7.0_x5.0_darwin_amd64"
* "${PACKER_HOME_DIR}/plugin/github.com/hashicorp/azure/packer-plugin-azure_2.7.0_x5.0_darwin_amd64_x5"

+ docs
+ tests
2021-02-02 18:05:04 +01:00
Megan Marsh
6a1a22151c move the various flag packages from helper to command, since command is the only package that uses them. 2020-11-16 14:23:35 -08:00
Wilken Rivera
acabc1c1aa Add packer fmt command (#10225)
* Add packer fmt command

This change adds a new command that allows users to format one or more
HCL2 Packer configuration template files.

Related to: #9174

* command/fmt: Add check flag

Packer's fmt command now supports a check flag that will output the name
of any file that would be changed by the HCL2 formatting engine. The
check flag is mutually exclusive with the write flag and will only check
if formatting is needed.

The update write flag will now overwrite the source files with the newly
formatted HCL2 source unless the `-write=false` or `-check` is passed at
the command line.

* Returns a diagnostic error if Format is unable to show a diff - equivalent to `terraform fmt`
* Updates testing to run against #Format and not the private methods of the HCL2Formatter; fixes ShowDiff test failure on Windows
* Updates comments for exported functions

* Add docs for fmt command
2020-11-11 11:49:39 -05:00
Adrien Delorme
5ba134ac5b JSON to HCL2 (minimal best-effort) transpiler (#9659)
hcl2_upgrade transforms a JSON build-file in a HCL2 build-file.
This starts a validated Packer core and from that core we generate an HCL 'block' per plugin/configuration. So for a builder, a provisioner, a post-processor or a variable. The contents of each block is just transformed as is and basically all fields are HCL2-ified.
A generated field can be valid in JSON but invalid on HCL2; for example JSON templating (in mapstructure) allows to set arrays of strings - like `x = ["a", "b"]` - with single strings - like `x="a"` -, HCL does not allow this.
Since JSON does not make the distinction between variables and locals, everything will be a variable. So variables that use other variables will not work.
hcl2_upgrade tries to transform go templating interpolation calls to HCL2 calls when possible, leaving the go templating calls like they are in case it cannot.

Work:
* transpiler
* tests
* update hcl v2 library so that output looks great.
* update docs
2020-08-25 10:51:43 +02:00
Adrien Delorme
51d02f8c2d hcl2: inspect command 2020-06-23 11:58:57 +02:00
Moss
4f26534072 add on-error flag option to run cleanup provisioner 2020-06-16 15:34:00 +02:00
Adrien Delorme
bac9c74447 packer console for HCL2 (#9359) 2020-06-05 17:23:54 +02:00
Adrien Delorme
7ca0a80a86 remove Ui from command.MetaArgs 2020-05-12 12:14:30 +02:00
Adrien Delorme
77297e49e9 Update cli.go 2020-05-12 12:07:02 +02:00
Adrien Delorme
efcc6af06c fix tests 2020-05-08 17:46:33 +02:00
Adrien Delorme
a93a45e4d3 more fixes to refactor 2020-05-08 17:15:00 +02:00
Adrien Delorme
42a05e1e80 more refactoring 2020-05-08 16:41:47 +02:00
Adrien Delorme
2f63e4e79d refactor term interrupts & have RunContext take a conf struct now 2020-05-08 12:05:14 +02:00
Adrien Delorme
5290beb23e Update cli.go 2020-05-08 11:59:10 +02:00
Adrien Delorme
a5ab87ca44 add scaffolding for the new packer command layout 2020-05-07 17:52:49 +02:00