Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .go-version
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
1.21.13
1.25.11

126 changes: 30 additions & 96 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,37 @@
# Copyright (c) HashiCorp, Inc.
# Copyright IBM Corp. 2013, 2026
# SPDX-License-Identifier: MPL-2.0

issues:
# List of regexps of issue texts to exclude, empty list by default.
# But independently from this option we use default exclude patterns,
# it can be disabled by `exclude-use-default: false`. To list all
# excluded by default patterns execute `golangci-lint run --help`

exclude-rules:
# Exclude gosimple bool check
- linters:
- gosimple
text: "S(1002|1008|1021)"
# Exclude failing staticchecks for now
- linters:
- staticcheck
text: "SA(1006|1019|4006|4010|4017|5007|6005|9004):"
# Exclude lll issues for long lines with go:generate
- linters:
- lll
source: "^//go:generate "
- linters:
- errcheck
path: ".*_test.go"

# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
max-issues-per-linter: 0

# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same-issues: 0
version: "2"

linters:
disable-all: true
enable:
- errcheck
- goimports
- gosimple
- asasalint
- asciicheck
- bidichk
- decorder
- dupword
- govet
- ineffassign
- misspell
- nilerr
- reassign
- staticcheck
- unconvert
- unused
fast: true
settings:
errcheck:
# report about not checking of errors in type assertions: `a := b.(MyStruct)`;
# default is false: such cases aren't reported by default.
check-type-assertions: false

# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
# default is false: such cases aren't reported by default.
check-blank: false
staticcheck:
# SAxxxx checks in https://staticcheck.dev/docs/configuration/options/#checks
# Example (to disable some checks): [ "all", "-SA1000", "-SA1001"]
# Run `GL_DEBUG=staticcheck golangci-lint run --enable=staticcheck` to see all available checks and enabled by config checks.
checks: ["all", "-SA4006", "-ST1000", "-ST1003", "-ST1005", "-ST1012", "-ST1016", "-ST1020", "-ST1021", "-ST1022", "-QF1001", "-QF1004", "-QF1008", "-QF1012"]

# options for analysis running
run:
Expand All @@ -57,71 +47,15 @@ run:
# include test files or not, default is true
tests: true

# list of build tags, all linters use it. Default is empty list.
#build-tags:
# - mytag

# which dirs to skip: issues from them won't be reported;
# can use regexp here: generated.*, regexp is applied on full path;
# default value is empty list, but default dirs are skipped independently
# from this option's value (see skip-dirs-use-default).
#skip-dirs:
# - src/external_libs
# - autogenerated_by_my_lib

# default is true. Enables skipping of directories:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs-use-default: true

# which files to skip: they will be analyzed, but issues from them
# won't be reported. Default value is empty list, but there is
# no need to include all autogenerated files, we confidently recognize
# autogenerated files. If it's not please let us know.
exclude-files:
- ".*\\.hcl2spec\\.go$"
# skip-files:
# - ".*\\.hcl2spec\\.go$"
# - lib/bad.go

# by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules":
# If invoked with -mod=readonly, the go command is disallowed from the implicit
# automatic updating of go.mod described above. Instead, it fails when any changes
# to go.mod are needed. This setting is most useful to check that go.mod does
# not need updates, such as in a continuous integration and testing system.
# If invoked with -mod=vendor, the go command assumes that the vendor
# directory holds the correct copies of dependencies and ignores
# the dependency descriptions in go.mod.
modules-download-mode: readonly

# output configuration options
output:
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
formats: colored-line-number

# print lines of code with issue, default is true
print-issued-lines: true

# print linter name in the end of issue text, default is true
print-linter-name: true

# make issues output unique by line, default is true
uniq-by-line: true


# all available settings of specific linters
linters-settings:
errcheck:
# report about not checking of errors in type assetions: `a := b.(MyStruct)`;
# default is false: such cases aren't reported by default.
check-type-assertions: false

# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
# default is false: such cases aren't reported by default.
check-blank: false

# [deprecated] comma-separated list of pairs of the form pkg:regex
# the regex is used to ignore names within pkg. (default "fmt:.*").
# see https://github.com/kisielk/errcheck#the-deprecated-method for details
exclude-functions: fmt:.*,io/ioutil:^Read.*,io:Close

# path to a file containing a list of functions to exclude from checking
# see https://github.com/kisielk/errcheck#excluding-functions for details
#exclude: /path/to/file.txt
formatters:
enable:
- gofmt
- goimports
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 1.1.4 (June 17, 2026)

* fix: add an optional wait before creating the image to improve reliability in image creation workflows.
* fix: use `openstack` as the HCP metadata provider name (instead of the default prefixed provider value).
* chore: add the HCP Ready flag to web metadata.
* chore: update copyright and license headers across the codebase for compliance.
* chore: bump `github.com/hashicorp/packer-plugin-sdk` from `0.6.4` to `0.6.7`.

## 1.0.0 (June 14, 2021)

* Update packer-plugin-sdk to version 0.2.3. [GH-29]
Expand Down
11 changes: 5 additions & 6 deletions builder/openstack/access_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"crypto/x509"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"

