Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport of Document process for registering a plugin as a Packer Integration into stable-website #12745

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
157 commits
Select commit Hold shift + click to select a range
35c579a
CHANGELOG: update for 1.9.0 release
lbajolet-hashicorp May 30, 2023
f730bd6
changelog: update for release 1.9.0
lbajolet-hashicorp May 31, 2023
ac29a13
version: prepare for 1.10.0 releases
lbajolet-hashicorp May 31, 2023
3f4e49e
CHANGELOG: add advisory on multiproject support
lbajolet-hashicorp May 31, 2023
925cb5e
hcp: support HCP_PROJECT_ID environment variable
lbajolet-hashicorp Jun 1, 2023
571adf9
CHANGELOG: add changelog for v1.9.1
lbajolet-hashicorp Jun 1, 2023
2d5d78a
CHANGELOG: fix latest release version
lbajolet-hashicorp Jun 1, 2023
5f038ce
CHANGELOG: prepare for upcoming v1.9.2
lbajolet-hashicorp Jun 1, 2023
d563a3c
[COMPLIANCE] Add Copyright and License Headers
hashicorp-copywrite[bot] Jun 5, 2023
aeffaa7
docs: add a paragraph on fingerprint generation (#12464)
lbajolet-hashicorp Jun 15, 2023
ffa1e54
Delete check-legacy-links-format.yml (#12471)
Jun 16, 2023
f1c1e49
Fix executable directory path
nywilken May 11, 2023
f7a0df4
Reduce the number of nest plugin scans
nywilken May 11, 2023
4347e8c
Default to PuluginFolders is KnownPluginFolders is unset
nywilken May 24, 2023
18cc6ed
docs: move community tools to docs folder
dstaley Jun 23, 2023
8982d4f
Migrate external Parallels plugin to Parallels/packer-plugin-parallel…
Jul 3, 2023
9c85fc2
Update plugin loading documentation (#12485)
Jul 6, 2023
8beddcf
website: fix header on configure page
lbajolet-hashicorp Jul 12, 2023
0e3de18
fix: revise env var PACKER_PLUGIN_PATH
akkuman Jul 13, 2023
456bc23
hcl2template: only warn once for missing plugins
lbajolet-hashicorp Jul 17, 2023
2824320
packer: remove discoverExternalComponents
lbajolet-hashicorp Jul 11, 2023
a2930bd
packer: warn on bundled plugins usage
lbajolet-hashicorp Jul 11, 2023
b522edc
hcl2_upgrade: add required_plugins in out template
lbajolet-hashicorp Jul 14, 2023
6e76465
Makefile: remove mode-check target (#12505)
lbajolet-hashicorp Jul 18, 2023
5271c28
Add closing code block
garyng Jul 18, 2023
cc1e2fc
Prefix url with product slug
garyng Jul 18, 2023
58b193f
Use backtick to prevent html parsing
garyng Jul 19, 2023
0194d83
Result of tsccr-helper -log-level=info -pin-all-workflows . (#12507)
hashicorp-tsccr[bot] Jul 19, 2023
3c4a4f0
CHANGELOG: add changelog for Packer 1.9.2
lbajolet-hashicorp Jul 19, 2023
e3c20e3
CHANGELOG: prepare for 1.9.3
lbajolet-hashicorp Jul 19, 2023
02f1d50
build(deps-dev): bump word-wrap from 1.2.3 to 1.2.4 in /website
dependabot[bot] Jul 18, 2023
e9e4534
build(deps): bump tough-cookie from 4.0.0 to 4.1.3 in /website
dependabot[bot] Jul 8, 2023
739b2ac
docs: fix typo (#12493)
dunglas Jul 19, 2023
13ed8d9
Update github-script action REST calls
nywilken Jul 20, 2023
682f2e7
.github/workflows: Replace untrusted GHA in repo workflows (#12530)
Jul 21, 2023
2401add
Fix body attribute for github-script comment
nywilken Jul 24, 2023
a1957a1
[COMPLIANCE] Add Copyright and License Headers
hashicorp-copywrite[bot] Jul 24, 2023
74b5c2a
issue-comment-created: Add guard for labels
nywilken May 30, 2023
55decee
.github: fix issues-opened.yml workflow
lbajolet-hashicorp Jul 24, 2023
38101a6
hcp: Add support for project level service principals
nywilken Jul 19, 2023
60c66fd
Add additional validation for manually set project ids
nywilken Jul 20, 2023
d0198c8
packer: track bundled plugins usage on telemetry
lbajolet-hashicorp Jul 24, 2023
3512a17
command: change wording for init's postitional arg
lbajolet-hashicorp Jul 24, 2023
3922329
website: add usage notice to init
lbajolet-hashicorp Jul 24, 2023
5c9ab19
Result of tsccr-helper -log-level=info -pin-all-workflows .
hashicorp-tsccr[bot] Jul 27, 2023
d1aa103
workflows/jira: Fix syntax error for createComment
nywilken Jul 27, 2023
d3d3371
Update plugin loading for current directory
nywilken Jul 27, 2023
a96584f
Update plugin discover logic
nywilken Jul 27, 2023
848039d
Update plugin discover testing
nywilken Jul 28, 2023
99c79ec
Add build tags to skip amd64 tests on darwin/arm64 (#12549)
Aug 2, 2023
b29abbc
Dockerfile: remove trailing whitespaces
lbajolet-hashicorp Jul 20, 2023
ffe2776
README: fix link to CONTRIBUTING
lbajolet-hashicorp Jul 21, 2023
8387369
Dockerfile: add release-full target
lbajolet-hashicorp Jul 21, 2023
c6da777
workflows: add docker-full to build workflow
lbajolet-hashicorp Jul 21, 2023
55854f5
Makefile: only build dev version of binary/docker
lbajolet-hashicorp Jul 25, 2023
376f0e9
docker: remove trailing spaces for Docker README
lbajolet-hashicorp Aug 3, 2023
168e464
docker: add full image to docker README
lbajolet-hashicorp Aug 3, 2023
9ccec0d
Removed repetitive statement from HCP debug logs (#12552)
Aug 8, 2023
4d0a51c
go.mod: bump golang.org/x/net to v0.13.0
lbajolet-hashicorp Aug 8, 2023
19055df
[COMPLIANCE] License changes (#12568)
hashicorp-copywrite[bot] Aug 10, 2023
320fd8d
Update licensing for product release pipeline (#12570)
Aug 11, 2023
c575946
Update terminology to reflect community editions of Packer (#12571)
Aug 11, 2023
2b32903
Document PLSP-related environment variables
lbajolet-hashicorp Aug 16, 2023
a961adf
Update BUSL LICENSE to include licensed product and version. (#12575)
hashicorp-copywrite[bot] Aug 16, 2023
50e8f50
Update CHANGELOG for 1.9.3
nywilken Aug 16, 2023
999d751
Rename duplicate ami name to fix failing test
nywilken Aug 17, 2023
f961715
Prepare for 1.9.4 dev mode
nywilken Aug 17, 2023
eb9e1a4
packer: remove implicit required plugins
lbajolet-hashicorp Aug 9, 2023
f8ebf69
telemetry: Add nil check in SetBundledUsage
nywilken Aug 18, 2023
42da69e
CHANGELOG: cut 1.9.4 release
lbajolet-hashicorp Aug 18, 2023
a0cb199
.go-version: bump version of Go to 1.20.7
finnigja Aug 18, 2023
3c6e3f5
CHANGELOG: preparing for 1.9.5
lbajolet-hashicorp Aug 18, 2023
ebdee64
Bump backport assistant to latest version
nywilken Aug 18, 2023
fa663b4
Updating Community Tools webpage
Aug 25, 2023
2325c7e
Set ivoronin/packer-plugin-sshkey version to 'latest'
ivoronin Aug 18, 2023
48e8c3e
Update version output for `-v` and `--version` flags
nywilken Aug 11, 2023
318529f
hcl2template: remove value validation for locals
lbajolet-hashicorp Sep 6, 2023
6fa0d25
website: register ksyun docuement
notone0010 Aug 4, 2023
7f7567f
Remove plugins on the integration framework
nywilken Sep 15, 2023
324e628
chore: unnecessary use of fmt.Sprintf
testwill Sep 21, 2023
7eb6a45
chore: remove refs to deprecated io/ioutil
testwill Sep 22, 2023
d56db70
Bump github.com/pierrec/lz4 to v4.1.18
zhsj Jul 30, 2023
c0e5947
init: warn if no requirements specified
lbajolet-hashicorp Sep 27, 2023
8490333
Fix broken acctest for Amazon data source
nywilken Oct 2, 2023
8dcc6b9
Bump Go tooling version to 1.20.8
nywilken Oct 3, 2023
8438d81
hcl2template: remove unused shouldContinue bool
lbajolet-hashicorp Aug 24, 2023
2a6ccac
hcl2template: simplify datasource evaluation
lbajolet-hashicorp Aug 24, 2023
14b6ad1
hcl2template: report localtion for cycle detection
lbajolet-hashicorp Aug 24, 2023
d9259d6
hcl2template: extract attr filter code from ds
lbajolet-hashicorp Aug 24, 2023
51ec786
hcl2template: simplify startDatasource function
lbajolet-hashicorp Aug 25, 2023
434a163
hcl2template: fix func to get vars from a config
lbajolet-hashicorp Aug 25, 2023
a1722ab
website: Add community maintained IPSW data source Packer plugin
torarnv Jul 26, 2023
020f18e
command: remove unused FlagSetFlags enum
lbajolet-hashicorp Oct 6, 2023
0e5776a
build with Go 1.20.10
finnigja Oct 20, 2023
193f5e1
go get -u golang.org/x/net && go mod tidy
finnigja Oct 20, 2023
9a1d4b5
go get -u google.golang.org/grpc && go mod tidy
finnigja Oct 20, 2023
fa5d035
build(deps-dev): bump @babel/traverse from 7.17.9 to 7.23.2 in /website
dependabot[bot] Oct 17, 2023
ac71611
Remove all HashiCorp vendored plugins
nywilken Oct 18, 2023
c65bb2f
Remove amazon plugin from acceptance test
nywilken Oct 18, 2023
e8d5436
Remove functions for detecting plugin usage
nywilken Oct 19, 2023
da06116
cmd/hcl2_upgrade: Don't error when using a HashiCorp plugin that is n…
nywilken Oct 19, 2023
3c8de6e
plugins: install SHA256SUM file with 0644 perms
lbajolet-hashicorp Oct 25, 2023
d47cbe7
command: remove SHA256SUM file on plugin removal
lbajolet-hashicorp Oct 25, 2023
452e855
Update README
nywilken Oct 23, 2023
71aa2f3
Bump required Go version in CONTRIBUTING guide
nywilken Oct 23, 2023
0ec424a
Fix broken link to Consul's environment variables page (#12673)
Oct 30, 2023
c528681
docs: amend HCL templates/functions docs
lbajolet-hashicorp Oct 27, 2023
f221a79
command: error on invalid plugins remove
lbajolet-hashicorp Oct 26, 2023
19c14fd
docs: fix aws_secretsmanager Title Name (#12678)
ygxxii Nov 2, 2023
98176f5
Update LICENSE text
hc-github-team-es-release-engineering Nov 8, 2023
edaa10e
Update CHANGELOG
nywilken Nov 8, 2023
c703d2e
Fix notes section in CHANGELOG
nywilken Nov 8, 2023
b328049
Update CHANGELOG
nywilken Nov 8, 2023
360df8f
scripts/prepare_changelog: Replace python for with gh and jq commands
nywilken Nov 8, 2023
631ed14
scripts/prepare_changelog:Update to output entries not in CHANGELOG.md
nywilken Nov 10, 2023
4b1553c
Bump Go to 1.20.11 to mitigate against insecure Windows path parsing
nywilken Nov 9, 2023
85e9e22
Update CHANGELOG
nywilken Nov 10, 2023
2b7bfae
Apply suggestions from code review
Nov 10, 2023
ebc1317
Bumped product version to 1.11.0.
nywilken Nov 10, 2023
a118b54
Bumped product version to 1.11.0
nywilken Nov 10, 2023
c59edfa
Remove dangling upgrade external plugins script
nywilken Nov 10, 2023
cc22e28
Bumped product version to 1.12.0.
hc-github-team-packer Nov 10, 2023
c138ce5
Revert "Bumped product version to 1.12.0."
nywilken Nov 10, 2023
c245b1f
deps: Bump github.com/hashicorp/hcp-sdk-go to v0.73.0
nywilken Nov 15, 2023
7951607
Remove release-engineering as codeowners
sarahethompson Nov 22, 2023
9b2d9f4
build(deps): bump github.com/hashicorp/hcp-sdk-go from 0.73.0 to 0.74.0
dependabot[bot] Nov 22, 2023
efe182b
packer: link to docs if a component is missing
lbajolet-hashicorp Nov 22, 2023
311ba90
Update Acceptance Test to include BuilderSet
nywilken Nov 23, 2023
17ff508
Update didyoumean to call provisioners.List()
nywilken Nov 23, 2023
c90ea91
Update LICENSE
hc-github-team-es-release-engineering Nov 27, 2023
708653c
Update LICENSE
hc-github-team-es-release-engineering Nov 27, 2023
8c7b973
hcl2: don't show an empty source on var errors
lbajolet-hashicorp Nov 27, 2023
ebaf831
cmd/hcl2upgrade: Add VirtualBox as known plugin
nywilken Nov 28, 2023
2aad170
Bumps github.com/hashicorp/packer-plugin-sdk from 0.4.0 to 0.5.2
nywilken Nov 28, 2023
263821a
hcl2template/functions: Add Non-null refinements for various functions
nywilken Nov 28, 2023
083243c
Bump github.com/go-jose/go-jose/v3 to address GO-2023-2334
nywilken Nov 29, 2023
aad03ba
docs: reorg plugins installation tabs
lbajolet-hashicorp Nov 27, 2023
35d20c2
docs: rm implicit github urls from install guide
lbajolet-hashicorp Nov 28, 2023
24430e2
docs: reorganise plugin installation docs
lbajolet-hashicorp Nov 29, 2023
327d8a4
Update CHANGELOG for upcoming releases
nywilken Dec 4, 2023
6f43a82
command: add packer plugins install path flag
lbajolet-hashicorp Oct 3, 2023
a2d9c9d
command: add --force option to init/install
lbajolet-hashicorp Oct 25, 2023
ae5b918
command: reject version with --path for install
lbajolet-hashicorp Nov 24, 2023
e293f2d
command: plugins install reject non-releases
lbajolet-hashicorp Nov 24, 2023
8e2a22e
command: simplify local binary installation
lbajolet-hashicorp Dec 1, 2023
97e2e9e
docs: add exerpt on packer plugins install --path
lbajolet-hashicorp Dec 4, 2023
91a16aa
Remove migrated plugins from old plugin docs framework
nywilken Dec 5, 2023
da97f46
plugin-getter: don't rely only on version for list
lbajolet-hashicorp Dec 4, 2023
4d5f1a3
Update CHANGELOG for 1.10.0 release
nywilken Dec 5, 2023
72bc6c8
Document process for registering a plugin as a Packer Integration
nywilken Nov 20, 2023
97624ce
Replace relative links
nywilken Nov 30, 2023
72385d6
Address review feedback
nywilken Dec 1, 2023
5a96009
Add example shell commands for copying integration files into plugin …
nywilken Dec 1, 2023
ea92d8b
Remove reference to deprecated single components
nywilken Dec 1, 2023
ec16ac2
backport of commit ea92d8b1f38d1debce15a4d7685e38d715b49cd5
nywilken Dec 1, 2023
2b1d934
Merge ea92d8b1f38d1debce15a4d7685e38d715b49cd5 into backport/update/p…
hc-github-team-packer Dec 5, 2023
1c52bce
backport of commit cae2c5eb621ed341e93b8672b6455daa3b43d239
Dec 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/ISSUE_TEMPLATE/plugin_integration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
name: Plugin Integration Request
about: Open request to add your plugin as a Packer integration (https://developer.hashicorp.com/packer/integrations)
labels: integration-request
---

#### Description

A written description of your plugin along with a link to the plugin repository.

#### Integration Tier
<!--- By default all integrations are registered as community integrations.
HashiCorp Technology partners https://www.hashicorp.com/partners/find-a-partner will be registered as a partner once verified. --->

#### Checklist
- [] Has valid [`metadata.hcl`](https://github.com/hashicorp/integration-template) file in plugin repository.
- [] Has added integration scripts [packer-plugin-scaffolding](https://github.com/hashicorp/packer-plugin-scoffolding) to plugin repository.
- [] Has added top-level integration README.md file to plugin `docs` directory.
- [] All plugins components have one README.md describing their usage.
- [] Has a fully synced `.web-docs` directory ready for publishing to the integrations portal.

60 changes: 58 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
## 1.9.0 (Unreleased)
## 1.9.2 (Upcoming)

## 1.9.1 (June 1, 2023)

### BUG FIXES:

* On May 16th 2023, HCP introduced multi-project support to the platform.
In order to use multiple projects in your organization, you will need to update Packer
to version 1.9.1 or above. Starting with 1.9.1, you may specify a project ID to push
builds to with the `HCP_PROJECT_ID` environment variable. If no project ID is specified,
Packer will pick the project with the oldest creation date. Older versions of Packer are
incompatible with multi-project support on HCP, and builds will fail for HCP
organizations with multiple projects on versions before 1.9.1.
[GH-12453](https://github.com/hashicorp/packer/pull/12453)

## 1.9.0 (May 31, 2023)

### NOTES:

* **Breaking Change**: Iteration fingerprints used to be computed from the Git SHA of the
repository where the template is located when running packer build. This
changes with this release, and now fingerprints are automatically generated
Expand All @@ -12,20 +28,60 @@
these builds will work exactly as they did before.
[GH-12172](https://github.com/hashicorp/packer/pull/12172)

* **Breaking Change**: Community-maintained plugins bundled with the Packer binary have been removed.
These external plugin components are released independently of Packer core and can be installed
directly by the user. Users relying on the external plugin components listed below should refer
to the `packer plugins` sub-command and, if using HCL2, a `required_plugins` block to define a
list of plugins for building a template.

### PLUGINS

* Remove provisioner plugins for Chef, Converge, Puppet, Salt, and Inspec as
vendored plugins. These plugins have been previously archived and not
updated in release since being archived. These plugins can be installed
using `packer init` or with the Packer plugins sub-command `packer plugins install github.com/hashicorp/chef`.
[GH-12374](https://github.com/hashicorp/packer/pull/12374)

* The following community plugins won't be bundled with Packer anymore:

* [Alicloud](https://github.com/hashicorp/packer-plugin-alicloud)
* [CloudStack](https://github.com/hashicorp/packer-plugin-cloudstack)
* [HCloud](https://github.com/hashicorp/packer-plugin-hcloud)
* [HyperOne](https://github.com/hashicorp/packer-plugin-hyperone)
* [Hyper-V](https://github.com/hashicorp/packer-plugin-hyperv)
* [JDCloud](https://github.com/hashicorp/packer-plugin-jdcloud)
* [LXC](https://github.com/hashicorp/packer-plugin-lxc)
* [LXD](https://github.com/hashicorp/packer-plugin-lxd)
* [NCloud](https://github.com/hashicorp/packer-plugin-ncloud)
* [OpenStack](https://github.com/hashicorp/packer-plugin-openstack)
* [Proxmox](https://github.com/hashicorp/packer-plugin-proxmox)
* [TencentCloud](https://github.com/hashicorp/packer-plugin-tencentcloud)
* [Triton](https://github.com/hashicorp/packer-plugin-triton)
* [Yandex](https://github.com/hashicorp/packer-plugin-yandex)

[GH-12436](https://github.com/hashicorp/packer/pull/12436)

Users relying on these external plugin components should refer to the `packer plugins` sub-command and,
if using HCL2, a `required_plugins` block to define a list of plugins to use for building a template.

### IMPROVEMENTS:

* core/hcp: Now, fingerprints used by HCP Packer are randomly generated ULIDs
instead of a Git SHA, and a new one is always generated, unless one is
already specified in the environment.
specified in the environment.
[GH-12172](https://github.com/hashicorp/packer/pull/12172)

### BUG FIXES:

* Fix LDFLAGS for release pipelines: Between Packer 1.8.5 and Packer 1.8.7, changes
to the LDFLAGS in use for building the binaries for Packer had mistakenly
removed some compilation flags, leading to the final binaries not being stripped.
This change raised the size of the built binaries by as much as 45%.
In this release, we fixed the LDFLAGS during compilation, yielding leaner binaries.

* Bumped gopsutil to v3. This fixes a macOS intermittent crash reported by the community
[GH-12430](https://github.com/hashicorp/packer/issues/12430)

## 1.8.7 (May 4, 2023)

### NOTES:
Expand Down
4 changes: 0 additions & 4 deletions command/vendored_plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ import (
googlecomputebuilder "github.com/hashicorp/packer-plugin-googlecompute/builder/googlecompute"
googlecomputeexportpostprocessor "github.com/hashicorp/packer-plugin-googlecompute/post-processor/googlecompute-export"
googlecomputeimportpostprocessor "github.com/hashicorp/packer-plugin-googlecompute/post-processor/googlecompute-import"
parallelsisobuilder "github.com/hashicorp/packer-plugin-parallels/builder/parallels/iso"
parallelspvmbuilder "github.com/hashicorp/packer-plugin-parallels/builder/parallels/pvm"
qemubuilder "github.com/hashicorp/packer-plugin-qemu/builder/qemu"
vagrantbuilder "github.com/hashicorp/packer-plugin-vagrant/builder/vagrant"
vagrantpostprocessor "github.com/hashicorp/packer-plugin-vagrant/post-processor/vagrant"
Expand Down Expand Up @@ -69,8 +67,6 @@ var VendoredBuilders = map[string]packersdk.Builder{
"azure-dtl": new(azuredtlbuilder.Builder),
"docker": new(dockerbuilder.Builder),
"googlecompute": new(googlecomputebuilder.Builder),
"parallels-iso": new(parallelsisobuilder.Builder),
"parallels-pvm": new(parallelspvmbuilder.Builder),
"qemu": new(qemubuilder.Builder),
"vagrant": new(vagrantbuilder.Builder),
"vsphere-clone": new(vsphereclonebuilder.Builder),
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ require (
)

require (
github.com/go-openapi/strfmt v0.21.3
github.com/hashicorp/packer-plugin-ansible v1.0.3
github.com/hashicorp/packer-plugin-azure v1.4.0
github.com/hashicorp/packer-plugin-docker v1.0.8
github.com/hashicorp/packer-plugin-googlecompute v1.1.0
github.com/hashicorp/packer-plugin-parallels v1.0.3
github.com/hashicorp/packer-plugin-qemu v1.0.9
github.com/hashicorp/packer-plugin-vagrant v1.0.3
github.com/hashicorp/packer-plugin-virtualbox v1.0.4
Expand Down Expand Up @@ -127,7 +127,6 @@ require (
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/loads v0.21.2 // indirect
github.com/go-openapi/spec v0.20.8 // indirect
github.com/go-openapi/strfmt v0.21.3 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-openapi/validate v0.22.1 // indirect
github.com/gofrs/uuid v4.0.0+incompatible // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,6 @@ github.com/hashicorp/packer-plugin-docker v1.0.8 h1:UWPG/pl+1RFsaNQVhEuowCeOZuES
github.com/hashicorp/packer-plugin-docker v1.0.8/go.mod h1:4U3gHULbUw3okSqqZgQZD5ptyJKs0S7LfOOt2U3V4Jk=
github.com/hashicorp/packer-plugin-googlecompute v1.1.0 h1:/cSZCJuRV6osaSa1uOy8cpN+c/uiCbrSsZ8vyNC0slk=
github.com/hashicorp/packer-plugin-googlecompute v1.1.0/go.mod h1:k7MhKwEDw9ASP3a1y1syKJFZiZ8pO4oH40HvVgGHzUE=
github.com/hashicorp/packer-plugin-parallels v1.0.3 h1:smypphUCEj3arCdlvbNtZvGC1ujsUSRtN1MBvZHt/w8=
github.com/hashicorp/packer-plugin-parallels v1.0.3/go.mod h1:Q842nvosVmP5FnYozk8ZZj93HGIan19jHTxGeteBCb0=
github.com/hashicorp/packer-plugin-qemu v1.0.9 h1:1YKBBzBULYUBWtpAZJTbaLjjZPAdQ63okkpTqMBTnzM=
github.com/hashicorp/packer-plugin-qemu v1.0.9/go.mod h1:BpWIpVpOoPFV9Ppmzq4DP/S0QNoh1R+7DUCqxHdXc+Y=
github.com/hashicorp/packer-plugin-sdk v0.4.0 h1:UyLYe0y02D9wkOQ3FeeZWyFg2+mx2vLuWRGUL5xt50I=
Expand Down
55 changes: 52 additions & 3 deletions internal/hcp/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ package api

import (
"fmt"
"log"
"os"
"time"

packerSvc "github.com/hashicorp/hcp-sdk-go/clients/cloud-packer-service/stable/2021-04-30/client/packer_service"
organizationSvc "github.com/hashicorp/hcp-sdk-go/clients/cloud-resource-manager/preview/2019-12-10/client/organization_service"
projectSvc "github.com/hashicorp/hcp-sdk-go/clients/cloud-resource-manager/preview/2019-12-10/client/project_service"
"github.com/hashicorp/hcp-sdk-go/clients/cloud-resource-manager/preview/2019-12-10/models"
rmmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-resource-manager/preview/2019-12-10/models"
"github.com/hashicorp/hcp-sdk-go/httpclient"
"github.com/hashicorp/packer/internal/hcp/env"
Expand Down Expand Up @@ -97,9 +101,54 @@ func (c *Client) loadProjectID() error {
if err != nil {
return fmt.Errorf("unable to fetch project id: %v", err)
}
if len(listProjResp.Payload.Projects) > 1 {
return fmt.Errorf("this version of Packer does not support multiple projects")

if env.HasProjectID() {
proj, err := findProjectByID(os.Getenv(env.HCPProjectID), listProjResp.Payload.Projects)
if err != nil {
return err
}

c.ProjectID = proj.ID
} else {
if len(listProjResp.Payload.Projects) > 1 {
log.Printf("[WARNING] Multiple HCP projects found, will pick the oldest one by default\n" +
"To specify which project to use, set the HCP_PROJECT_ID environment variable to the one you want to use.")
}

proj, err := findOldestProject(listProjResp.Payload.Projects)
if err != nil {
return err
}

c.ProjectID = proj.ID
}
c.ProjectID = listProjResp.Payload.Projects[0].ID

return nil
}

func findOldestProject(projs []*models.HashicorpCloudResourcemanagerProject) (*models.HashicorpCloudResourcemanagerProject, error) {
if len(projs) == 0 {
return nil, fmt.Errorf("no project found")
}

proj := projs[0]
for i := 1; i < len(projs); i++ {
nxtProj := projs[i]

if time.Time(nxtProj.CreatedAt).Before(time.Time(proj.CreatedAt)) {
proj = nxtProj
}
}

return proj, nil
}

func findProjectByID(projID string, projs []*models.HashicorpCloudResourcemanagerProject) (*models.HashicorpCloudResourcemanagerProject, error) {
for _, proj := range projs {
if proj.ID == projID {
return proj, nil
}
}

return nil, fmt.Errorf("No project %q found", projID)
}
163 changes: 163 additions & 0 deletions internal/hcp/api/client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
package api

import (
"testing"
"time"

"github.com/go-openapi/strfmt"
"github.com/hashicorp/hcp-sdk-go/clients/cloud-resource-manager/preview/2019-12-10/models"
)

func TestFindProjectID(t *testing.T) {
testcases := []struct {
Name string
ProjectID string
ProjectList []*models.HashicorpCloudResourcemanagerProject
ExpectProjectID string
ExpectErr bool
}{
{
"Only one project, project exists, success",
"test-project-exists",
[]*models.HashicorpCloudResourcemanagerProject{
{
ID: "test-project-exists",
},
},
"test-project-exists",
false,
},
{
"Multiple projects, project exists, success",
"test-project-exists",
[]*models.HashicorpCloudResourcemanagerProject{
{
ID: "other-project-exists",
},
{
ID: "test-project-exists",
},
},
"test-project-exists",
false,
},
{
"One project, no id match, fail",
"test-project-exists",
[]*models.HashicorpCloudResourcemanagerProject{
{
ID: "other-project-exists",
},
},
"",
true,
},
{
"Multiple projects, no id match, fail",
"test-project-exists",
[]*models.HashicorpCloudResourcemanagerProject{
{
ID: "other-project-exists",
},
{
ID: "yet-another-project-exists",
},
},
"",
true,
},
{
"No projects, no id match, fail",
"test-project-exists",
[]*models.HashicorpCloudResourcemanagerProject{},
"",
true,
},
}

for _, tt := range testcases {
t.Run(tt.Name, func(t *testing.T) {
proj, err := findProjectByID(tt.ProjectID, tt.ProjectList)
if (err != nil) != tt.ExpectErr {
t.Errorf("test findProjectByID, expected %t, got %t",
tt.ExpectErr,
err != nil)
}

if proj != nil && proj.ID != tt.ExpectProjectID {
t.Errorf("expected to select project %q, got %q", tt.ExpectProjectID, proj.ID)
}
})
}
}

func TestFindOldestProject(t *testing.T) {
testcases := []struct {
Name string
ProjectList []*models.HashicorpCloudResourcemanagerProject
ExpectProjectID string
ExpectErr bool
}{
{
"Only one project, project exists, success",
[]*models.HashicorpCloudResourcemanagerProject{
{
ID: "test-project-exists",
},
},
"test-project-exists",
false,
},
{
"Multiple projects, pick the oldest",
[]*models.HashicorpCloudResourcemanagerProject{
{
ID: "test-project-exists",
CreatedAt: strfmt.DateTime(time.Date(2023, 1, 1, 1, 0, 0, 0, time.UTC)),
},
{
ID: "test-oldest-project",
CreatedAt: strfmt.DateTime(time.Date(2022, 1, 1, 1, 0, 0, 0, time.UTC)),
},
},
"test-oldest-project",
false,
},
{
"Multiple projects, different order, pick the oldest",
[]*models.HashicorpCloudResourcemanagerProject{
{
ID: "test-oldest-project",
CreatedAt: strfmt.DateTime(time.Date(2022, 1, 1, 1, 0, 0, 0, time.UTC)),
},
{
ID: "test-project-exists",
CreatedAt: strfmt.DateTime(time.Date(2023, 1, 1, 1, 0, 0, 0, time.UTC)),
},
},
"test-oldest-project",
false,
},
{
"No projects, should error",
[]*models.HashicorpCloudResourcemanagerProject{},
"",
true,
},
}

for _, tt := range testcases {
t.Run(tt.Name, func(t *testing.T) {
proj, err := findOldestProject(tt.ProjectList)
if (err != nil) != tt.ExpectErr {
t.Errorf("test findProjectByID, expected %t, got %t",
tt.ExpectErr,
err != nil)
}

if proj != nil && proj.ID != tt.ExpectProjectID {
t.Errorf("expected to select project %q, got %q", tt.ExpectProjectID, proj.ID)
}
})
}
}
Loading
Loading