Expand Down Expand Up @@ -205,7 +204,7 @@
tls_config := &tls.Config{}

if c.CACertFile != "" {
caCert, err := ioutil.ReadFile(c.CACertFile)
caCert, err := os.ReadFile(c.CACertFile)
if err != nil {
return []error{err}
}
Expand All @@ -229,7 +228,7 @@
tls_config.Certificates = []tls.Certificate{cert}
}

transport := cleanhttp.DefaultTransport()

Check failure on line 231 in builder/openstack/access_config.go

View workflow job for this annotation

GitHub Actions / Lint check

undefined: cleanhttp (typecheck)
transport.TLSClientConfig = tls_config
client.HTTPClient.Transport = transport

Expand Down Expand Up @@ -300,7 +299,7 @@
func (drt *DebugRoundTripper) RoundTrip(request *http.Request) (*http.Response, error) {
defer func() {
if request.Body != nil {
request.Body.Close()
_ = request.Body.Close()
}
}()

Expand All @@ -323,15 +322,15 @@

if response.StatusCode >= 400 {
buf := bytes.NewBuffer([]byte{})
body, _ := ioutil.ReadAll(io.TeeReader(response.Body, buf))
body, _ := io.ReadAll(io.TeeReader(response.Body, buf))
drt.DebugMessage(fmt.Sprintf("Response Error: %+v\n", string(body)))
bufWithClose := ioutil.NopCloser(buf)
bufWithClose := io.NopCloser(buf)
response.Body = bufWithClose
}

return response, err
}

func (drt *DebugRoundTripper) DebugMessage(message string) {
drt.ui.Message(fmt.Sprintf("[DEBUG] %s", message))
drt.ui.Say(fmt.Sprintf("[DEBUG] %s", message))
}
3 changes: 1 addition & 2 deletions builder/openstack/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import (
)

func TestBuilder_ImplementsBuilder(t *testing.T) {
var raw interface{}
raw = &Builder{}
var raw interface{} = &Builder{}
if _, ok := raw.(packersdk.Builder); !ok {
t.Fatalf("Builder should be a builder")
}
Expand Down
2 changes: 1 addition & 1 deletion builder/openstack/image_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type ImageConfig struct {
// shared.
ImageMembers []string `mapstructure:"image_members" required:"false"`
// When true, perform the image accept so the members can see the image in their
// project. This requires a user with priveleges both in the build project and
// project. This requires a user with privileges both in the build project and
// in the members provided. Defaults to false.
ImageAutoAcceptMembers bool `mapstructure:"image_auto_accept_members" required:"false"`
// Disk format of the resulting image. This option works if
Expand Down
12 changes: 9 additions & 3 deletions builder/openstack/run_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ import (
func init() {
// Clear out the openstack env vars so they don't
// affect our tests.
os.Setenv("SDK_USERNAME", "")
os.Setenv("SDK_PASSWORD", "")
os.Setenv("SDK_PROVIDER", "")
if err := os.Setenv("SDK_USERNAME", ""); err != nil {
panic(err)
}
if err := os.Setenv("SDK_PASSWORD", ""); err != nil {
panic(err)
}
if err := os.Setenv("SDK_PROVIDER", ""); err != nil {
panic(err)
}
}

func testRunConfig() *RunConfig {
Expand Down
10 changes: 5 additions & 5 deletions builder/openstack/step_allocate_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (s *StepAllocateIp) Run(ctx context.Context, state multistep.StateBag) mult
state.Put("access_ip", &instanceIP)

if s.FloatingIP == "" && !s.ReuseIPs && s.FloatingIPNetwork == "" {
ui.Message("Floating IP not required")
ui.Say("Floating IP not required")
return multistep.ActionContinue
}

Expand Down Expand Up @@ -69,7 +69,7 @@ func (s *StepAllocateIp) Run(ctx context.Context, state multistep.StateBag) mult
}

instanceIP = *freeFloatingIP
ui.Message(fmt.Sprintf("Selected floating IP: '%s' (%s)", instanceIP.ID, instanceIP.FloatingIP))
ui.Say(fmt.Sprintf("Selected floating IP: '%s' (%s)", instanceIP.ID, instanceIP.FloatingIP))
state.Put("floatingip_istemp", false)
} else if s.ReuseIPs {
// If ReuseIPs is set to true and we have a free floating IP, use it rather
Expand All @@ -84,7 +84,7 @@ func (s *StepAllocateIp) Run(ctx context.Context, state multistep.StateBag) mult
}

instanceIP = *freeFloatingIP
ui.Message(fmt.Sprintf("Selected floating IP: '%s' (%s)", instanceIP.ID, instanceIP.FloatingIP))
ui.Say(fmt.Sprintf("Selected floating IP: '%s' (%s)", instanceIP.ID, instanceIP.FloatingIP))
state.Put("floatingip_istemp", false)
} else if s.FloatingIPNetwork != "" {
// Lastly, if FloatingIPNetwork was provided by the user, we need to use it
Expand All @@ -109,7 +109,7 @@ func (s *StepAllocateIp) Run(ctx context.Context, state multistep.StateBag) mult
}

instanceIP = *newIP
ui.Message(fmt.Sprintf("Created floating IP: '%s' (%s)", instanceIP.ID, instanceIP.FloatingIP))
ui.Say(fmt.Sprintf("Created floating IP: '%s' (%s)", instanceIP.ID, instanceIP.FloatingIP))
state.Put("floatingip_istemp", true)
}

Expand Down Expand Up @@ -138,7 +138,7 @@ func (s *StepAllocateIp) Run(ctx context.Context, state multistep.StateBag) mult
return multistep.ActionHalt
}

ui.Message(fmt.Sprintf(
ui.Say(fmt.Sprintf(
"Added floating IP '%s' (%s) to instance!", instanceIP.ID, instanceIP.FloatingIP))
}

Expand Down
2 changes: 1 addition & 1 deletion builder/openstack/step_create_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) mul
}

// Set the Image ID in the state
ui.Message(fmt.Sprintf("Image: %s", imageId))
ui.Say(fmt.Sprintf("Image: %s", imageId))
state.Put("image", imageId)

// Wait for the image to become ready
Expand Down
2 changes: 1 addition & 1 deletion builder/openstack/step_create_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (s *StepCreateVolume) Run(ctx context.Context, state multistep.StateBag) mu
}

// Set the Volume ID in the state.
ui.Message(fmt.Sprintf("Volume ID: %s", volume.ID))
ui.Say(fmt.Sprintf("Volume ID: %s", volume.ID))
state.Put("volume_id", volume.ID)

return multistep.ActionContinue
Expand Down
2 changes: 1 addition & 1 deletion builder/openstack/step_discover_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (s *StepDiscoverNetwork) Run(ctx context.Context, state multistep.StateBag)
return multistep.ActionHalt
}

ui.Message(fmt.Sprintf("Found network ID: %s", networkID))
ui.Say(fmt.Sprintf("Found network ID: %s", networkID))
networks = append(networks, servers.Network{UUID: networkID})
}

Expand Down
4 changes: 2 additions & 2 deletions builder/openstack/step_get_password.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ func (s *StepGetPassword) Run(ctx context.Context, state multistep.StateBag) mul
time.Sleep(5 * time.Second)
}

ui.Message("Password retrieved!")
ui.Say("Password retrieved!")
s.Comm.WinRMPassword = password

// In debug-mode, we output the password
if s.Debug {
ui.Message(fmt.Sprintf(
ui.Say(fmt.Sprintf(
"Password (since debug is enabled) \"%s\"", s.Comm.WinRMPassword))
}

Expand Down
6 changes: 4 additions & 2 deletions builder/openstack/step_key_pair.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ func (s *StepKeyPair) Run(ctx context.Context, state multistep.StateBag) multist
// If we're in debug mode, output the private key to the working
// directory.
if s.Debug {
ui.Message(fmt.Sprintf("Saving key for debug purposes: %s", s.DebugKeyPath))
ui.Say(fmt.Sprintf("Saving key for debug purposes: %s", s.DebugKeyPath))
f, err := os.Create(s.DebugKeyPath)
if err != nil {
state.Put("error", fmt.Errorf("Error saving debug key: %s", err))
return multistep.ActionHalt
}
defer f.Close()
defer func() {
_ = f.Close()
}()

// Write the key out
if _, err := f.Write(s.Comm.SSHPrivateKey); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion builder/openstack/step_load_flavor.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (s *StepLoadFlavor) Run(ctx context.Context, state multistep.StateBag) mult
flavor = &flavors.Flavor{ID: id}
}

ui.Message(fmt.Sprintf("Verified flavor. ID: %s", flavor.ID))
ui.Say(fmt.Sprintf("Verified flavor. ID: %s", flavor.ID))
state.Put("flavor_id", flavor.ID)
return multistep.ActionContinue
}
Expand Down
6 changes: 3 additions & 3 deletions builder/openstack/step_run_source_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ package openstack
import (
"context"
"fmt"
"io/ioutil"
"log"
"os"

"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/bootfromvolume"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs"
Expand Down Expand Up @@ -46,7 +46,7 @@ func (s *StepRunSourceServer) Run(ctx context.Context, state multistep.StateBag)

userData := []byte(s.UserData)
if s.UserDataFile != "" {
userData, err = ioutil.ReadFile(s.UserDataFile)
userData, err = os.ReadFile(s.UserDataFile)
if err != nil {
err = fmt.Errorf("Error reading user data file: %s", err)
state.Put("error", err)
Expand Down Expand Up @@ -111,7 +111,7 @@ func (s *StepRunSourceServer) Run(ctx context.Context, state multistep.StateBag)
return multistep.ActionHalt
}

ui.Message(fmt.Sprintf("Server ID: %s", s.server.ID))
ui.Say(fmt.Sprintf("Server ID: %s", s.server.ID))
log.Printf("server id: %s", s.server.ID)

ui.Say("Waiting for server to become ready...")
Expand Down
Loading
Loading