diff --git a/acctest/testing.go b/acctest/testing.go index 23fd804a3de..f72b8f428cb 100644 --- a/acctest/testing.go +++ b/acctest/testing.go @@ -73,9 +73,9 @@ type TestTeardownFunc func() error // // Users should just use a *testing.T object, which implements this. type TestT interface { - Error(args ...interface{}) - Fatal(args ...interface{}) - Skip(args ...interface{}) + Error(args ...any) + Fatal(args ...any) + Skip(args ...any) } type TestBuilderSet struct { diff --git a/acctest/testing_test.go b/acctest/testing_test.go index 8f9f121961a..58f8d4b359d 100644 --- a/acctest/testing_test.go +++ b/acctest/testing_test.go @@ -44,28 +44,28 @@ func TestTest_preCheck(t *testing.T) { // mockT implements TestT for testing type mockT struct { ErrorCalled bool - ErrorArgs []interface{} + ErrorArgs []any FatalCalled bool - FatalArgs []interface{} + FatalArgs []any SkipCalled bool - SkipArgs []interface{} + SkipArgs []any f bool } -func (t *mockT) Error(args ...interface{}) { +func (t *mockT) Error(args ...any) { t.ErrorCalled = true t.ErrorArgs = args t.f = true } -func (t *mockT) Fatal(args ...interface{}) { +func (t *mockT) Fatal(args ...any) { t.FatalCalled = true t.FatalArgs = args t.f = true } -func (t *mockT) Skip(args ...interface{}) { +func (t *mockT) Skip(args ...any) { t.SkipCalled = true t.SkipArgs = args t.f = true diff --git a/builder/file/artifact.go b/builder/file/artifact.go index aac15af0d10..2ee5e475ce2 100644 --- a/builder/file/artifact.go +++ b/builder/file/artifact.go @@ -33,7 +33,7 @@ func (a *FileArtifact) String() string { return fmt.Sprintf("Stored file: %s", a.filename) } -func (a *FileArtifact) State(name string) interface{} { +func (a *FileArtifact) State(name string) any { if name == registryimage.ArtifactStateURI { img, err := registryimage.FromArtifact(a, registryimage.WithID(path.Base(a.filename)), diff --git a/builder/file/builder.go b/builder/file/builder.go index d426b35634e..2d23e837417 100644 --- a/builder/file/builder.go +++ b/builder/file/builder.go @@ -27,7 +27,7 @@ type Builder struct { func (b *Builder) ConfigSpec() hcldec.ObjectSpec { return b.config.FlatMapstructure().HCL2Spec() } -func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) { +func (b *Builder) Prepare(raws ...any) ([]string, []string, error) { warnings, errs := b.config.Prepare(raws...) if errs != nil { return nil, warnings, errs diff --git a/builder/file/config.go b/builder/file/config.go index a0fd8679b89..7b305673b92 100644 --- a/builder/file/config.go +++ b/builder/file/config.go @@ -25,7 +25,7 @@ type Config struct { Content string `mapstructure:"content"` } -func (c *Config) Prepare(raws ...interface{}) ([]string, error) { +func (c *Config) Prepare(raws ...any) ([]string, error) { warnings := []string{} err := config.Decode(c, &config.DecodeOpts{ diff --git a/builder/file/config_test.go b/builder/file/config_test.go index c917a6d4108..71eedb00597 100644 --- a/builder/file/config_test.go +++ b/builder/file/config_test.go @@ -8,8 +8,8 @@ import ( "testing" ) -func testConfig() map[string]interface{} { - return map[string]interface{}{ +func testConfig() map[string]any { + return map[string]any{ "source": "src.txt", "target": "dst.txt", "content": "Hello, world!", diff --git a/builder/null/artifact_export.go b/builder/null/artifact_export.go index ede3f91118c..8afbc10a84d 100644 --- a/builder/null/artifact_export.go +++ b/builder/null/artifact_export.go @@ -27,7 +27,7 @@ func (a *NullArtifact) String() string { return "Did not export anything. This is the null builder" } -func (a *NullArtifact) State(name string) interface{} { +func (a *NullArtifact) State(name string) any { switch name { case registryimage.ArtifactStateURI: img, _ := registryimage.FromArtifact(a, @@ -38,7 +38,7 @@ func (a *NullArtifact) State(name string) interface{} { ) return img case "generated_data": - return map[interface{}]interface{}{ + return map[any]any{ "ID": "Null", } default: diff --git a/builder/null/builder.go b/builder/null/builder.go index 57cbfbd2b02..0e9e1e2b89f 100644 --- a/builder/null/builder.go +++ b/builder/null/builder.go @@ -22,7 +22,7 @@ type Builder struct { func (b *Builder) ConfigSpec() hcldec.ObjectSpec { return b.config.FlatMapstructure().HCL2Spec() } -func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) { +func (b *Builder) Prepare(raws ...any) ([]string, []string, error) { warnings, errs := b.config.Prepare(raws...) if errs != nil { return nil, warnings, errs diff --git a/builder/null/config.go b/builder/null/config.go index f8f67cc6adb..27b5ac6bcc0 100644 --- a/builder/null/config.go +++ b/builder/null/config.go @@ -21,7 +21,7 @@ type Config struct { CommConfig communicator.Config `mapstructure:",squash"` } -func (c *Config) Prepare(raws ...interface{}) ([]string, error) { +func (c *Config) Prepare(raws ...any) ([]string, error) { err := config.Decode(c, &config.DecodeOpts{ PluginType: BuilderId, diff --git a/builder/null/config_test.go b/builder/null/config_test.go index 89cc177e65c..b4c74e05e0a 100644 --- a/builder/null/config_test.go +++ b/builder/null/config_test.go @@ -10,8 +10,8 @@ import ( "github.com/hashicorp/packer-plugin-sdk/communicator" ) -func testConfig() map[string]interface{} { - return map[string]interface{}{ +func testConfig() map[string]any { + return map[string]any{ "ssh_host": "foo", "ssh_username": "bar", "ssh_password": "baz", diff --git a/command/build_cancellation_test.go b/command/build_cancellation_test.go index ecb5e75f36c..90f5368adb3 100644 --- a/command/build_cancellation_test.go +++ b/command/build_cancellation_test.go @@ -57,7 +57,7 @@ func TestBuildCommand_RunContext_CtxCancel(t *testing.T) { t.Run(tt.name, func(t *testing.T) { t.Parallel() b := NewParallelTestBuilder(tt.parallelPassingTests) - locked := &LockedBuilder{unlock: make(chan interface{})} + locked := &LockedBuilder{unlock: make(chan any)} c := &BuildCommand{ Meta: testMetaParallel(t, b, locked), } diff --git a/command/build_parallel_test.go b/command/build_parallel_test.go index 1870d82a8ec..19d3b135bfb 100644 --- a/command/build_parallel_test.go +++ b/command/build_parallel_test.go @@ -35,7 +35,7 @@ type ParallelTestBuilder struct { func (b *ParallelTestBuilder) ConfigSpec() hcldec.ObjectSpec { return nil } -func (b *ParallelTestBuilder) Prepare(raws ...interface{}) ([]string, []string, error) { +func (b *ParallelTestBuilder) Prepare(raws ...any) ([]string, []string, error) { return nil, nil, nil } @@ -46,11 +46,11 @@ func (b *ParallelTestBuilder) Run(ctx context.Context, ui packersdk.Ui, hook pac } // LockedBuilder won't run until unlock is called -type LockedBuilder struct{ unlock chan interface{} } +type LockedBuilder struct{ unlock chan any } func (b *LockedBuilder) ConfigSpec() hcldec.ObjectSpec { return nil } -func (b *LockedBuilder) Prepare(raws ...interface{}) ([]string, []string, error) { +func (b *LockedBuilder) Prepare(raws ...any) ([]string, []string, error) { return nil, nil, nil } @@ -93,7 +93,7 @@ func TestBuildParallel_1(t *testing.T) { // testfile has 6 builds, with first one locks 'forever', other builds // should go through. b := NewParallelTestBuilder(5) - locked := &LockedBuilder{unlock: make(chan interface{})} + locked := &LockedBuilder{unlock: make(chan any)} c := &BuildCommand{ Meta: testMetaParallel(t, b, locked), @@ -122,7 +122,7 @@ func TestBuildParallel_2(t *testing.T) { // testfile has 6 builds, 2 of them lock 'forever', other builds // should go through. b := NewParallelTestBuilder(4) - locked := &LockedBuilder{unlock: make(chan interface{})} + locked := &LockedBuilder{unlock: make(chan any)} c := &BuildCommand{ Meta: testMetaParallel(t, b, locked), @@ -151,7 +151,7 @@ func TestBuildParallel_Timeout(t *testing.T) { // testfile has 6 builds, 1 of them locks 'forever', one locks and times // out other builds should go through. b := NewParallelTestBuilder(4) - locked := &LockedBuilder{unlock: make(chan interface{})} + locked := &LockedBuilder{unlock: make(chan any)} c := &BuildCommand{ Meta: testMetaParallel(t, b, locked), diff --git a/command/cli.go b/command/cli.go index 38d3e9a6d49..98881d0080e 100644 --- a/command/cli.go +++ b/command/cli.go @@ -111,8 +111,8 @@ func (ba *BuildArgs) AddFlagSets(flags *flag.FlagSet) { // // Most of the arguments are kept as-is, except for the -var args, where only // the keys are kept to avoid leaking potential secrets. -func GetCleanedBuildArgs(ba *BuildArgs) map[string]interface{} { - cleanedArgs := map[string]interface{}{ +func GetCleanedBuildArgs(ba *BuildArgs) map[string]any { + cleanedArgs := map[string]any{ "debug": ba.Debug, "force": ba.Force, "only": ba.Only, diff --git a/command/fix.go b/command/fix.go index 4441eeed71c..af4974a0737 100644 --- a/command/fix.go +++ b/command/fix.go @@ -66,7 +66,7 @@ func (c *FixCommand) RunContext(ctx context.Context, cla *FixArgs) int { defer tplF.Close() // Decode the JSON into a generic map structure - var templateData map[string]interface{} + var templateData map[string]any decoder := json.NewDecoder(tplF) if err := decoder.Decode(&templateData); err != nil { c.Ui.Error(fmt.Sprintf("Error parsing template: %s", err)) diff --git a/command/flag-slice/flag_test.go b/command/flag-slice/flag_test.go index 6fd5feec3c0..36f6c6ca96b 100644 --- a/command/flag-slice/flag_test.go +++ b/command/flag-slice/flag_test.go @@ -10,8 +10,7 @@ import ( ) func TestStringFlag_implements(t *testing.T) { - var raw interface{} - raw = new(StringFlag) + var raw any = new(StringFlag) if _, ok := raw.(flag.Value); !ok { t.Fatalf("StringFlag should be a Value") } diff --git a/command/hcl2_upgrade.go b/command/hcl2_upgrade.go index e1ccaed49a4..cb9a3c431d8 100644 --- a/command/hcl2_upgrade.go +++ b/command/hcl2_upgrade.go @@ -86,7 +86,7 @@ const ( ) var ( - amazonSecretsManagerMap = map[string]map[string]interface{}{} + amazonSecretsManagerMap = map[string]map[string]any{} localsVariableMap = map[string]string{} timestamp = false isotime = false @@ -392,7 +392,7 @@ func transposeTemplatingCalls(s []byte) []byte { } } id := fmt.Sprintf("autogenerated_%d", len(amazonSecretsManagerMap)+1) - amazonSecretsManagerMap[id] = map[string]interface{}{ + amazonSecretsManagerMap[id] = map[string]any{ "name": a[0], "key": a[1], } @@ -405,7 +405,7 @@ func transposeTemplatingCalls(s []byte) []byte { } } id := fmt.Sprintf("autogenerated_%d", len(amazonSecretsManagerMap)+1) - amazonSecretsManagerMap[id] = map[string]interface{}{ + amazonSecretsManagerMap[id] = map[string]any{ "name": a[0], } return fmt.Sprintf("${data.amazon-secretsmanager.%s.value}", id) @@ -681,7 +681,7 @@ func referencedUserVariables(s []byte) map[string]*template.Variable { return vars } -func jsonBodyToHCL2Body(out *hclwrite.Body, kvs map[string]interface{}) { +func jsonBodyToHCL2Body(out *hclwrite.Body, kvs map[string]any) { ks := []string{} for k := range kvs { ks = append(ks, k) @@ -692,8 +692,8 @@ func jsonBodyToHCL2Body(out *hclwrite.Body, kvs map[string]interface{}) { value := kvs[k] switch value := value.(type) { - case map[string]interface{}: - var mostComplexElem interface{} + case map[string]any: + var mostComplexElem any for _, randomElem := range value { if k == "linux_options" || k == "network_interface" || k == "shared_image_gallery" { break @@ -729,12 +729,12 @@ func jsonBodyToHCL2Body(out *hclwrite.Body, kvs map[string]interface{}) { } case map[string]string, map[string]int, map[string]float64: out.SetAttributeValue(k, hcl2shim.HCL2ValueFromConfigValue(value)) - case []interface{}: + case []any: if len(value) == 0 { continue } - var mostComplexElem interface{} + var mostComplexElem any for _, randomElem := range value { // HACK: we take the most complex element of that slice because // in hcl2 slices of plain types can be arrays, for example: @@ -751,12 +751,12 @@ func jsonBodyToHCL2Body(out *hclwrite.Body, kvs map[string]interface{}) { } } switch mostComplexElem.(type) { - case map[string]interface{}: + case map[string]any: // this is an object in a slice; so we unwrap it. We // could try to remove any 's' suffix in the key, but // this might not work everywhere. for i := range value { - value := value[i].(map[string]interface{}) + value := value[i].(map[string]any) nestedBlockBody := out.AppendNewBlock(k, nil).Body() jsonBodyToHCL2Body(nestedBlockBody, value) } @@ -1117,12 +1117,12 @@ func (p *AmazonAmiDatasourceParser) Parse(_ *template.Template) error { p.out = []byte{} } - amazonAmiFilters := []map[string]interface{}{} + amazonAmiFilters := []map[string]any{} i := 1 for _, builder := range p.Builders { if strings.HasPrefix(builder.Type, "amazon-") { if sourceAmiFilter, ok := builder.Config["source_ami_filter"]; ok { - sourceAmiFilterCfg := map[string]interface{}{} + sourceAmiFilterCfg := map[string]any{} if err := mapstructure.Decode(sourceAmiFilter, &sourceAmiFilterCfg); err != nil { return fmt.Errorf("Failed to write amazon-ami data source: %v", err) } @@ -1211,9 +1211,9 @@ type AwsAccessConfig struct { PollingConfig *AWSPollingConfig `mapstructure:"aws_polling" required:"false"` } -func copyAWSAccessConfig(sourceAmi map[string]interface{}, builder map[string]interface{}) (map[string]interface{}, error) { +func copyAWSAccessConfig(sourceAmi map[string]any, builder map[string]any) (map[string]any, error) { // Transform access config to a map - accessConfigMap := map[string]interface{}{} + accessConfigMap := map[string]any{} if err := mapstructure.Decode(AwsAccessConfig{}, &accessConfigMap); err != nil { return sourceAmi, err } @@ -1374,7 +1374,7 @@ func writeProvisioner(typeName string, provisioner *template.Provisioner) []byte cfg := provisioner.Config if cfg == nil { - cfg = map[string]interface{}{} + cfg = map[string]any{} } if len(provisioner.Except) > 0 { @@ -1430,7 +1430,7 @@ func (p *PostProcessorParser) Parse(tpl *template.Template) error { } cfg := pp.Config if cfg == nil { - cfg = map[string]interface{}{} + cfg = map[string]any{} } if len(pp.Except) > 0 { diff --git a/datasource/hcp-packer-artifact/data.go b/datasource/hcp-packer-artifact/data.go index e1693ddb8aa..01200b40fe3 100644 --- a/datasource/hcp-packer-artifact/data.go +++ b/datasource/hcp-packer-artifact/data.go @@ -62,7 +62,7 @@ func (d *Datasource) ConfigSpec() hcldec.ObjectSpec { return d.config.FlatMapstructure().HCL2Spec() } -func (d *Datasource) Configure(raws ...interface{}) error { +func (d *Datasource) Configure(raws ...any) error { err := config.Decode(&d.config, nil, raws...) if err != nil { return err diff --git a/datasource/hcp-packer-image/data.go b/datasource/hcp-packer-image/data.go index db2ed1bb2c6..9bfbd9e5b0a 100644 --- a/datasource/hcp-packer-image/data.go +++ b/datasource/hcp-packer-image/data.go @@ -62,7 +62,7 @@ func (d *Datasource) ConfigSpec() hcldec.ObjectSpec { return d.config.FlatMapstructure().HCL2Spec() } -func (d *Datasource) Configure(raws ...interface{}) error { +func (d *Datasource) Configure(raws ...any) error { err := config.Decode(&d.config, nil, raws...) if err != nil { return err diff --git a/datasource/hcp-packer-iteration/data.go b/datasource/hcp-packer-iteration/data.go index d7241d7af8c..e6c7d872146 100644 --- a/datasource/hcp-packer-iteration/data.go +++ b/datasource/hcp-packer-iteration/data.go @@ -40,7 +40,7 @@ func (d *Datasource) ConfigSpec() hcldec.ObjectSpec { return d.config.FlatMapstructure().HCL2Spec() } -func (d *Datasource) Configure(raws ...interface{}) error { +func (d *Datasource) Configure(raws ...any) error { err := config.Decode(&d.config, nil, raws...) if err != nil { return err diff --git a/datasource/hcp-packer-version/data.go b/datasource/hcp-packer-version/data.go index 643d046afd0..b08fc31025b 100644 --- a/datasource/hcp-packer-version/data.go +++ b/datasource/hcp-packer-version/data.go @@ -37,7 +37,7 @@ func (d *Datasource) ConfigSpec() hcldec.ObjectSpec { return d.config.FlatMapstructure().HCL2Spec() } -func (d *Datasource) Configure(raws ...interface{}) error { +func (d *Datasource) Configure(raws ...any) error { err := config.Decode(&d.config, nil, raws...) if err != nil { return err diff --git a/datasource/http/data.go b/datasource/http/data.go index 10a8d9ce4e4..b2dc6bcac95 100644 --- a/datasource/http/data.go +++ b/datasource/http/data.go @@ -52,7 +52,7 @@ func (d *Datasource) ConfigSpec() hcldec.ObjectSpec { return d.config.FlatMapstructure().HCL2Spec() } -func (d *Datasource) Configure(raws ...interface{}) error { +func (d *Datasource) Configure(raws ...any) error { err := config.Decode(&d.config, nil, raws...) if err != nil { return err diff --git a/datasource/null/data.go b/datasource/null/data.go index 09eefee1edc..74a99f1afb7 100644 --- a/datasource/null/data.go +++ b/datasource/null/data.go @@ -34,7 +34,7 @@ func (d *Datasource) ConfigSpec() hcldec.ObjectSpec { return d.config.FlatMapstructure().HCL2Spec() } -func (d *Datasource) Configure(raws ...interface{}) error { +func (d *Datasource) Configure(raws ...any) error { err := config.Decode(&d.config, nil, raws...) if err != nil { return err diff --git a/fix/fixer.go b/fix/fixer.go index 73843daa113..e4c42c5494c 100644 --- a/fix/fixer.go +++ b/fix/fixer.go @@ -14,7 +14,7 @@ type Fixer interface { // Fix takes a raw map structure input, potentially transforms it // in some way, and returns the new, transformed structure. The // Fix method is allowed to mutate the input. - Fix(input map[string]interface{}) (map[string]interface{}, error) + Fix(input map[string]any) (map[string]any, error) // Synopsis returns a string description of what the fixer actually // does. diff --git a/fix/fixer_amazon_enhanced_networking.go b/fix/fixer_amazon_enhanced_networking.go index 68df7a1ddd7..52a481f03a0 100644 --- a/fix/fixer_amazon_enhanced_networking.go +++ b/fix/fixer_amazon_enhanced_networking.go @@ -19,10 +19,10 @@ func (FixerAmazonEnhancedNetworking) DeprecatedOptions() map[string][]string { } } -func (FixerAmazonEnhancedNetworking) Fix(input map[string]interface{}) (map[string]interface{}, error) { +func (FixerAmazonEnhancedNetworking) Fix(input map[string]any) (map[string]any, error) { // Our template type we'll use for this fixer only type template struct { - Builders []map[string]interface{} + Builders []map[string]any } // Decode the input into our structure, if we can diff --git a/fix/fixer_amazon_enhanced_networking_test.go b/fix/fixer_amazon_enhanced_networking_test.go index 1cc07c158a7..fef63cce6f9 100644 --- a/fix/fixer_amazon_enhanced_networking_test.go +++ b/fix/fixer_amazon_enhanced_networking_test.go @@ -14,17 +14,17 @@ func TestFixerAmazonEnhancedNetworking_Impl(t *testing.T) { func TestFixerAmazonEnhancedNetworking(t *testing.T) { cases := []struct { - Input map[string]interface{} - Expected map[string]interface{} + Input map[string]any + Expected map[string]any }{ // Attach field == false { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "amazon-ebs", "enhanced_networking": false, }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "amazon-ebs", "ena_support": false, }, @@ -32,12 +32,12 @@ func TestFixerAmazonEnhancedNetworking(t *testing.T) { // Attach field == true { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "amazon-ebs", "enhanced_networking": true, }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "amazon-ebs", "ena_support": true, }, @@ -47,12 +47,12 @@ func TestFixerAmazonEnhancedNetworking(t *testing.T) { for _, tc := range cases { var f FixerAmazonEnhancedNetworking - input := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Input}, + input := map[string]any{ + "builders": []map[string]any{tc.Input}, } - expected := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Expected}, + expected := map[string]any{ + "builders": []map[string]any{tc.Expected}, } output, err := f.Fix(input) diff --git a/fix/fixer_amazon_private_ip.go b/fix/fixer_amazon_private_ip.go index 897f3bf8542..0964bc18718 100644 --- a/fix/fixer_amazon_private_ip.go +++ b/fix/fixer_amazon_private_ip.go @@ -21,9 +21,9 @@ func (FixerAmazonPrivateIP) DeprecatedOptions() map[string][]string { } } -func (FixerAmazonPrivateIP) Fix(input map[string]interface{}) (map[string]interface{}, error) { +func (FixerAmazonPrivateIP) Fix(input map[string]any) (map[string]any, error) { type template struct { - Builders []map[string]interface{} + Builders []map[string]any } // Decode the input into our structure, if we can diff --git a/fix/fixer_amazon_private_ip_test.go b/fix/fixer_amazon_private_ip_test.go index 175211be12d..73867d75df7 100644 --- a/fix/fixer_amazon_private_ip_test.go +++ b/fix/fixer_amazon_private_ip_test.go @@ -14,17 +14,17 @@ func TestFixerAmazonPrivateIP_Impl(t *testing.T) { func TestFixerAmazonPrivateIP(t *testing.T) { cases := []struct { - Input map[string]interface{} - Expected map[string]interface{} + Input map[string]any + Expected map[string]any }{ // Attach field == false { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "amazon-ebs", "ssh_private_ip": false, }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "amazon-ebs", "ssh_interface": "public_ip", }, @@ -32,12 +32,12 @@ func TestFixerAmazonPrivateIP(t *testing.T) { // Attach field == true { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "amazon-ebs", "ssh_private_ip": true, }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "amazon-ebs", "ssh_interface": "private_ip", }, @@ -45,12 +45,12 @@ func TestFixerAmazonPrivateIP(t *testing.T) { // ssh_private_ip specified as string { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "amazon-ebs", "ssh_private_ip": "true", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "amazon-ebs", "ssh_interface": "private_ip", }, @@ -60,12 +60,12 @@ func TestFixerAmazonPrivateIP(t *testing.T) { for _, tc := range cases { var f FixerAmazonPrivateIP - input := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Input}, + input := map[string]any{ + "builders": []map[string]any{tc.Input}, } - expected := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Expected}, + expected := map[string]any{ + "builders": []map[string]any{tc.Expected}, } output, err := f.Fix(input) @@ -82,8 +82,8 @@ func TestFixerAmazonPrivateIP(t *testing.T) { func TestFixerAmazonPrivateIPNonBoolean(t *testing.T) { var f FixerAmazonPrivateIP - input := map[string]interface{}{ - "builders": []map[string]interface{}{{ + input := map[string]any{ + "builders": []map[string]any{{ "type": "amazon-ebs", "ssh_private_ip": "not-a-boolean-value", }}, diff --git a/fix/fixer_amazon_shutdown_behavior.go b/fix/fixer_amazon_shutdown_behavior.go index 2dc80ed9210..078c5c116c1 100644 --- a/fix/fixer_amazon_shutdown_behavior.go +++ b/fix/fixer_amazon_shutdown_behavior.go @@ -19,10 +19,10 @@ func (FixerAmazonShutdownBehavior) DeprecatedOptions() map[string][]string { } } -func (FixerAmazonShutdownBehavior) Fix(input map[string]interface{}) (map[string]interface{}, error) { +func (FixerAmazonShutdownBehavior) Fix(input map[string]any) (map[string]any, error) { // The type we'll decode into; we only care about builders type template struct { - Builders []map[string]interface{} + Builders []map[string]any } // Decode the input into our structure, if we can diff --git a/fix/fixer_amazon_shutdown_behavior_test.go b/fix/fixer_amazon_shutdown_behavior_test.go index 3b988b988e2..7fc219a8d87 100644 --- a/fix/fixer_amazon_shutdown_behavior_test.go +++ b/fix/fixer_amazon_shutdown_behavior_test.go @@ -14,28 +14,28 @@ func TestFixerAmazonShutdownBehavior(t *testing.T) { func TestFixerAmazonShutdownBehavior_Fix_shutdown_behaviour(t *testing.T) { cases := []struct { - Input map[string]interface{} - Expected map[string]interface{} + Input map[string]any + Expected map[string]any }{ // No shutdown_behaviour field { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "amazon-ebs", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "amazon-ebs", }, }, // shutdown_behaviour field { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "amazon-ebs", "shutdown_behaviour": "stop", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "amazon-ebs", "shutdown_behavior": "stop", }, @@ -45,12 +45,12 @@ func TestFixerAmazonShutdownBehavior_Fix_shutdown_behaviour(t *testing.T) { for _, tc := range cases { var f FixerAmazonShutdownBehavior - input := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Input}, + input := map[string]any{ + "builders": []map[string]any{tc.Input}, } - expected := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Expected}, + expected := map[string]any{ + "builders": []map[string]any{tc.Expected}, } output, err := f.Fix(input) diff --git a/fix/fixer_amazon_spot_price_product.go b/fix/fixer_amazon_spot_price_product.go index 8a66f3d7828..9e558ffa764 100644 --- a/fix/fixer_amazon_spot_price_product.go +++ b/fix/fixer_amazon_spot_price_product.go @@ -17,10 +17,10 @@ func (FixerAmazonSpotPriceProductDeprecation) DeprecatedOptions() map[string][]s } } -func (FixerAmazonSpotPriceProductDeprecation) Fix(input map[string]interface{}) (map[string]interface{}, error) { +func (FixerAmazonSpotPriceProductDeprecation) Fix(input map[string]any) (map[string]any, error) { // The type we'll decode into; we only care about builders type template struct { - Builders []map[string]interface{} + Builders []map[string]any } // Decode the input into our structure, if we can diff --git a/fix/fixer_amazon_temporary_security_group_cidrs.go b/fix/fixer_amazon_temporary_security_group_cidrs.go index 21bf0f25bd7..2dbf87bd879 100644 --- a/fix/fixer_amazon_temporary_security_group_cidrs.go +++ b/fix/fixer_amazon_temporary_security_group_cidrs.go @@ -17,10 +17,10 @@ func (FixerAmazonTemporarySecurityCIDRs) DeprecatedOptions() map[string][]string } } -func (FixerAmazonTemporarySecurityCIDRs) Fix(input map[string]interface{}) (map[string]interface{}, error) { +func (FixerAmazonTemporarySecurityCIDRs) Fix(input map[string]any) (map[string]any, error) { // Our template type we'll use for this fixer only type template struct { - Builders []map[string]interface{} + Builders []map[string]any } // Decode the input into our structure, if we can diff --git a/fix/fixer_amazon_temporary_security_group_cidrs_test.go b/fix/fixer_amazon_temporary_security_group_cidrs_test.go index 2de73fc8a6c..28710ba235c 100644 --- a/fix/fixer_amazon_temporary_security_group_cidrs_test.go +++ b/fix/fixer_amazon_temporary_security_group_cidrs_test.go @@ -14,16 +14,16 @@ func TestFixerAmazonTemporarySecurityCIDRs_Impl(t *testing.T) { func TestFixerAmazonTemporarySecurityCIDRs(t *testing.T) { cases := []struct { - Input map[string]interface{} - Expected map[string]interface{} + Input map[string]any + Expected map[string]any }{ { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "amazon-ebs", "temporary_security_group_source_cidr": "0.0.0.0/0", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "amazon-ebs", "temporary_security_group_source_cidrs": []string{"0.0.0.0/0"}, }, @@ -33,12 +33,12 @@ func TestFixerAmazonTemporarySecurityCIDRs(t *testing.T) { for _, tc := range cases { var f FixerAmazonTemporarySecurityCIDRs - input := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Input}, + input := map[string]any{ + "builders": []map[string]any{tc.Input}, } - expected := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Expected}, + expected := map[string]any{ + "builders": []map[string]any{tc.Expected}, } output, err := f.Fix(input) diff --git a/fix/fixer_azure_exclude_from_latest.go b/fix/fixer_azure_exclude_from_latest.go index 57221cede9f..61776b6b708 100644 --- a/fix/fixer_azure_exclude_from_latest.go +++ b/fix/fixer_azure_exclude_from_latest.go @@ -19,10 +19,10 @@ func (FixerAzureExcludeFromLatest) DeprecatedOptions() map[string][]string { } } -func (FixerAzureExcludeFromLatest) Fix(input map[string]interface{}) (map[string]interface{}, error) { +func (FixerAzureExcludeFromLatest) Fix(input map[string]any) (map[string]any, error) { // The type we'll decode into; we only care about builders type template struct { - Builders []map[string]interface{} + Builders []map[string]any } // Decode the input into our structure, if we can @@ -50,7 +50,7 @@ func (FixerAzureExcludeFromLatest) Fix(input map[string]interface{}) (map[string continue } - sharedImageDestination, ok := builder["shared_image_destination"].(map[string]interface{}) + sharedImageDestination, ok := builder["shared_image_destination"].(map[string]any) if !ok { continue } diff --git a/fix/fixer_azure_exclude_from_latest_test.go b/fix/fixer_azure_exclude_from_latest_test.go index 28fc5b86683..e14572e5323 100644 --- a/fix/fixer_azure_exclude_from_latest_test.go +++ b/fix/fixer_azure_exclude_from_latest_test.go @@ -14,32 +14,32 @@ func TestFixerAzureExcludeFromLatest(t *testing.T) { func TestFixerAzureExcludeFromLatest_Fix_exlude_from_latest(t *testing.T) { cases := []struct { - Input map[string]interface{} - Expected map[string]interface{} + Input map[string]any + Expected map[string]any }{ // No shared_image_destination field { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "azure-chroot", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "azure-chroot", }, }, // exlude_from_latest field { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "azure-chroot", - "shared_image_destination": map[string]interface{}{ + "shared_image_destination": map[string]any{ "exlude_from_latest": "false", }, }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "azure-chroot", - "shared_image_destination": map[string]interface{}{ + "shared_image_destination": map[string]any{ "exclude_from_latest": "false", }, }, @@ -49,12 +49,12 @@ func TestFixerAzureExcludeFromLatest_Fix_exlude_from_latest(t *testing.T) { for _, tc := range cases { var f FixerAzureExcludeFromLatest - input := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Input}, + input := map[string]any{ + "builders": []map[string]any{tc.Input}, } - expected := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Expected}, + expected := map[string]any{ + "builders": []map[string]any{tc.Expected}, } output, err := f.Fix(input) diff --git a/fix/fixer_clean_image_name.go b/fix/fixer_clean_image_name.go index 22803364856..6bb630f83fa 100644 --- a/fix/fixer_clean_image_name.go +++ b/fix/fixer_clean_image_name.go @@ -22,10 +22,10 @@ func (FixerCleanImageName) DeprecatedOptions() map[string][]string { } } -func (FixerCleanImageName) Fix(input map[string]interface{}) (map[string]interface{}, error) { +func (FixerCleanImageName) Fix(input map[string]any) (map[string]any, error) { // Our template type we'll use for this fixer only type template struct { - Builders []map[string]interface{} + Builders []map[string]any } // Decode the input into our structure, if we can @@ -48,7 +48,7 @@ func (FixerCleanImageName) Fix(input map[string]interface{}) (map[string]interfa v[k] = re.ReplaceAllString(v[k], "clean_resource_name") } builder[key] = v - case map[string]interface{}: + case map[string]any: for k := range v { if s, ok := v[k].(string); ok { v[k] = re.ReplaceAllString(s, "clean_resource_name") diff --git a/fix/fixer_clean_image_name_test.go b/fix/fixer_clean_image_name_test.go index 2f3a5205fab..80da8674635 100644 --- a/fix/fixer_clean_image_name_test.go +++ b/fix/fixer_clean_image_name_test.go @@ -10,8 +10,7 @@ import ( ) func TestFixerCleanImageName_Impl(t *testing.T) { - var raw interface{} - raw = new(FixerCleanImageName) + var raw any = new(FixerCleanImageName) if _, ok := raw.(Fixer); !ok { t.Fatalf("must be a Fixer") } @@ -20,24 +19,24 @@ func TestFixerCleanImageName_Impl(t *testing.T) { func TestFixerCleanImageName_Fix(t *testing.T) { var f FixerCleanImageName - input := map[string]interface{}{ - "builders": []interface{}{ - map[string]interface{}{ + input := map[string]any{ + "builders": []any{ + map[string]any{ "type": "foo", "ami_name": "heyo clean_image_name", - "image_labels": map[string]interface{}{ + "image_labels": map[string]any{ "name": "test-packer-{{packer_version | clean_image_name}}", }, }, }, } - expected := map[string]interface{}{ - "builders": []map[string]interface{}{ + expected := map[string]any{ + "builders": []map[string]any{ { "type": "foo", "ami_name": "heyo clean_resource_name", - "image_labels": map[string]interface{}{ + "image_labels": map[string]any{ "name": "test-packer-{{packer_version | clean_resource_name}}", }, }, diff --git a/fix/fixer_comm_config.go b/fix/fixer_comm_config.go index af4c3e3f09e..41e1d22e054 100644 --- a/fix/fixer_comm_config.go +++ b/fix/fixer_comm_config.go @@ -20,9 +20,9 @@ func (FixerCommConfig) DeprecatedOptions() map[string][]string { } } -func (FixerCommConfig) Fix(input map[string]interface{}) (map[string]interface{}, error) { +func (FixerCommConfig) Fix(input map[string]any) (map[string]any, error) { type template struct { - Builders []interface{} + Builders []any } // Decode the input into our structure, if we can @@ -32,7 +32,7 @@ func (FixerCommConfig) Fix(input map[string]interface{}) (map[string]interface{} } for i, raw := range tpl.Builders { - var builders map[string]interface{} + var builders map[string]any if err := mapstructure.Decode(raw, &builders); err != nil { // Ignore errors, could be a non-map continue diff --git a/fix/fixer_comm_config_test.go b/fix/fixer_comm_config_test.go index 390a6909e24..78826aebe20 100644 --- a/fix/fixer_comm_config_test.go +++ b/fix/fixer_comm_config_test.go @@ -14,17 +14,17 @@ func TestFixerCommConfig_Impl(t *testing.T) { func TestFixerCommConfig_Fix(t *testing.T) { cases := []struct { - Input map[string]interface{} - Expected map[string]interface{} + Input map[string]any + Expected map[string]any }{ // set host_port_min { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "virtualbox-iso", "host_port_min": 2222, }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "virtualbox-iso", "host_port_min": 2222, }, @@ -32,12 +32,12 @@ func TestFixerCommConfig_Fix(t *testing.T) { // set ssh_host_port_min (old key) { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "virtualbox-ovf", "ssh_host_port_min": 2222, }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "virtualbox-ovf", "host_port_min": 2222, }, @@ -46,13 +46,13 @@ func TestFixerCommConfig_Fix(t *testing.T) { // set ssh_host_port_min and host_port_min // host_port_min takes precedence { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "virtualbox-vm", "ssh_host_port_min": 1234, "host_port_min": 4321, }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "virtualbox-vm", "host_port_min": 4321, }, @@ -60,12 +60,12 @@ func TestFixerCommConfig_Fix(t *testing.T) { // set host_port_max { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "virtualbox-iso", "host_port_max": 4444, }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "virtualbox-iso", "host_port_max": 4444, }, @@ -73,12 +73,12 @@ func TestFixerCommConfig_Fix(t *testing.T) { // set ssh_host_port_max (old key) { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "virtualbox-iso", "ssh_host_port_max": 4444, }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "virtualbox-iso", "host_port_max": 4444, }, @@ -87,13 +87,13 @@ func TestFixerCommConfig_Fix(t *testing.T) { // set ssh_host_port_max and host_port_max // host_port_max takes precedence { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "virtualbox-vm", "ssh_host_port_max": 1234, "host_port_max": 4321, }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "virtualbox-vm", "host_port_max": 4321, }, @@ -101,12 +101,12 @@ func TestFixerCommConfig_Fix(t *testing.T) { // set skip_nat_mapping { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "virtualbox-vm", "skip_nat_mapping": true, }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "virtualbox-vm", "skip_nat_mapping": true, }, @@ -114,12 +114,12 @@ func TestFixerCommConfig_Fix(t *testing.T) { // set ssh_skip_nat_mapping (old key) { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "virtualbox-vm", "ssh_skip_nat_mapping": true, }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "virtualbox-vm", "skip_nat_mapping": true, }, @@ -128,13 +128,13 @@ func TestFixerCommConfig_Fix(t *testing.T) { // set ssh_skip_nat_mapping and skip_nat_mapping // skip_nat_mapping takes precedence { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "virtualbox-iso", "ssh_skip_nat_mapping": false, "skip_nat_mapping": true, }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "virtualbox-iso", "skip_nat_mapping": true, }, @@ -144,12 +144,12 @@ func TestFixerCommConfig_Fix(t *testing.T) { for _, tc := range cases { var f FixerCommConfig - input := map[string]interface{}{ - "builders": []interface{}{tc.Input}, + input := map[string]any{ + "builders": []any{tc.Input}, } - expected := map[string]interface{}{ - "builders": []interface{}{tc.Expected}, + expected := map[string]any{ + "builders": []any{tc.Expected}, } output, err := f.Fix(input) diff --git a/fix/fixer_createtime.go b/fix/fixer_createtime.go index 98cc014ec44..36232a050b8 100644 --- a/fix/fixer_createtime.go +++ b/fix/fixer_createtime.go @@ -17,10 +17,10 @@ func (FixerCreateTime) DeprecatedOptions() map[string][]string { return map[string][]string{} } -func (FixerCreateTime) Fix(input map[string]interface{}) (map[string]interface{}, error) { +func (FixerCreateTime) Fix(input map[string]any) (map[string]any, error) { // Our template type we'll use for this fixer only type template struct { - Builders []map[string]interface{} + Builders []map[string]any } // Decode the input into our structure, if we can diff --git a/fix/fixer_createtime_test.go b/fix/fixer_createtime_test.go index f707a8a3910..d9fef9287d4 100644 --- a/fix/fixer_createtime_test.go +++ b/fix/fixer_createtime_test.go @@ -9,8 +9,7 @@ import ( ) func TestFixerCreateTime_Impl(t *testing.T) { - var raw interface{} - raw = new(FixerCreateTime) + var raw any = new(FixerCreateTime) if _, ok := raw.(Fixer); !ok { t.Fatalf("must be a Fixer") } @@ -19,8 +18,8 @@ func TestFixerCreateTime_Impl(t *testing.T) { func TestFixerCreateTime_Fix(t *testing.T) { var f FixerCreateTime - input := map[string]interface{}{ - "builders": []interface{}{ + input := map[string]any{ + "builders": []any{ map[string]string{ "type": "foo", "ami_name": "{{.CreateTime}} foo", @@ -28,8 +27,8 @@ func TestFixerCreateTime_Fix(t *testing.T) { }, } - expected := map[string]interface{}{ - "builders": []map[string]interface{}{ + expected := map[string]any{ + "builders": []map[string]any{ { "type": "foo", "ami_name": "{{timestamp}} foo", diff --git a/fix/fixer_docker_email.go b/fix/fixer_docker_email.go index 2c94be62ac8..b4d4e5bc761 100644 --- a/fix/fixer_docker_email.go +++ b/fix/fixer_docker_email.go @@ -15,14 +15,14 @@ func (FixerDockerEmail) DeprecatedOptions() map[string][]string { } -func (FixerDockerEmail) Fix(input map[string]interface{}) (map[string]interface{}, error) { +func (FixerDockerEmail) Fix(input map[string]any) (map[string]any, error) { if input["post-processors"] == nil { return input, nil } // Our template type we'll use for this fixer only type template struct { - Builders []map[string]interface{} + Builders []map[string]any PP `mapstructure:",squash"` } diff --git a/fix/fixer_galaxy_command.go b/fix/fixer_galaxy_command.go index 98285b2f734..7e9f8b7368e 100644 --- a/fix/fixer_galaxy_command.go +++ b/fix/fixer_galaxy_command.go @@ -17,9 +17,9 @@ func (FixerGalaxyCommand) DeprecatedOptions() map[string][]string { } } -func (FixerGalaxyCommand) Fix(input map[string]interface{}) (map[string]interface{}, error) { +func (FixerGalaxyCommand) Fix(input map[string]any) (map[string]any, error) { type template struct { - Provisioners []interface{} + Provisioners []any } // Decode the input into our structure, if we can @@ -29,7 +29,7 @@ func (FixerGalaxyCommand) Fix(input map[string]interface{}) (map[string]interfac } for i, raw := range tpl.Provisioners { - var provisioners map[string]interface{} + var provisioners map[string]any if err := mapstructure.Decode(raw, &provisioners); err != nil { // Ignore errors, could be a non-map continue diff --git a/fix/fixer_galaxy_command_test.go b/fix/fixer_galaxy_command_test.go index c28e4ff864f..dd6b50d7d60 100644 --- a/fix/fixer_galaxy_command_test.go +++ b/fix/fixer_galaxy_command_test.go @@ -14,17 +14,17 @@ func TestFixerGalaxyCommand_Impl(t *testing.T) { func TestFixerGalaxyCommand_Fix(t *testing.T) { cases := []struct { - Input map[string]interface{} - Expected map[string]interface{} + Input map[string]any + Expected map[string]any }{ // set galaxy_command { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "ansible-local", "galaxy_command": "/usr/local/bin/ansible-galaxy", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "ansible-local", "galaxy_command": "/usr/local/bin/ansible-galaxy", }, @@ -32,12 +32,12 @@ func TestFixerGalaxyCommand_Fix(t *testing.T) { // set galaxycommand (old key) { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "ansible-local", "galaxycommand": "/usr/bin/ansible-galaxy", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "ansible-local", "galaxy_command": "/usr/bin/ansible-galaxy", }, @@ -46,13 +46,13 @@ func TestFixerGalaxyCommand_Fix(t *testing.T) { // set galaxy_command and galaxycommand // galaxy_command takes precedence { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "ansible-local", "galaxy_command": "ansible_galaxy_command", "galaxycommand": "ansible_galaxycommand", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "ansible-local", "galaxy_command": "ansible_galaxy_command", }, @@ -62,12 +62,12 @@ func TestFixerGalaxyCommand_Fix(t *testing.T) { for _, tc := range cases { var f FixerGalaxyCommand - input := map[string]interface{}{ - "provisioners": []interface{}{tc.Input}, + input := map[string]any{ + "provisioners": []any{tc.Input}, } - expected := map[string]interface{}{ - "provisioners": []interface{}{tc.Expected}, + expected := map[string]any{ + "provisioners": []any{tc.Expected}, } output, err := f.Fix(input) diff --git a/fix/fixer_hyperv_cpu_and_ram_naming.go b/fix/fixer_hyperv_cpu_and_ram_naming.go index 757cfaf6bdd..ba4f5c6a157 100644 --- a/fix/fixer_hyperv_cpu_and_ram_naming.go +++ b/fix/fixer_hyperv_cpu_and_ram_naming.go @@ -16,10 +16,10 @@ func (FizerHypervCPUandRAM) DeprecatedOptions() map[string][]string { } } -func (FizerHypervCPUandRAM) Fix(input map[string]interface{}) (map[string]interface{}, error) { +func (FizerHypervCPUandRAM) Fix(input map[string]any) (map[string]any, error) { // The type we'll decode into; we only care about builders type template struct { - Builders []map[string]interface{} + Builders []map[string]any } // Decode the input into our structure, if we can diff --git a/fix/fixer_hyperv_deprecations.go b/fix/fixer_hyperv_deprecations.go index b7a0ce2aeea..24b872e2fc3 100644 --- a/fix/fixer_hyperv_deprecations.go +++ b/fix/fixer_hyperv_deprecations.go @@ -17,10 +17,10 @@ func (FixerHypervDeprecations) DeprecatedOptions() map[string][]string { } } -func (FixerHypervDeprecations) Fix(input map[string]interface{}) (map[string]interface{}, error) { +func (FixerHypervDeprecations) Fix(input map[string]any) (map[string]any, error) { // The type we'll decode into; we only care about builders type template struct { - Builders []map[string]interface{} + Builders []map[string]any } // Decode the input into our structure, if we can diff --git a/fix/fixer_hyperv_deprecations_test.go b/fix/fixer_hyperv_deprecations_test.go index 7f3dee17a41..ded337e1682 100644 --- a/fix/fixer_hyperv_deprecations_test.go +++ b/fix/fixer_hyperv_deprecations_test.go @@ -15,28 +15,28 @@ func TestFixerHypervDeprecations_impl(t *testing.T) { func TestFixerHypervDeprecations_Fix(t *testing.T) { cases := []struct { - Input map[string]interface{} - Expected map[string]interface{} + Input map[string]any + Expected map[string]any }{ // No vhd_temp_path field in template - noop { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "hyperv-iso", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "hyperv-iso", }, }, // Deprecated vhd_temp_path field in template should be deleted { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "hyperv-iso", "vhd_temp_path": "foopath", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "hyperv-iso", }, }, @@ -45,12 +45,12 @@ func TestFixerHypervDeprecations_Fix(t *testing.T) { for _, tc := range cases { var f FixerHypervDeprecations - input := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Input}, + input := map[string]any{ + "builders": []map[string]any{tc.Input}, } - expected := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Expected}, + expected := map[string]any{ + "builders": []map[string]any{tc.Expected}, } output, err := f.Fix(input) diff --git a/fix/fixer_hyperv_vmxc_typo.go b/fix/fixer_hyperv_vmxc_typo.go index 135c601afc0..413fd2449df 100644 --- a/fix/fixer_hyperv_vmxc_typo.go +++ b/fix/fixer_hyperv_vmxc_typo.go @@ -17,10 +17,10 @@ func (FixerHypervVmxcTypo) DeprecatedOptions() map[string][]string { } } -func (FixerHypervVmxcTypo) Fix(input map[string]interface{}) (map[string]interface{}, error) { +func (FixerHypervVmxcTypo) Fix(input map[string]any) (map[string]any, error) { // The type we'll decode into; we only care about builders type template struct { - Builders []map[string]interface{} + Builders []map[string]any } // Decode the input into our structure, if we can diff --git a/fix/fixer_hyperv_vmxc_typo_test.go b/fix/fixer_hyperv_vmxc_typo_test.go index 4366820b2f2..121e67f0303 100644 --- a/fix/fixer_hyperv_vmxc_typo_test.go +++ b/fix/fixer_hyperv_vmxc_typo_test.go @@ -15,17 +15,17 @@ func TestFixerHypervVmxcTypo_impl(t *testing.T) { func TestFixerHypervVmxcTypo_Fix(t *testing.T) { cases := []struct { - Input map[string]interface{} - Expected map[string]interface{} + Input map[string]any + Expected map[string]any }{ // No "clone_from_vmxc_path" in template - noop { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "hyperv-vmcx", "temp_path": "C:/some/temp/path", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "hyperv-vmcx", "temp_path": "C:/some/temp/path", }, @@ -34,12 +34,12 @@ func TestFixerHypervVmxcTypo_Fix(t *testing.T) { // "clone_from_vmxc_path" should be replaced with // "clone_from_vmcx_path" in template { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "hyperv-vmcx", "clone_from_vmxc_path": "C:/some/vmcx/path", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "hyperv-vmcx", "clone_from_vmcx_path": "C:/some/vmcx/path", }, @@ -49,12 +49,12 @@ func TestFixerHypervVmxcTypo_Fix(t *testing.T) { for _, tc := range cases { var f FixerHypervVmxcTypo - input := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Input}, + input := map[string]any{ + "builders": []map[string]any{tc.Input}, } - expected := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Expected}, + expected := map[string]any{ + "builders": []map[string]any{tc.Expected}, } output, err := f.Fix(input) diff --git a/fix/fixer_iso_checksum_type_and_url.go b/fix/fixer_iso_checksum_type_and_url.go index fd22749211c..09c308d0060 100644 --- a/fix/fixer_iso_checksum_type_and_url.go +++ b/fix/fixer_iso_checksum_type_and_url.go @@ -17,10 +17,10 @@ func (FixerISOChecksumTypeAndURL) DeprecatedOptions() map[string][]string { } } -func (FixerISOChecksumTypeAndURL) Fix(input map[string]interface{}) (map[string]interface{}, error) { +func (FixerISOChecksumTypeAndURL) Fix(input map[string]any) (map[string]any, error) { // Our template type we'll use for this fixer only type template struct { - Builders []map[string]interface{} + Builders []map[string]any } // Decode the input into our structure, if we can @@ -52,7 +52,7 @@ func (FixerISOChecksumTypeAndURL) Fix(input map[string]interface{}) (map[string] return input, nil } -func stringValue(v interface{}) string { +func stringValue(v any) string { switch rfl := v.(type) { case string: return rfl diff --git a/fix/fixer_iso_checksum_type_and_url_test.go b/fix/fixer_iso_checksum_type_and_url_test.go index 4cd0b29a353..27ea299a65f 100644 --- a/fix/fixer_iso_checksum_type_and_url_test.go +++ b/fix/fixer_iso_checksum_type_and_url_test.go @@ -10,8 +10,7 @@ import ( ) func TestFixerISOChecksumTypeAndURL_Impl(t *testing.T) { - var raw interface{} - raw = new(FixerISOChecksumTypeAndURL) + var raw any = new(FixerISOChecksumTypeAndURL) if _, ok := raw.(Fixer); !ok { t.Fatalf("must be a Fixer") } @@ -20,44 +19,44 @@ func TestFixerISOChecksumTypeAndURL_Impl(t *testing.T) { func TestFixerISOChecksumTypeAndURL_Fix(t *testing.T) { cases := []struct { - Input map[string]interface{} - Expected map[string]interface{} + Input map[string]any + Expected map[string]any }{ { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "foo", "iso_checksum_url": "bar", "iso_checksum_type": "ignored", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "foo", "iso_checksum": "file:bar", }, }, { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "foo", "iso_checksum": "checksum", "iso_checksum_type": "md5", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "foo", "iso_checksum": "md5:checksum", }, }, { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "foo", "iso_checksum": "checksum", "iso_checksum_url": "path/to/checksumfile", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "foo", "iso_checksum": "file:path/to/checksumfile", }, @@ -67,12 +66,12 @@ func TestFixerISOChecksumTypeAndURL_Fix(t *testing.T) { for _, tc := range cases { var f FixerISOChecksumTypeAndURL - input := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Input}, + input := map[string]any{ + "builders": []map[string]any{tc.Input}, } - expected := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Expected}, + expected := map[string]any{ + "builders": []map[string]any{tc.Expected}, } output, err := f.Fix(input) diff --git a/fix/fixer_iso_md5.go b/fix/fixer_iso_md5.go index dcadd15404d..369f9f663f4 100644 --- a/fix/fixer_iso_md5.go +++ b/fix/fixer_iso_md5.go @@ -17,10 +17,10 @@ func (FixerISOMD5) DeprecatedOptions() map[string][]string { } } -func (FixerISOMD5) Fix(input map[string]interface{}) (map[string]interface{}, error) { +func (FixerISOMD5) Fix(input map[string]any) (map[string]any, error) { // Our template type we'll use for this fixer only type template struct { - Builders []map[string]interface{} + Builders []map[string]any } // Decode the input into our structure, if we can diff --git a/fix/fixer_iso_md5_test.go b/fix/fixer_iso_md5_test.go index 25fb55dd65f..dff7e35a2af 100644 --- a/fix/fixer_iso_md5_test.go +++ b/fix/fixer_iso_md5_test.go @@ -9,8 +9,7 @@ import ( ) func TestFixerISOMD5_Impl(t *testing.T) { - var raw interface{} - raw = new(FixerISOMD5) + var raw any = new(FixerISOMD5) if _, ok := raw.(Fixer); !ok { t.Fatalf("must be a Fixer") } @@ -19,8 +18,8 @@ func TestFixerISOMD5_Impl(t *testing.T) { func TestFixerISOMD5_Fix(t *testing.T) { var f FixerISOMD5 - input := map[string]interface{}{ - "builders": []interface{}{ + input := map[string]any{ + "builders": []any{ map[string]string{ "type": "foo", "iso_md5": "bar", @@ -28,8 +27,8 @@ func TestFixerISOMD5_Fix(t *testing.T) { }, } - expected := map[string]interface{}{ - "builders": []map[string]interface{}{ + expected := map[string]any{ + "builders": []map[string]any{ { "type": "foo", "iso_checksum": "bar", diff --git a/fix/fixer_parallels_deprecations.go b/fix/fixer_parallels_deprecations.go index bd7b926f461..e1530c21dd5 100644 --- a/fix/fixer_parallels_deprecations.go +++ b/fix/fixer_parallels_deprecations.go @@ -18,10 +18,10 @@ func (FixerParallelsDeprecations) DeprecatedOptions() map[string][]string { } } -func (FixerParallelsDeprecations) Fix(input map[string]interface{}) (map[string]interface{}, error) { +func (FixerParallelsDeprecations) Fix(input map[string]any) (map[string]any, error) { // The type we'll decode into; we only care about builders type template struct { - Builders []map[string]interface{} + Builders []map[string]any } // Decode the input into our structure, if we can diff --git a/fix/fixer_parallels_deprecations_test.go b/fix/fixer_parallels_deprecations_test.go index 90fc70b4f35..f3c975d19b0 100644 --- a/fix/fixer_parallels_deprecations_test.go +++ b/fix/fixer_parallels_deprecations_test.go @@ -14,28 +14,28 @@ func TestFixerParallelsDeprecations(t *testing.T) { func TestFixerParallelsDeprecations_Fix_parallels_tools_guest_path(t *testing.T) { cases := []struct { - Input map[string]interface{} - Expected map[string]interface{} + Input map[string]any + Expected map[string]any }{ // No parallels_tools_host_path field { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "parallels-iso", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "parallels-iso", }, }, // parallels_tools_host_path field { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "parallels-iso", "parallels_tools_host_path": "/Path...", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "parallels-iso", }, }, @@ -44,12 +44,12 @@ func TestFixerParallelsDeprecations_Fix_parallels_tools_guest_path(t *testing.T) for _, tc := range cases { var f FixerParallelsDeprecations - input := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Input}, + input := map[string]any{ + "builders": []map[string]any{tc.Input}, } - expected := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Expected}, + expected := map[string]any{ + "builders": []map[string]any{tc.Expected}, } output, err := f.Fix(input) @@ -65,17 +65,17 @@ func TestFixerParallelsDeprecations_Fix_parallels_tools_guest_path(t *testing.T) func TestFixerParallelsDeprecations_Fix_guest_os_distribution(t *testing.T) { cases := []struct { - Input map[string]interface{} - Expected map[string]interface{} + Input map[string]any + Expected map[string]any }{ // No guest_os_distribution field { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "parallels-iso", "guest_os_type": "ubuntu", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "parallels-iso", "guest_os_type": "ubuntu", }, @@ -83,13 +83,13 @@ func TestFixerParallelsDeprecations_Fix_guest_os_distribution(t *testing.T) { // guest_os_distribution and guest_os_type field { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "parallels-iso", "guest_os_type": "linux", "guest_os_distribution": "ubuntu", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "parallels-iso", "guest_os_type": "ubuntu", }, @@ -97,12 +97,12 @@ func TestFixerParallelsDeprecations_Fix_guest_os_distribution(t *testing.T) { // guest_os_distribution but no guest_os_type field { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "parallels-iso", "guest_os_distribution": "ubuntu", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "parallels-iso", "guest_os_type": "ubuntu", }, @@ -112,12 +112,12 @@ func TestFixerParallelsDeprecations_Fix_guest_os_distribution(t *testing.T) { for _, tc := range cases { var f FixerParallelsDeprecations - input := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Input}, + input := map[string]any{ + "builders": []map[string]any{tc.Input}, } - expected := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Expected}, + expected := map[string]any{ + "builders": []map[string]any{tc.Expected}, } output, err := f.Fix(input) diff --git a/fix/fixer_parallels_headless.go b/fix/fixer_parallels_headless.go index eececc03499..507c1e03fe8 100644 --- a/fix/fixer_parallels_headless.go +++ b/fix/fixer_parallels_headless.go @@ -16,10 +16,10 @@ func (FixerParallelsHeadless) DeprecatedOptions() map[string][]string { } } -func (FixerParallelsHeadless) Fix(input map[string]interface{}) (map[string]interface{}, error) { +func (FixerParallelsHeadless) Fix(input map[string]any) (map[string]any, error) { // The type we'll decode into; we only care about builders type template struct { - Builders []map[string]interface{} + Builders []map[string]any } // Decode the input into our structure, if we can diff --git a/fix/fixer_parallels_headless_test.go b/fix/fixer_parallels_headless_test.go index 5b711c169b8..2d8289ecc51 100644 --- a/fix/fixer_parallels_headless_test.go +++ b/fix/fixer_parallels_headless_test.go @@ -14,28 +14,28 @@ func TestFixerParallelsHeadless_Impl(t *testing.T) { func TestFixerParallelsHeadless_Fix(t *testing.T) { cases := []struct { - Input map[string]interface{} - Expected map[string]interface{} + Input map[string]any + Expected map[string]any }{ // No headless field { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "parallels-iso", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "parallels-iso", }, }, // Headless field { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "parallels-iso", "headless": false, }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "parallels-iso", }, }, @@ -44,12 +44,12 @@ func TestFixerParallelsHeadless_Fix(t *testing.T) { for _, tc := range cases { var f FixerParallelsHeadless - input := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Input}, + input := map[string]any{ + "builders": []map[string]any{tc.Input}, } - expected := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Expected}, + expected := map[string]any{ + "builders": []map[string]any{tc.Expected}, } output, err := f.Fix(input) diff --git a/fix/fixer_powershell_escapes.go b/fix/fixer_powershell_escapes.go index 59175e65362..8db5e79a249 100644 --- a/fix/fixer_powershell_escapes.go +++ b/fix/fixer_powershell_escapes.go @@ -17,9 +17,9 @@ func (FixerPowerShellEscapes) DeprecatedOptions() map[string][]string { return map[string][]string{} } -func (FixerPowerShellEscapes) Fix(input map[string]interface{}) (map[string]interface{}, error) { +func (FixerPowerShellEscapes) Fix(input map[string]any) (map[string]any, error) { type template struct { - Provisioners []interface{} + Provisioners []any } var psUnescape = strings.NewReplacer( @@ -36,7 +36,7 @@ func (FixerPowerShellEscapes) Fix(input map[string]interface{}) (map[string]inte } for i, raw := range tpl.Provisioners { - var provisioners map[string]interface{} + var provisioners map[string]any if err := mapstructure.Decode(raw, &provisioners); err != nil { // Ignore errors, could be a non-map continue @@ -57,7 +57,7 @@ func (FixerPowerShellEscapes) Fix(input map[string]interface{}) (map[string]inte if err := mapstructure.Decode(raw, &env_vars); err != nil { continue } - env_vars_unescaped := make([]interface{}, len(env_vars)) + env_vars_unescaped := make([]any, len(env_vars)) for j, env_var := range env_vars { env_vars_unescaped[j] = psUnescape.Replace(env_var) } diff --git a/fix/fixer_pp_docker_tag_tags.go b/fix/fixer_pp_docker_tag_tags.go index 4399a366c6a..125cb96a38c 100644 --- a/fix/fixer_pp_docker_tag_tags.go +++ b/fix/fixer_pp_docker_tag_tags.go @@ -18,7 +18,7 @@ func (FixerDockerTagtoTags) DeprecatedOptions() map[string][]string { } } -func (FixerDockerTagtoTags) Fix(input map[string]interface{}) (map[string]interface{}, error) { +func (FixerDockerTagtoTags) Fix(input map[string]any) (map[string]any, error) { if input["post-processors"] == nil { return input, nil } @@ -56,7 +56,7 @@ func (FixerDockerTagtoTags) Fix(input map[string]interface{}) (map[string]interf if ok { // Gather all "tag" into the []string switch t := tagRaw.(type) { - case []interface{}: + case []any: for _, tag := range t { allTags = append(allTags, tag.(string)) } @@ -75,7 +75,7 @@ func (FixerDockerTagtoTags) Fix(input map[string]interface{}) (map[string]interf if ok { // Gather all "tag" into the []string switch t := tagsRaw.(type) { - case []interface{}: + case []any: for _, tag := range t { allTags = append(allTags, tag.(string)) } diff --git a/fix/fixer_pp_docker_tag_tags_test.go b/fix/fixer_pp_docker_tag_tags_test.go index 02de59516ad..b59ae2b8c84 100644 --- a/fix/fixer_pp_docker_tag_tags_test.go +++ b/fix/fixer_pp_docker_tag_tags_test.go @@ -16,15 +16,15 @@ func TestFixerDockerTags(t *testing.T) { func TestFixerDockerTags_Fix(t *testing.T) { var f FixerDockerTagtoTags - input := map[string]interface{}{ - "post-processors": []interface{}{ - map[string]interface{}{ + input := map[string]any{ + "post-processors": []any{ + map[string]any{ "type": "docker-tag", "tag": "foo", "tags": []string{"foo", "bar"}, }, - []interface{}{ - map[string]interface{}{ + []any{ + map[string]any{ "type": "docker-tag", "tag": []string{"baz"}, "tags": []string{"foo", "bar"}, @@ -33,14 +33,14 @@ func TestFixerDockerTags_Fix(t *testing.T) { }, } - expected := map[string]interface{}{ - "post-processors": []interface{}{ - map[string]interface{}{ + expected := map[string]any{ + "post-processors": []any{ + map[string]any{ "type": "docker-tag", "tags": []string{"foo", "bar"}, }, - []interface{}{ - map[string]interface{}{ + []any{ + map[string]any{ "type": "docker-tag", "tags": []string{"baz", "foo", "bar"}, }, diff --git a/fix/fixer_pp_manifest_filename.go b/fix/fixer_pp_manifest_filename.go index 8dab6df89d4..cc289de084a 100644 --- a/fix/fixer_pp_manifest_filename.go +++ b/fix/fixer_pp_manifest_filename.go @@ -16,7 +16,7 @@ func (FixerManifestFilename) DeprecatedOptions() map[string][]string { } } -func (FixerManifestFilename) Fix(input map[string]interface{}) (map[string]interface{}, error) { +func (FixerManifestFilename) Fix(input map[string]any) (map[string]any, error) { if input["post-processors"] == nil { return input, nil } diff --git a/fix/fixer_pp_manifest_filename_test.go b/fix/fixer_pp_manifest_filename_test.go index 4c1712cc629..326a8569fa6 100644 --- a/fix/fixer_pp_manifest_filename_test.go +++ b/fix/fixer_pp_manifest_filename_test.go @@ -16,14 +16,14 @@ func TestFixerManifestPPFilename_Impl(t *testing.T) { func TestFixerManifestPPFilename_Fix(t *testing.T) { var f FixerManifestFilename - input := map[string]interface{}{ - "post-processors": []interface{}{ - map[string]interface{}{ + input := map[string]any{ + "post-processors": []any{ + map[string]any{ "type": "manifest", "filename": "foo", }, - []interface{}{ - map[string]interface{}{ + []any{ + map[string]any{ "type": "manifest", "filename": "foo", }, @@ -31,14 +31,14 @@ func TestFixerManifestPPFilename_Fix(t *testing.T) { }, } - expected := map[string]interface{}{ - "post-processors": []interface{}{ - map[string]interface{}{ + expected := map[string]any{ + "post-processors": []any{ + map[string]any{ "type": "manifest", "output": "foo", }, - []interface{}{ - map[string]interface{}{ + []any{ + map[string]any{ "type": "manifest", "output": "foo", }, diff --git a/fix/fixer_pp_vagrant_override.go b/fix/fixer_pp_vagrant_override.go index d139740fc52..5571a4092fe 100644 --- a/fix/fixer_pp_vagrant_override.go +++ b/fix/fixer_pp_vagrant_override.go @@ -14,7 +14,7 @@ func (FixerVagrantPPOverride) DeprecatedOptions() map[string][]string { return map[string][]string{} } -func (FixerVagrantPPOverride) Fix(input map[string]interface{}) (map[string]interface{}, error) { +func (FixerVagrantPPOverride) Fix(input map[string]any) (map[string]any, error) { if input["post-processors"] == nil { return input, nil } @@ -46,7 +46,7 @@ func (FixerVagrantPPOverride) Fix(input map[string]interface{}) (map[string]inte continue } - overrides := make(map[string]interface{}) + overrides := make(map[string]any) for _, name := range possible { if _, ok := pp[name]; !ok { continue diff --git a/fix/fixer_pp_vagrant_override_test.go b/fix/fixer_pp_vagrant_override_test.go index ad666c99f1e..ef12ee3f787 100644 --- a/fix/fixer_pp_vagrant_override_test.go +++ b/fix/fixer_pp_vagrant_override_test.go @@ -16,25 +16,25 @@ func TestFixerVagrantPPOverride_Impl(t *testing.T) { func TestFixerVagrantPPOverride_Fix(t *testing.T) { var f FixerVagrantPPOverride - input := map[string]interface{}{ - "post-processors": []interface{}{ + input := map[string]any{ + "post-processors": []any{ "foo", - map[string]interface{}{ + map[string]any{ "type": "vagrant", - "aws": map[string]interface{}{ + "aws": map[string]any{ "foo": "bar", }, }, - map[string]interface{}{ + map[string]any{ "type": "vsphere", }, - []interface{}{ - map[string]interface{}{ + []any{ + map[string]any{ "type": "vagrant", - "vmware": map[string]interface{}{ + "vmware": map[string]any{ "foo": "bar", }, }, @@ -42,28 +42,28 @@ func TestFixerVagrantPPOverride_Fix(t *testing.T) { }, } - expected := map[string]interface{}{ - "post-processors": []interface{}{ + expected := map[string]any{ + "post-processors": []any{ "foo", - map[string]interface{}{ + map[string]any{ "type": "vagrant", - "override": map[string]interface{}{ - "aws": map[string]interface{}{ + "override": map[string]any{ + "aws": map[string]any{ "foo": "bar", }, }, }, - map[string]interface{}{ + map[string]any{ "type": "vsphere", }, - []interface{}{ - map[string]interface{}{ + []any{ + map[string]any{ "type": "vagrant", - "override": map[string]interface{}{ - "vmware": map[string]interface{}{ + "override": map[string]any{ + "vmware": map[string]any{ "foo": "bar", }, }, diff --git a/fix/fixer_proxmox_type.go b/fix/fixer_proxmox_type.go index e43c0044a50..7185b9d7ff7 100644 --- a/fix/fixer_proxmox_type.go +++ b/fix/fixer_proxmox_type.go @@ -14,9 +14,9 @@ func (FixerProxmoxType) DeprecatedOptions() map[string][]string { return map[string][]string{} } -func (FixerProxmoxType) Fix(input map[string]interface{}) (map[string]interface{}, error) { +func (FixerProxmoxType) Fix(input map[string]any) (map[string]any, error) { type template struct { - Builders []map[string]interface{} + Builders []map[string]any } // Decode the input into our structure, if we can diff --git a/fix/fixer_proxmox_type_test.go b/fix/fixer_proxmox_type_test.go index c79d1d71a73..89b5c9b64db 100644 --- a/fix/fixer_proxmox_type_test.go +++ b/fix/fixer_proxmox_type_test.go @@ -10,8 +10,7 @@ import ( ) func TestFixerProxmoxType_Impl(t *testing.T) { - var raw interface{} - raw = new(FixerProxmoxType) + var raw any = new(FixerProxmoxType) if _, ok := raw.(Fixer); !ok { t.Fatalf("must be a Fixer") } @@ -20,36 +19,36 @@ func TestFixerProxmoxType_Impl(t *testing.T) { func TestFixerProxmoxType_Fix(t *testing.T) { cases := []struct { - Input map[string]interface{} - Expected map[string]interface{} + Input map[string]any + Expected map[string]any }{ { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "proxmox", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "proxmox-iso", }, }, { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "proxmox-iso", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "proxmox-iso", }, }, { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "proxmox-clone", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "proxmox-clone", }, }, @@ -58,12 +57,12 @@ func TestFixerProxmoxType_Fix(t *testing.T) { for _, tc := range cases { var f FixerProxmoxType - input := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Input}, + input := map[string]any{ + "builders": []map[string]any{tc.Input}, } - expected := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Expected}, + expected := map[string]any{ + "builders": []map[string]any{tc.Expected}, } output, err := f.Fix(input) diff --git a/fix/fixer_qemu_disk_size.go b/fix/fixer_qemu_disk_size.go index aeb5e4ce93d..b9c562bc6ae 100644 --- a/fix/fixer_qemu_disk_size.go +++ b/fix/fixer_qemu_disk_size.go @@ -16,9 +16,9 @@ func (FixerQEMUDiskSize) DeprecatedOptions() map[string][]string { return map[string][]string{} } -func (FixerQEMUDiskSize) Fix(input map[string]interface{}) (map[string]interface{}, error) { +func (FixerQEMUDiskSize) Fix(input map[string]any) (map[string]any, error) { type template struct { - Builders []map[string]interface{} + Builders []map[string]any } // Decode the input into our structure, if we can diff --git a/fix/fixer_qemu_disk_size_test.go b/fix/fixer_qemu_disk_size_test.go index 7f534a70e89..46191f42630 100644 --- a/fix/fixer_qemu_disk_size_test.go +++ b/fix/fixer_qemu_disk_size_test.go @@ -14,27 +14,27 @@ func TestFixerQEMUDiskSize_impl(t *testing.T) { func TestFixerQEMUDiskSize(t *testing.T) { cases := []struct { - Input map[string]interface{} - Expected map[string]interface{} + Input map[string]any + Expected map[string]any }{ { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "qemu", "disk_size": int(40960), }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "qemu", "disk_size": "40960M", }, }, { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "qemu", "disk_size": float64(50000), }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "qemu", "disk_size": "50000M", }, @@ -44,12 +44,12 @@ func TestFixerQEMUDiskSize(t *testing.T) { for _, tc := range cases { var f FixerQEMUDiskSize - input := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Input}, + input := map[string]any{ + "builders": []map[string]any{tc.Input}, } - expected := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Expected}, + expected := map[string]any{ + "builders": []map[string]any{tc.Expected}, } output, err := f.Fix(input) diff --git a/fix/fixer_qemu_host_port.go b/fix/fixer_qemu_host_port.go index 162ec6b67b2..180974c806f 100644 --- a/fix/fixer_qemu_host_port.go +++ b/fix/fixer_qemu_host_port.go @@ -10,9 +10,9 @@ import ( // FixerQEMUHostPort updates ssh_host_port_min and ssh_host_port_max to host_port_min and host_port_max for QEMU builders type FixerQEMUHostPort struct{} -func (FixerQEMUHostPort) Fix(input map[string]interface{}) (map[string]interface{}, error) { +func (FixerQEMUHostPort) Fix(input map[string]any) (map[string]any, error) { type template struct { - Builders []map[string]interface{} + Builders []map[string]any } // Decode the input into our structure, if we can diff --git a/fix/fixer_qemu_host_port_test.go b/fix/fixer_qemu_host_port_test.go index 3fe4b6fa8f6..472a136ba90 100644 --- a/fix/fixer_qemu_host_port_test.go +++ b/fix/fixer_qemu_host_port_test.go @@ -14,27 +14,27 @@ func TestFixerQEMUHostPort_impl(t *testing.T) { func TestFixerQEMUHostPort(t *testing.T) { cases := []struct { - Input map[string]interface{} - Expected map[string]interface{} + Input map[string]any + Expected map[string]any }{ { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "qemu", "ssh_host_port_min": 2222, }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "qemu", "host_port_min": 2222, }, }, { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "qemu", "ssh_host_port_max": 4444, }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "qemu", "host_port_max": 4444, }, @@ -44,12 +44,12 @@ func TestFixerQEMUHostPort(t *testing.T) { for _, tc := range cases { var f FixerQEMUHostPort - input := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Input}, + input := map[string]any{ + "builders": []map[string]any{tc.Input}, } - expected := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Expected}, + expected := map[string]any{ + "builders": []map[string]any{tc.Expected}, } output, err := f.Fix(input) diff --git a/fix/fixer_scaleway_access_key.go b/fix/fixer_scaleway_access_key.go index be776f5078e..5d3cf48538a 100644 --- a/fix/fixer_scaleway_access_key.go +++ b/fix/fixer_scaleway_access_key.go @@ -17,10 +17,10 @@ func (FixerScalewayAccessKey) DeprecatedOptions() map[string][]string { } } -func (FixerScalewayAccessKey) Fix(input map[string]interface{}) (map[string]interface{}, error) { +func (FixerScalewayAccessKey) Fix(input map[string]any) (map[string]any, error) { // The type we'll decode into; we only care about builders type template struct { - Builders []map[string]interface{} + Builders []map[string]any } // Decode the input into our structure, if we can diff --git a/fix/fixer_scaleway_access_key_test.go b/fix/fixer_scaleway_access_key_test.go index 46d74971a83..8d2df011392 100644 --- a/fix/fixer_scaleway_access_key_test.go +++ b/fix/fixer_scaleway_access_key_test.go @@ -14,28 +14,28 @@ func TestFixerScalewayAccessKey_Fix_Impl(t *testing.T) { func TestFixerScalewayAccessKey_Fix(t *testing.T) { cases := []struct { - Input map[string]interface{} - Expected map[string]interface{} + Input map[string]any + Expected map[string]any }{ // No key_path field { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "scaleway", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "scaleway", }, }, // organization_id without access_key { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "scaleway", "organization_id": "0000", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "scaleway", "organization_id": "0000", }, @@ -43,12 +43,12 @@ func TestFixerScalewayAccessKey_Fix(t *testing.T) { // access_key without organization_id { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "scaleway", "access_key": "1111", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "scaleway", "organization_id": "1111", }, @@ -56,13 +56,13 @@ func TestFixerScalewayAccessKey_Fix(t *testing.T) { // access_key and organization_id { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "scaleway", "access_key": "2222", "organization_id": "3333", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "scaleway", "organization_id": "3333", }, @@ -72,12 +72,12 @@ func TestFixerScalewayAccessKey_Fix(t *testing.T) { for _, tc := range cases { var f FixerScalewayAccessKey - input := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Input}, + input := map[string]any{ + "builders": []map[string]any{tc.Input}, } - expected := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Expected}, + expected := map[string]any{ + "builders": []map[string]any{tc.Expected}, } output, err := f.Fix(input) diff --git a/fix/fixer_ssh_timeout.go b/fix/fixer_ssh_timeout.go index 21fbaf3da42..02959de01ce 100644 --- a/fix/fixer_ssh_timeout.go +++ b/fix/fixer_ssh_timeout.go @@ -16,9 +16,9 @@ func (FixerSSHTimout) DeprecatedOptions() map[string][]string { } } -func (FixerSSHTimout) Fix(input map[string]interface{}) (map[string]interface{}, error) { +func (FixerSSHTimout) Fix(input map[string]any) (map[string]any, error) { type template struct { - Builders []interface{} + Builders []any } // Decode the input into our structure, if we can @@ -28,7 +28,7 @@ func (FixerSSHTimout) Fix(input map[string]interface{}) (map[string]interface{}, } for i, raw := range tpl.Builders { - var builders map[string]interface{} + var builders map[string]any if err := mapstructure.Decode(raw, &builders); err != nil { // Ignore errors, could be a non-map continue diff --git a/fix/fixer_ssh_timeout_test.go b/fix/fixer_ssh_timeout_test.go index 9951db389a6..92a02ecaeab 100644 --- a/fix/fixer_ssh_timeout_test.go +++ b/fix/fixer_ssh_timeout_test.go @@ -14,27 +14,27 @@ func TestFixerSSHTimout_Impl(t *testing.T) { func TestFixerSSHTimout_Fix(t *testing.T) { cases := []struct { - Input map[string]interface{} - Expected map[string]interface{} + Input map[string]any + Expected map[string]any }{ // set galaxy_command { - Input: map[string]interface{}{ + Input: map[string]any{ "ssh_timeout": "1h5m2s", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "ssh_timeout": "1h5m2s", }, }, // set galaxycommand (old key) { - Input: map[string]interface{}{ + Input: map[string]any{ "ssh_wait_timeout": "1h5m2s", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "ssh_timeout": "1h5m2s", }, }, @@ -42,12 +42,12 @@ func TestFixerSSHTimout_Fix(t *testing.T) { // set galaxy_command and galaxycommand // galaxy_command takes precedence { - Input: map[string]interface{}{ + Input: map[string]any{ "ssh_timeout": "1h5m2s", "ssh_wait_timeout": "30m", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "ssh_timeout": "1h5m2s", }, }, @@ -56,12 +56,12 @@ func TestFixerSSHTimout_Fix(t *testing.T) { for _, tc := range cases { var f FixerSSHTimout - input := map[string]interface{}{ - "builders": []interface{}{tc.Input}, + input := map[string]any{ + "builders": []any{tc.Input}, } - expected := map[string]interface{}{ - "builders": []interface{}{tc.Expected}, + expected := map[string]any{ + "builders": []any{tc.Expected}, } output, err := f.Fix(input) diff --git a/fix/fixer_sshdisableagent.go b/fix/fixer_sshdisableagent.go index 818495743a1..5af76d4205a 100644 --- a/fix/fixer_sshdisableagent.go +++ b/fix/fixer_sshdisableagent.go @@ -17,10 +17,10 @@ func (FixerSSHDisableAgent) DeprecatedOptions() map[string][]string { } } -func (FixerSSHDisableAgent) Fix(input map[string]interface{}) (map[string]interface{}, error) { +func (FixerSSHDisableAgent) Fix(input map[string]any) (map[string]any, error) { // The type we'll decode into; we only care about builders type template struct { - Builders []map[string]interface{} + Builders []map[string]any } // Decode the input into our structure, if we can diff --git a/fix/fixer_sshdisableagent_test.go b/fix/fixer_sshdisableagent_test.go index 40eaea95a0e..c283e14f409 100644 --- a/fix/fixer_sshdisableagent_test.go +++ b/fix/fixer_sshdisableagent_test.go @@ -14,50 +14,50 @@ func TestFixerSSHDisableAgent_Impl(t *testing.T) { func TestFixerSSHDisableAgent_Fix(t *testing.T) { cases := []struct { - Input map[string]interface{} - Expected map[string]interface{} + Input map[string]any + Expected map[string]any }{ // No disable_agent field { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "virtualbox", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "virtualbox", }, }, // disable_agent_forwarding without disable_agent { - Input: map[string]interface{}{ + Input: map[string]any{ "ssh_disable_agent_forwarding": true, }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "ssh_disable_agent_forwarding": true, }, }, // disable_agent without disable_agent_forwarding { - Input: map[string]interface{}{ + Input: map[string]any{ "ssh_disable_agent": true, }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "ssh_disable_agent_forwarding": true, }, }, // disable_agent and disable_agent_forwarding { - Input: map[string]interface{}{ + Input: map[string]any{ "ssh_disable_agent": true, "ssh_disable_agent_forwarding": false, }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "ssh_disable_agent_forwarding": false, }, }, @@ -66,12 +66,12 @@ func TestFixerSSHDisableAgent_Fix(t *testing.T) { for _, tc := range cases { var f FixerSSHDisableAgent - input := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Input}, + input := map[string]any{ + "builders": []map[string]any{tc.Input}, } - expected := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Expected}, + expected := map[string]any{ + "builders": []map[string]any{tc.Expected}, } output, err := f.Fix(input) diff --git a/fix/fixer_sshkeypath.go b/fix/fixer_sshkeypath.go index d3224e3a7b3..fad7fa5d2ed 100644 --- a/fix/fixer_sshkeypath.go +++ b/fix/fixer_sshkeypath.go @@ -17,10 +17,10 @@ func (FixerSSHKeyPath) DeprecatedOptions() map[string][]string { } } -func (FixerSSHKeyPath) Fix(input map[string]interface{}) (map[string]interface{}, error) { +func (FixerSSHKeyPath) Fix(input map[string]any) (map[string]any, error) { // The type we'll decode into; we only care about builders type template struct { - Builders []map[string]interface{} + Builders []map[string]any } // Decode the input into our structure, if we can diff --git a/fix/fixer_sshkeypath_test.go b/fix/fixer_sshkeypath_test.go index 73692365507..bb88323b0ca 100644 --- a/fix/fixer_sshkeypath_test.go +++ b/fix/fixer_sshkeypath_test.go @@ -14,50 +14,50 @@ func TestFixerSSHKeyPath_Impl(t *testing.T) { func TestFixerSSHKeyPath_Fix(t *testing.T) { cases := []struct { - Input map[string]interface{} - Expected map[string]interface{} + Input map[string]any + Expected map[string]any }{ // No key_path field { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "virtualbox", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "virtualbox", }, }, // private_key_file without key_path { - Input: map[string]interface{}{ + Input: map[string]any{ "ssh_private_key_file": "id_rsa", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "ssh_private_key_file": "id_rsa", }, }, // key_path without private_key_file { - Input: map[string]interface{}{ + Input: map[string]any{ "ssh_key_path": "id_rsa", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "ssh_private_key_file": "id_rsa", }, }, // key_path and private_key_file { - Input: map[string]interface{}{ + Input: map[string]any{ "ssh_key_path": "key_id_rsa", "ssh_private_key_file": "private_id_rsa", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "ssh_private_key_file": "private_id_rsa", }, }, @@ -66,12 +66,12 @@ func TestFixerSSHKeyPath_Fix(t *testing.T) { for _, tc := range cases { var f FixerSSHKeyPath - input := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Input}, + input := map[string]any{ + "builders": []map[string]any{tc.Input}, } - expected := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Expected}, + expected := map[string]any{ + "builders": []map[string]any{tc.Expected}, } output, err := f.Fix(input) diff --git a/fix/fixer_virtualbox_gaattach.go b/fix/fixer_virtualbox_gaattach.go index c8b4799438f..f4864de2c13 100644 --- a/fix/fixer_virtualbox_gaattach.go +++ b/fix/fixer_virtualbox_gaattach.go @@ -17,10 +17,10 @@ func (FixerVirtualBoxGAAttach) DeprecatedOptions() map[string][]string { } } -func (FixerVirtualBoxGAAttach) Fix(input map[string]interface{}) (map[string]interface{}, error) { +func (FixerVirtualBoxGAAttach) Fix(input map[string]any) (map[string]any, error) { // The type we'll decode into; we only care about builders type template struct { - Builders []map[string]interface{} + Builders []map[string]any } // Decode the input into our structure, if we can diff --git a/fix/fixer_virtualbox_gaattach_test.go b/fix/fixer_virtualbox_gaattach_test.go index 5894a120898..db5aeb7101d 100644 --- a/fix/fixer_virtualbox_gaattach_test.go +++ b/fix/fixer_virtualbox_gaattach_test.go @@ -14,28 +14,28 @@ func TestFixerVirtualBoxGAAttach_Impl(t *testing.T) { func TestFixerVirtualBoxGAAttach_Fix(t *testing.T) { cases := []struct { - Input map[string]interface{} - Expected map[string]interface{} + Input map[string]any + Expected map[string]any }{ // No attach field { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "virtualbox", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "virtualbox", }, }, // Attach field == false { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "virtualbox", "guest_additions_attach": false, }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "virtualbox", "guest_additions_mode": "upload", }, @@ -43,12 +43,12 @@ func TestFixerVirtualBoxGAAttach_Fix(t *testing.T) { // Attach field == true { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "virtualbox", "guest_additions_attach": true, }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "virtualbox", "guest_additions_mode": "attach", }, @@ -56,12 +56,12 @@ func TestFixerVirtualBoxGAAttach_Fix(t *testing.T) { // Attach field is not a bool { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "virtualbox", "guest_additions_attach": "what", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "virtualbox", "guest_additions_attach": "what", }, @@ -71,12 +71,12 @@ func TestFixerVirtualBoxGAAttach_Fix(t *testing.T) { for _, tc := range cases { var f FixerVirtualBoxGAAttach - input := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Input}, + input := map[string]any{ + "builders": []map[string]any{tc.Input}, } - expected := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Expected}, + expected := map[string]any{ + "builders": []map[string]any{tc.Expected}, } output, err := f.Fix(input) diff --git a/fix/fixer_virtualbox_rename.go b/fix/fixer_virtualbox_rename.go index a19e31421bb..fccae7cf8ec 100644 --- a/fix/fixer_virtualbox_rename.go +++ b/fix/fixer_virtualbox_rename.go @@ -14,10 +14,10 @@ func (FixerVirtualBoxRename) DeprecatedOptions() map[string][]string { return map[string][]string{} } -func (FixerVirtualBoxRename) Fix(input map[string]interface{}) (map[string]interface{}, error) { +func (FixerVirtualBoxRename) Fix(input map[string]any) (map[string]any, error) { type template struct { - Builders []map[string]interface{} - Provisioners []interface{} + Builders []map[string]any + Provisioners []any } // Decode the input into our structure, if we can @@ -45,7 +45,7 @@ func (FixerVirtualBoxRename) Fix(input map[string]interface{}) (map[string]inter } for i, raw := range tpl.Provisioners { - var m map[string]interface{} + var m map[string]any if err := mapstructure.WeakDecode(raw, &m); err != nil { // Ignore errors, could be a non-map continue @@ -56,7 +56,7 @@ func (FixerVirtualBoxRename) Fix(input map[string]interface{}) (map[string]inter continue } - var override map[string]interface{} + var override map[string]any if err := mapstructure.WeakDecode(raw, &override); err != nil { return nil, err } diff --git a/fix/fixer_virtualbox_rename_test.go b/fix/fixer_virtualbox_rename_test.go index 37597be3807..4f13c8c7f9a 100644 --- a/fix/fixer_virtualbox_rename_test.go +++ b/fix/fixer_virtualbox_rename_test.go @@ -14,15 +14,15 @@ func TestFixerVirtualBoxRename_impl(t *testing.T) { func TestFixerVirtualBoxRename_Fix(t *testing.T) { cases := []struct { - Input map[string]interface{} - Expected map[string]interface{} + Input map[string]any + Expected map[string]any }{ { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "virtualbox", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "virtualbox-iso", }, }, @@ -31,12 +31,12 @@ func TestFixerVirtualBoxRename_Fix(t *testing.T) { for _, tc := range cases { var f FixerVirtualBoxRename - input := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Input}, + input := map[string]any{ + "builders": []map[string]any{tc.Input}, } - expected := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Expected}, + expected := map[string]any{ + "builders": []map[string]any{tc.Expected}, } output, err := f.Fix(input) @@ -52,25 +52,25 @@ func TestFixerVirtualBoxRename_Fix(t *testing.T) { func TestFixerVirtualBoxRenameFix_provisionerOverride(t *testing.T) { cases := []struct { - Input map[string]interface{} - Expected map[string]interface{} + Input map[string]any + Expected map[string]any }{ { - Input: map[string]interface{}{ - "provisioners": []interface{}{ - map[string]interface{}{ - "override": map[string]interface{}{ - "virtualbox": map[string]interface{}{}, + Input: map[string]any{ + "provisioners": []any{ + map[string]any{ + "override": map[string]any{ + "virtualbox": map[string]any{}, }, }, }, }, - Expected: map[string]interface{}{ - "provisioners": []interface{}{ - map[string]interface{}{ - "override": map[string]interface{}{ - "virtualbox-iso": map[string]interface{}{}, + Expected: map[string]any{ + "provisioners": []any{ + map[string]any{ + "override": map[string]any{ + "virtualbox-iso": map[string]any{}, }, }, }, diff --git a/fix/fixer_vmware_compaction.go b/fix/fixer_vmware_compaction.go index d149f1eded8..2e422777172 100644 --- a/fix/fixer_vmware_compaction.go +++ b/fix/fixer_vmware_compaction.go @@ -14,10 +14,10 @@ func (FixerVMwareCompaction) DeprecatedOptions() map[string][]string { return map[string][]string{} } -func (FixerVMwareCompaction) Fix(input map[string]interface{}) (map[string]interface{}, error) { +func (FixerVMwareCompaction) Fix(input map[string]any) (map[string]any, error) { // The type we'll decode into; we only care about builders type template struct { - Builders []map[string]interface{} + Builders []map[string]any } // Decode the input into our structure, if we can diff --git a/fix/fixer_vmware_compaction_test.go b/fix/fixer_vmware_compaction_test.go index 0736042a898..8e1a159f03d 100644 --- a/fix/fixer_vmware_compaction_test.go +++ b/fix/fixer_vmware_compaction_test.go @@ -14,34 +14,34 @@ func TestFixerVMwareCompaction_impl(t *testing.T) { func TestFixerVMwareCompaction_Fix(t *testing.T) { cases := []struct { - Input map[string]interface{} - Expected map[string]interface{} + Input map[string]any + Expected map[string]any }{ { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "virtualbox-iso", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "virtualbox-iso", }, }, { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "vmware-iso", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "vmware-iso", }, }, { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "vmware-iso", "remote_type": "esx5", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "vmware-iso", "remote_type": "esx5", "disk_type_id": "zeroedthick", @@ -49,13 +49,13 @@ func TestFixerVMwareCompaction_Fix(t *testing.T) { }, }, { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "vmware-iso", "remote_type": "esx5", "disk_type_id": "zeroedthick", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "vmware-iso", "remote_type": "esx5", "disk_type_id": "zeroedthick", @@ -63,14 +63,14 @@ func TestFixerVMwareCompaction_Fix(t *testing.T) { }, }, { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "vmware-iso", "remote_type": "esx5", "disk_type_id": "zeroedthick", "skip_compaction": false, }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "vmware-iso", "remote_type": "esx5", "disk_type_id": "zeroedthick", @@ -78,13 +78,13 @@ func TestFixerVMwareCompaction_Fix(t *testing.T) { }, }, { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "vmware-iso", "remote_type": "esx5", "disk_type_id": "thin", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "vmware-iso", "remote_type": "esx5", "disk_type_id": "thin", @@ -95,12 +95,12 @@ func TestFixerVMwareCompaction_Fix(t *testing.T) { for _, tc := range cases { var f FixerVMwareCompaction - input := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Input}, + input := map[string]any{ + "builders": []map[string]any{tc.Input}, } - expected := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Expected}, + expected := map[string]any{ + "builders": []map[string]any{tc.Expected}, } output, err := f.Fix(input) diff --git a/fix/fixer_vmware_rename.go b/fix/fixer_vmware_rename.go index 7b81fb849f1..c223f200cfe 100644 --- a/fix/fixer_vmware_rename.go +++ b/fix/fixer_vmware_rename.go @@ -14,10 +14,10 @@ func (FixerVMwareRename) DeprecatedOptions() map[string][]string { return map[string][]string{} } -func (FixerVMwareRename) Fix(input map[string]interface{}) (map[string]interface{}, error) { +func (FixerVMwareRename) Fix(input map[string]any) (map[string]any, error) { // The type we'll decode into; we only care about builders type template struct { - Builders []map[string]interface{} + Builders []map[string]any } // Decode the input into our structure, if we can diff --git a/fix/fixer_vmware_rename_test.go b/fix/fixer_vmware_rename_test.go index 28c6c1de38c..518252f34c8 100644 --- a/fix/fixer_vmware_rename_test.go +++ b/fix/fixer_vmware_rename_test.go @@ -14,15 +14,15 @@ func TestFixerVMwareRename_impl(t *testing.T) { func TestFixerVMwareRename_Fix(t *testing.T) { cases := []struct { - Input map[string]interface{} - Expected map[string]interface{} + Input map[string]any + Expected map[string]any }{ { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "vmware", }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "vmware-iso", }, }, @@ -31,12 +31,12 @@ func TestFixerVMwareRename_Fix(t *testing.T) { for _, tc := range cases { var f FixerVMwareRename - input := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Input}, + input := map[string]any{ + "builders": []map[string]any{tc.Input}, } - expected := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Expected}, + expected := map[string]any{ + "builders": []map[string]any{tc.Expected}, } output, err := f.Fix(input) diff --git a/fix/fixer_vsphere_network_storage.go b/fix/fixer_vsphere_network_storage.go index 379d6167c85..d9eb012dda7 100644 --- a/fix/fixer_vsphere_network_storage.go +++ b/fix/fixer_vsphere_network_storage.go @@ -19,10 +19,10 @@ func (FixerVSphereNetworkDisk) DeprecatedOptions() map[string][]string { } } -func (FixerVSphereNetworkDisk) Fix(input map[string]interface{}) (map[string]interface{}, error) { +func (FixerVSphereNetworkDisk) Fix(input map[string]any) (map[string]any, error) { // The type we'll decode into; we only care about builders type template struct { - Builders []map[string]interface{} + Builders []map[string]any } // Decode the input into our structure, if we can @@ -46,8 +46,8 @@ func (FixerVSphereNetworkDisk) Fix(input map[string]interface{}) (map[string]int continue } - var networkAdapters []interface{} - nic := make(map[string]interface{}) + var networkAdapters []any + nic := make(map[string]any) hasNetwork := false networkRaw, ok := builder["network"] @@ -77,15 +77,15 @@ func (FixerVSphereNetworkDisk) Fix(input map[string]interface{}) (map[string]int networkAdapters = append(networkAdapters, nic) adaptersRaw, ok := builder["network_adapters"] if ok { - existingAdapters := adaptersRaw.([]interface{}) + existingAdapters := adaptersRaw.([]any) networkAdapters = append(networkAdapters, existingAdapters...) } builder["network_adapters"] = networkAdapters } - var storage []interface{} - disk := make(map[string]interface{}) + var storage []any + disk := make(map[string]any) hasStorage := false diskSizeRaw, ok := builder["disk_size"] @@ -113,7 +113,7 @@ func (FixerVSphereNetworkDisk) Fix(input map[string]interface{}) (map[string]int storage = append(storage, disk) storageRaw, ok := builder["storage"] if ok { - existingStorage := storageRaw.([]interface{}) + existingStorage := storageRaw.([]any) storage = append(storage, existingStorage...) } diff --git a/fix/fixer_vsphere_network_storage_test.go b/fix/fixer_vsphere_network_storage_test.go index 3a3273504bc..098b4c6af60 100644 --- a/fix/fixer_vsphere_network_storage_test.go +++ b/fix/fixer_vsphere_network_storage_test.go @@ -14,57 +14,57 @@ func TestFixerVSphereNetwork_impl(t *testing.T) { func TestFixerVSphereNetwork_Fix(t *testing.T) { cases := []struct { - Input map[string]interface{} - Expected map[string]interface{} + Input map[string]any + Expected map[string]any }{ { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "vsphere-iso", "network": "", "networkCard": "vmxnet3", "disk_size": 5000, }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "vsphere-iso", - "network_adapters": []interface{}{ - map[string]interface{}{ + "network_adapters": []any{ + map[string]any{ "network": "", "network_card": "vmxnet3", }, }, - "storage": []interface{}{ - map[string]interface{}{ + "storage": []any{ + map[string]any{ "disk_size": 5000, }, }, }, }, { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "vsphere-iso", "network": "", "network_card": "vmxnet3", "disk_size": 5000, }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "vsphere-iso", - "network_adapters": []interface{}{ - map[string]interface{}{ + "network_adapters": []any{ + map[string]any{ "network": "", "network_card": "vmxnet3", }, }, - "storage": []interface{}{ - map[string]interface{}{ + "storage": []any{ + map[string]any{ "disk_size": 5000, }, }, }, }, { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "vsphere-iso", "network": "myNetwork", "networkCard": "vmxnet3", @@ -73,16 +73,16 @@ func TestFixerVSphereNetwork_Fix(t *testing.T) { "disk_eagerly_scrub": true, }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "vsphere-iso", - "network_adapters": []interface{}{ - map[string]interface{}{ + "network_adapters": []any{ + map[string]any{ "network": "myNetwork", "network_card": "vmxnet3", }, }, - "storage": []interface{}{ - map[string]interface{}{ + "storage": []any{ + map[string]any{ "disk_size": 5000, "disk_thin_provisioned": true, "disk_eagerly_scrub": true, @@ -91,21 +91,21 @@ func TestFixerVSphereNetwork_Fix(t *testing.T) { }, }, { - Input: map[string]interface{}{ + Input: map[string]any{ "type": "vsphere-iso", "network": "myNetwork", "networkCard": "vmxnet3", "disk_size": 5000, "disk_thin_provisioned": true, "disk_eagerly_scrub": true, - "network_adapters": []interface{}{ - map[string]interface{}{ + "network_adapters": []any{ + map[string]any{ "network": "net1", "network_card": "vmxnet3", }, }, - "storage": []interface{}{ - map[string]interface{}{ + "storage": []any{ + map[string]any{ "disk_size": 5001, "disk_thin_provisioned": true, "disk_eagerly_scrub": true, @@ -113,25 +113,25 @@ func TestFixerVSphereNetwork_Fix(t *testing.T) { }, }, - Expected: map[string]interface{}{ + Expected: map[string]any{ "type": "vsphere-iso", - "network_adapters": []interface{}{ - map[string]interface{}{ + "network_adapters": []any{ + map[string]any{ "network": "myNetwork", "network_card": "vmxnet3", }, - map[string]interface{}{ + map[string]any{ "network": "net1", "network_card": "vmxnet3", }, }, - "storage": []interface{}{ - map[string]interface{}{ + "storage": []any{ + map[string]any{ "disk_size": 5000, "disk_thin_provisioned": true, "disk_eagerly_scrub": true, }, - map[string]interface{}{ + map[string]any{ "disk_size": 5001, "disk_thin_provisioned": true, "disk_eagerly_scrub": true, @@ -144,12 +144,12 @@ func TestFixerVSphereNetwork_Fix(t *testing.T) { for _, tc := range cases { var f FixerVSphereNetworkDisk - input := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Input}, + input := map[string]any{ + "builders": []map[string]any{tc.Input}, } - expected := map[string]interface{}{ - "builders": []map[string]interface{}{tc.Expected}, + expected := map[string]any{ + "builders": []map[string]any{tc.Expected}, } output, err := f.Fix(input) diff --git a/fix/helpers.go b/fix/helpers.go index 5ab0d2fe898..55368491c12 100644 --- a/fix/helpers.go +++ b/fix/helpers.go @@ -5,20 +5,20 @@ package fix // PP is a convenient way to interact with the post-processors within a fixer type PP struct { - PostProcessors []interface{} `mapstructure:"post-processors"` + PostProcessors []any `mapstructure:"post-processors"` } // postProcessors converts the variable structure of the template to a list -func (pp *PP) ppList() []map[string]interface{} { - pps := make([]map[string]interface{}, 0, len(pp.PostProcessors)) +func (pp *PP) ppList() []map[string]any { + pps := make([]map[string]any, 0, len(pp.PostProcessors)) for _, rawPP := range pp.PostProcessors { switch pp := rawPP.(type) { case string: - case map[string]interface{}: + case map[string]any: pps = append(pps, pp) - case []interface{}: + case []any: for _, innerRawPP := range pp { - if innerPP, ok := innerRawPP.(map[string]interface{}); ok { + if innerPP, ok := innerRawPP.(map[string]any); ok { pps = append(pps, innerPP) } } diff --git a/hcl2template/enforced_provisioner.go b/hcl2template/enforced_provisioner.go index 7484e6ba61e..37412d28e17 100644 --- a/hcl2template/enforced_provisioner.go +++ b/hcl2template/enforced_provisioner.go @@ -28,7 +28,7 @@ func (cfg *PackerConfig) GetCoreBuildProvisionerFromBlock(pb *ProvisionerBlock, } // Create basic builder variables - builderVars := map[string]interface{}{ + builderVars := map[string]any{ "packer_core_version": cfg.CorePackerVersionString, "packer_debug": strconv.FormatBool(cfg.debug), "packer_force": strconv.FormatBool(cfg.force), @@ -49,7 +49,7 @@ func (cfg *PackerConfig) GetCoreBuildProvisionerFromBlock(pb *ProvisionerBlock, if pb.Override != nil { if override, ok := pb.Override[buildName]; ok { - if typedOverride, ok := override.(map[string]interface{}); ok { + if typedOverride, ok := override.(map[string]any); ok { hclProvisioner.override = typedOverride } } diff --git a/hcl2template/enforced_provisioner_parser.go b/hcl2template/enforced_provisioner_parser.go index af63e257eb7..81466e65ac6 100644 --- a/hcl2template/enforced_provisioner_parser.go +++ b/hcl2template/enforced_provisioner_parser.go @@ -77,7 +77,7 @@ func (p *Parser) parseProvisionerBlocks(blockContent string) ([]*ProvisionerBloc func normalizeLegacyProvisionersJSON(blockContent string) (string, bool, error) { type legacyPayload struct { - Provisioners []map[string]interface{} `json:"provisioners"` + Provisioners []map[string]any `json:"provisioners"` } var payload legacyPayload @@ -89,14 +89,14 @@ func normalizeLegacyProvisionersJSON(blockContent string) (string, bool, error) return "", false, nil } - normalized := make([]map[string]interface{}, 0, len(payload.Provisioners)) + normalized := make([]map[string]any, 0, len(payload.Provisioners)) for _, provisioner := range payload.Provisioners { typeName, ok := provisioner["type"].(string) if !ok || typeName == "" { continue } - cfg := make(map[string]interface{}) + cfg := make(map[string]any) for key, value := range provisioner { if key == "type" { continue @@ -104,14 +104,14 @@ func normalizeLegacyProvisionersJSON(blockContent string) (string, bool, error) cfg[key] = value } - normalized = append(normalized, map[string]interface{}{typeName: cfg}) + normalized = append(normalized, map[string]any{typeName: cfg}) } if len(normalized) == 0 { return "", false, nil } - out := map[string]interface{}{ + out := map[string]any{ buildProvisionerLabel: normalized, } diff --git a/hcl2template/internal/mock.go b/hcl2template/internal/mock.go index 15d178e0d16..23d557c474e 100644 --- a/hcl2template/internal/mock.go +++ b/hcl2template/internal/mock.go @@ -45,7 +45,7 @@ type MockConfig struct { NestedSlice []NestedMockConfig `mapstructure:"nested_slice"` } -func (b *MockConfig) Prepare(raws ...interface{}) error { +func (b *MockConfig) Prepare(raws ...any) error { for i, raw := range raws { cval, ok := raw.(cty.Value) if !ok { @@ -78,7 +78,7 @@ var _ packersdk.Builder = new(MockBuilder) func (b *MockBuilder) ConfigSpec() hcldec.ObjectSpec { return b.Config.FlatMapstructure().HCL2Spec() } -func (b *MockBuilder) Prepare(raws ...interface{}) ([]string, []string, error) { +func (b *MockBuilder) Prepare(raws ...any) ([]string, []string, error) { return []string{"ID"}, nil, b.Config.Prepare(raws...) } @@ -100,11 +100,11 @@ func (b *MockProvisioner) ConfigSpec() hcldec.ObjectSpec { return b.Config.FlatMapstructure().HCL2Spec() } -func (b *MockProvisioner) Prepare(raws ...interface{}) error { +func (b *MockProvisioner) Prepare(raws ...any) error { return b.Config.Prepare(raws...) } -func (b *MockProvisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, _ map[string]interface{}) error { +func (b *MockProvisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, _ map[string]any) error { return nil } @@ -126,7 +126,7 @@ func (d *MockDatasource) OutputSpec() hcldec.ObjectSpec { return d.Config.FlatMapstructure().HCL2Spec() } -func (d *MockDatasource) Configure(raws ...interface{}) error { +func (d *MockDatasource) Configure(raws ...any) error { return d.Config.Prepare(raws...) } @@ -148,7 +148,7 @@ func (b *MockPostProcessor) ConfigSpec() hcldec.ObjectSpec { return b.Config.FlatMapstructure().HCL2Spec() } -func (b *MockPostProcessor) Configure(raws ...interface{}) error { +func (b *MockPostProcessor) Configure(raws ...any) error { return b.Config.Prepare(raws...) } @@ -171,7 +171,7 @@ func (b *MockCommunicator) ConfigSpec() hcldec.ObjectSpec { return b.Config.FlatMapstructure().HCL2Spec() } -func (b *MockCommunicator) Configure(raws ...interface{}) ([]string, error) { +func (b *MockCommunicator) Configure(raws ...any) ([]string, error) { return nil, b.Config.Prepare(raws...) } diff --git a/hcl2template/repl/format.go b/hcl2template/repl/format.go index ba15a028ffc..014acd36994 100644 --- a/hcl2template/repl/format.go +++ b/hcl2template/repl/format.go @@ -16,11 +16,11 @@ import ( // // The value must currently be a string, list, map, and any nested values // with those same types. -func FormatResult(value interface{}) string { +func FormatResult(value any) string { return formatResult(value, false) } -func formatResult(value interface{}, nested bool) string { +func formatResult(value any, nested bool) string { if value == nil { return "null" } @@ -41,16 +41,16 @@ func formatResult(value interface{}, nested bool) string { default: return "false" } - case []interface{}: + case []any: return formatListResult(output) - case map[string]interface{}: + case map[string]any: return formatMapResult(output) default: return "" } } -func formatListResult(value []interface{}) string { +func formatListResult(value []any) string { var outputBuf bytes.Buffer outputBuf.WriteString("[") if len(value) > 0 { @@ -67,7 +67,7 @@ func formatListResult(value []interface{}) string { return outputBuf.String() } -func formatMapResult(value map[string]interface{}) string { +func formatMapResult(value map[string]any) string { ks := make([]string, 0, len(value)) for k := range value { ks = append(ks, k) diff --git a/hcl2template/shim/values.go b/hcl2template/shim/values.go index 0b64e3d332b..9f559a476d0 100644 --- a/hcl2template/shim/values.go +++ b/hcl2template/shim/values.go @@ -18,7 +18,7 @@ import ( // This function will transform a cty null value into a Go nil value, which // isn't a possible outcome of the HCL/HIL-based decoder and so callers may // need to detect and reject any null values. -func ConfigValueFromHCL2(v cty.Value) interface{} { +func ConfigValueFromHCL2(v cty.Value) any { if !v.IsKnown() { return hcl2helper.UnknownVariableValue } @@ -56,7 +56,7 @@ func ConfigValueFromHCL2(v cty.Value) interface{} { } if v.Type().IsListType() || v.Type().IsSetType() || v.Type().IsTupleType() { - l := make([]interface{}, 0, v.LengthInt()) + l := make([]any, 0, v.LengthInt()) it := v.ElementIterator() for it.Next() { _, ev := it.Element() @@ -66,7 +66,7 @@ func ConfigValueFromHCL2(v cty.Value) interface{} { } if v.Type().IsMapType() || v.Type().IsObjectType() { - l := make(map[string]interface{}) + l := make(map[string]any) it := v.ElementIterator() for it.Next() { ek, ev := it.Element() diff --git a/hcl2template/shim/values_test.go b/hcl2template/shim/values_test.go index 7cae2faa46b..5d9ed55ae4d 100644 --- a/hcl2template/shim/values_test.go +++ b/hcl2template/shim/values_test.go @@ -15,7 +15,7 @@ import ( func TestConfigValueFromHCL2(t *testing.T) { tests := []struct { Input cty.Value - Want interface{} + Want any }{ { cty.True, @@ -48,11 +48,11 @@ func TestConfigValueFromHCL2(t *testing.T) { "zip": cty.StringVal("91037"), }), }), - map[string]interface{}{ + map[string]any{ "name": "Ermintrude", "age": int(19), - "address": map[string]interface{}{ - "street": []interface{}{"421 Shoreham Loop"}, + "address": map[string]any{ + "street": []any{"421 Shoreham Loop"}, "city": "Fridgewater", "state": "MA", "zip": "91037", @@ -64,7 +64,7 @@ func TestConfigValueFromHCL2(t *testing.T) { "foo": cty.StringVal("bar"), "bar": cty.StringVal("baz"), }), - map[string]interface{}{ + map[string]any{ "foo": "bar", "bar": "baz", }, @@ -74,7 +74,7 @@ func TestConfigValueFromHCL2(t *testing.T) { cty.StringVal("foo"), cty.True, }), - []interface{}{ + []any{ "foo", true, }, diff --git a/hcl2template/types.build.provisioners.go b/hcl2template/types.build.provisioners.go index b1b355b1b01..5bedeee2ce4 100644 --- a/hcl2template/types.build.provisioners.go +++ b/hcl2template/types.build.provisioners.go @@ -69,7 +69,7 @@ type ProvisionerBlock struct { MaxRetries int Timeout time.Duration ContinueOnError bool - Override map[string]interface{} + Override map[string]any OnlyExcept OnlyExcept HCL2Ref } @@ -118,9 +118,9 @@ func (p *Parser) decodeProvisioner(block *hcl.Block, ectx *hcl.EvalContext) (*Pr }) } - override := make(map[string]interface{}) + override := make(map[string]any) for buildName, overrides := range b.Override.AsValueMap() { - buildOverrides := make(map[string]interface{}) + buildOverrides := make(map[string]any) if !overrides.Type().IsObjectType() { return nil, append(diags, &hcl.Diagnostic{ @@ -199,7 +199,7 @@ func (cfg *PackerConfig) startProvisioner(source SourceUseBlock, pb *Provisioner if pb.Override != nil { if override, ok := pb.Override[source.name()]; ok { - hclProvisioner.override = override.(map[string]interface{}) + hclProvisioner.override = override.(map[string]any) } } diff --git a/hcl2template/types.hcl_post-processor.go b/hcl2template/types.hcl_post-processor.go index 465044a760b..b15fa0881f3 100644 --- a/hcl2template/types.hcl_post-processor.go +++ b/hcl2template/types.hcl_post-processor.go @@ -21,14 +21,14 @@ type HCL2PostProcessor struct { PostProcessor packersdk.PostProcessor postProcessorBlock *PostProcessorBlock evalContext *hcl.EvalContext - builderVariables map[string]interface{} + builderVariables map[string]any } func (p *HCL2PostProcessor) ConfigSpec() hcldec.ObjectSpec { return p.PostProcessor.ConfigSpec() } -func (p *HCL2PostProcessor) HCL2Prepare(buildVars map[string]interface{}) error { +func (p *HCL2PostProcessor) HCL2Prepare(buildVars map[string]any) error { var diags hcl.Diagnostics ectx := p.evalContext if len(buildVars) > 0 { @@ -65,13 +65,13 @@ func (p *HCL2PostProcessor) HCL2Prepare(buildVars map[string]interface{}) error return p.PostProcessor.Configure(p.builderVariables, flatPostProcessorCfg) } -func (p *HCL2PostProcessor) Configure(args ...interface{}) error { +func (p *HCL2PostProcessor) Configure(args ...any) error { return p.PostProcessor.Configure(args...) } func (p *HCL2PostProcessor) PostProcess(ctx context.Context, ui packersdk.Ui, artifact packersdk.Artifact) (packersdk.Artifact, bool, bool, error) { - generatedData := make(map[string]interface{}) - if artifactStateData, ok := artifact.State("generated_data").(map[interface{}]interface{}); ok { + generatedData := make(map[string]any) + if artifactStateData, ok := artifact.State("generated_data").(map[any]any); ok { for k, v := range artifactStateData { generatedData[k.(string)] = v } diff --git a/hcl2template/types.hcl_provisioner.go b/hcl2template/types.hcl_provisioner.go index 871a3e63f0c..7d5bde6b8d9 100644 --- a/hcl2template/types.hcl_provisioner.go +++ b/hcl2template/types.hcl_provisioner.go @@ -21,15 +21,15 @@ type HCL2Provisioner struct { Provisioner packersdk.Provisioner provisionerBlock *ProvisionerBlock evalContext *hcl.EvalContext - builderVariables map[string]interface{} - override map[string]interface{} + builderVariables map[string]any + override map[string]any } func (p *HCL2Provisioner) ConfigSpec() hcldec.ObjectSpec { return p.Provisioner.ConfigSpec() } -func (p *HCL2Provisioner) HCL2Prepare(buildVars map[string]interface{}) error { +func (p *HCL2Provisioner) HCL2Prepare(buildVars map[string]any) error { var diags hcl.Diagnostics ectx := p.evalContext if len(buildVars) > 0 { @@ -68,11 +68,11 @@ func (p *HCL2Provisioner) HCL2Prepare(buildVars map[string]interface{}) error { return p.Provisioner.Prepare(p.builderVariables, flatProvisionerCfg, p.override) } -func (p *HCL2Provisioner) Prepare(args ...interface{}) error { +func (p *HCL2Provisioner) Prepare(args ...any) error { return p.Provisioner.Prepare(args...) } -func (p *HCL2Provisioner) Provision(ctx context.Context, ui packersdk.Ui, c packersdk.Communicator, vars map[string]interface{}) error { +func (p *HCL2Provisioner) Provision(ctx context.Context, ui packersdk.Ui, c packersdk.Communicator, vars map[string]any) error { err := p.HCL2Prepare(vars) if err != nil { return err diff --git a/hcl2template/types.refstring.go b/hcl2template/types.refstring.go index 09634ade3fb..417e437ccd0 100644 --- a/hcl2template/types.refstring.go +++ b/hcl2template/types.refstring.go @@ -88,7 +88,7 @@ func newDataSourceRefString(parts []string) (refString, error) { } // getComponentByRef gets a registered component from the configuration from a refString -func (cfg *PackerConfig) getComponentByRef(rs refString) (interface{}, error) { +func (cfg *PackerConfig) getComponentByRef(rs refString) (any, error) { switch rs.MType { case "data": for _, ds := range cfg.Datasources { diff --git a/hcl2template/types.source.go b/hcl2template/types.source.go index 2b14e943f85..7c18c2afdda 100644 --- a/hcl2template/types.source.go +++ b/hcl2template/types.source.go @@ -147,8 +147,8 @@ func (cfg *PackerConfig) startBuilder(source SourceUseBlock, ectx *hcl.EvalConte } // These variables will populate the PackerConfig inside of the builders. -func (source *SourceUseBlock) builderVariables() map[string]interface{} { - return map[string]interface{}{ +func (source *SourceUseBlock) builderVariables() map[string]any { + return map[string]any{ "packer_build_name": source.Name, "packer_builder_type": source.Type, } diff --git a/hcl2template/utils.go b/hcl2template/utils.go index 1b17644d3cf..72258ff0772 100644 --- a/hcl2template/utils.go +++ b/hcl2template/utils.go @@ -127,7 +127,7 @@ func PrintableCtyValue(v cty.Value) string { return str } -func ConvertPluginConfigValueToHCLValue(v interface{}) (cty.Value, error) { +func ConvertPluginConfigValueToHCLValue(v any) (cty.Value, error) { var buildValue cty.Value switch v := v.(type) { case bool: diff --git a/internal/attestation/dsse.go b/internal/attestation/dsse.go index e52135d99ad..6be3268063a 100644 --- a/internal/attestation/dsse.go +++ b/internal/attestation/dsse.go @@ -23,7 +23,7 @@ type EnvelopeSignature struct { Cert string `json:"cert,omitempty"` } -func MarshalPayload(value interface{}) ([]byte, error) { +func MarshalPayload(value any) ([]byte, error) { return json.Marshal(value) } diff --git a/internal/attestation/sign_kms_keyless_test.go b/internal/attestation/sign_kms_keyless_test.go index d9abc346014..549716813f8 100644 --- a/internal/attestation/sign_kms_keyless_test.go +++ b/internal/attestation/sign_kms_keyless_test.go @@ -662,7 +662,7 @@ func currentProcessEnv() map[string]string { return env } -func mustJSONMarshal(t *testing.T, value interface{}) []byte { +func mustJSONMarshal(t *testing.T, value any) []byte { t.Helper() encoded, err := json.Marshal(value) diff --git a/internal/dag/edge.go b/internal/dag/edge.go index 0017ba27b74..6a4a8e133c6 100644 --- a/internal/dag/edge.go +++ b/internal/dag/edge.go @@ -23,8 +23,8 @@ type basicEdge struct { S, T Vertex } -func (e *basicEdge) Hashcode() interface{} { - return [...]interface{}{e.S, e.T} +func (e *basicEdge) Hashcode() any { + return [...]any{e.S, e.T} } func (e *basicEdge) Source() Vertex { diff --git a/internal/dag/graph.go b/internal/dag/graph.go index 31f6f4c80ed..903547ab203 100644 --- a/internal/dag/graph.go +++ b/internal/dag/graph.go @@ -13,8 +13,8 @@ import ( type Graph struct { vertices Set edges Set - downEdges map[interface{}]Set - upEdges map[interface{}]Set + downEdges map[any]Set + upEdges map[any]Set } // Subgrapher allows a Vertex to be a Graph itself, by returning a Grapher. @@ -30,7 +30,7 @@ type Grapher interface { } // Vertex of the graph. -type Vertex interface{} +type Vertex any // NamedVertex is an optional interface that can be implemented by Vertex // to give it a human-friendly name that is used for outputting the graph. @@ -207,10 +207,10 @@ func (g *Graph) init() { g.edges = make(Set) } if g.downEdges == nil { - g.downEdges = make(map[interface{}]Set) + g.downEdges = make(map[any]Set) } if g.upEdges == nil { - g.upEdges = make(map[interface{}]Set) + g.upEdges = make(map[any]Set) } } diff --git a/internal/dag/graph_test.go b/internal/dag/graph_test.go index 909e4c32254..4c6821f9bb9 100644 --- a/internal/dag/graph_test.go +++ b/internal/dag/graph_test.go @@ -127,10 +127,10 @@ func TestGraphEdgesTo(t *testing.T) { } type hashVertex struct { - code interface{} + code any } -func (v *hashVertex) Hashcode() interface{} { +func (v *hashVertex) Hashcode() any { return v.code } diff --git a/internal/dag/set.go b/internal/dag/set.go index d905ee13b7b..c0f8f1e0ed4 100644 --- a/internal/dag/set.go +++ b/internal/dag/set.go @@ -4,17 +4,17 @@ package dag // Set is a set data structure. -type Set map[interface{}]interface{} +type Set map[any]any // Hashable is the interface used by set to get the hash code of a value. // If this isn't given, then the value of the item being added to the set // itself is used as the comparison value. type Hashable interface { - Hashcode() interface{} + Hashcode() any } // hashcode returns the hashcode used for set elements. -func hashcode(v interface{}) interface{} { +func hashcode(v any) any { if h, ok := v.(Hashable); ok { return h.Hashcode() } @@ -23,17 +23,17 @@ func hashcode(v interface{}) interface{} { } // Add adds an item to the set -func (s Set) Add(v interface{}) { +func (s Set) Add(v any) { s[hashcode(v)] = v } // Delete removes an item from the set. -func (s Set) Delete(v interface{}) { +func (s Set) Delete(v any) { delete(s, hashcode(v)) } // Include returns true/false of whether a value is in the set. -func (s Set) Include(v interface{}) bool { +func (s Set) Include(v any) bool { _, ok := s[hashcode(v)] return ok } @@ -75,7 +75,7 @@ func (s Set) Difference(other Set) Set { // Filter returns a set that contains the elements from the receiver // where the given callback returns true. -func (s Set) Filter(cb func(interface{}) bool) Set { +func (s Set) Filter(cb func(any) bool) Set { result := make(Set) for _, v := range s { @@ -93,12 +93,12 @@ func (s Set) Len() int { } // List returns the list of set elements. -func (s Set) List() []interface{} { +func (s Set) List() []any { if s == nil { return nil } - r := make([]interface{}, 0, len(s)) + r := make([]any, 0, len(s)) for _, v := range s { r = append(r, v) } diff --git a/internal/dag/set_test.go b/internal/dag/set_test.go index 1e34ad3aa60..dc99db90367 100644 --- a/internal/dag/set_test.go +++ b/internal/dag/set_test.go @@ -11,34 +11,34 @@ import ( func TestSetDifference(t *testing.T) { cases := []struct { Name string - A, B []interface{} - Expected []interface{} + A, B []any + Expected []any }{ { "same", - []interface{}{1, 2, 3}, - []interface{}{3, 1, 2}, - []interface{}{}, + []any{1, 2, 3}, + []any{3, 1, 2}, + []any{}, }, { "A has extra elements", - []interface{}{1, 2, 3}, - []interface{}{3, 2}, - []interface{}{1}, + []any{1, 2, 3}, + []any{3, 2}, + []any{1}, }, { "B has extra elements", - []interface{}{1, 2, 3}, - []interface{}{3, 2, 1, 4}, - []interface{}{}, + []any{1, 2, 3}, + []any{3, 2, 1, 4}, + []any{}, }, { "B is nil", - []interface{}{1, 2, 3}, + []any{1, 2, 3}, nil, - []interface{}{1, 2, 3}, + []any{1, 2, 3}, }, } @@ -71,22 +71,22 @@ func TestSetDifference(t *testing.T) { func TestSetFilter(t *testing.T) { cases := []struct { - Input []interface{} - Expected []interface{} + Input []any + Expected []any }{ { - []interface{}{1, 2, 3}, - []interface{}{1, 2, 3}, + []any{1, 2, 3}, + []any{1, 2, 3}, }, { - []interface{}{4, 5, 6}, - []interface{}{4}, + []any{4, 5, 6}, + []any{4}, }, { - []interface{}{7, 8, 9}, - []interface{}{}, + []any{7, 8, 9}, + []any{}, }, } @@ -101,7 +101,7 @@ func TestSetFilter(t *testing.T) { expected.Add(v) } - actual := input.Filter(func(v interface{}) bool { + actual := input.Filter(func(v any) bool { return v.(int) < 5 }) match := actual.Intersection(expected) diff --git a/internal/hcp/registry/artifact.go b/internal/hcp/registry/artifact.go index 0e4de626f8e..0fc26397b0f 100644 --- a/internal/hcp/registry/artifact.go +++ b/internal/hcp/registry/artifact.go @@ -31,7 +31,7 @@ func (a *registryArtifact) String() string { return fmt.Sprintf("Published metadata to HCP Packer registry packer/%s/versions/%s", a.BucketName, a.VersionID) } -func (*registryArtifact) State(name string) interface{} { +func (*registryArtifact) State(name string) any { return nil } diff --git a/internal/hcp/registry/json_enforced_test.go b/internal/hcp/registry/json_enforced_test.go index 69c7108e5a9..eb7d7909454 100644 --- a/internal/hcp/registry/json_enforced_test.go +++ b/internal/hcp/registry/json_enforced_test.go @@ -23,7 +23,7 @@ func testJSONRegistryWithBuilds(t *testing.T, builderNames ...string) (*JSONRegi builders[name] = &packertemplate.Builder{ Name: name, Type: "test", - Config: map[string]interface{}{}, + Config: map[string]any{}, } } @@ -79,7 +79,7 @@ func TestJSONRegistry_InjectEnforcedProvisioners_AppliesOverride(t *testing.T) { foundOverride := false for _, raw := range provisioner.PrepConfigs { - config, ok := raw.(map[string]interface{}) + config, ok := raw.(map[string]any) if !ok { continue } diff --git a/internal/hcp/registry/metadata/cicd.go b/internal/hcp/registry/metadata/cicd.go index c779a691a5e..fdb324f2ec5 100644 --- a/internal/hcp/registry/metadata/cicd.go +++ b/internal/hcp/registry/metadata/cicd.go @@ -18,8 +18,8 @@ func (g *GithubActions) Detect() error { return nil } -func (g *GithubActions) Details() map[string]interface{} { - env := make(map[string]interface{}) +func (g *GithubActions) Details() map[string]any { + env := make(map[string]any) keys := []string{ "GITHUB_REPOSITORY", "GITHUB_REPOSITORY_ID", @@ -57,8 +57,8 @@ func (g *GitlabCI) Detect() error { return nil } -func (g *GitlabCI) Details() map[string]interface{} { - env := make(map[string]interface{}) +func (g *GitlabCI) Details() map[string]any { + env := make(map[string]any) keys := []string{ "CI_PROJECT_NAME", "CI_PROJECT_ID", @@ -97,8 +97,8 @@ func (b *BitbucketPipelines) Detect() error { return nil } -func (b *BitbucketPipelines) Details() map[string]interface{} { - env := make(map[string]interface{}) +func (b *BitbucketPipelines) Details() map[string]any { + env := make(map[string]any) keys := []string{ "BITBUCKET_REPO_FULL_NAME", "BITBUCKET_REPO_UUID", @@ -139,8 +139,8 @@ func (g *JenkinsCI) Detect() error { return nil } -func (g *JenkinsCI) Details() map[string]interface{} { - env := make(map[string]interface{}) +func (g *JenkinsCI) Details() map[string]any { + env := make(map[string]any) keys := []string{ "JENKINS_URL", "BUILD_URL", @@ -173,7 +173,7 @@ func (g *JenkinsCI) Type() string { return "jenkins" } -func GetCicdMetadata() map[string]interface{} { +func GetCicdMetadata() map[string]any { cicd := []MetadataProvider{ &JenkinsCI{}, &GithubActions{}, @@ -184,7 +184,7 @@ func GetCicdMetadata() map[string]interface{} { for _, c := range cicd { err := c.Detect() if err == nil { - return map[string]interface{}{ + return map[string]any{ "type": c.Type(), "details": c.Details(), } diff --git a/internal/hcp/registry/metadata/os.go b/internal/hcp/registry/metadata/os.go index b4684a3911c..c2a9dcab5fc 100644 --- a/internal/hcp/registry/metadata/os.go +++ b/internal/hcp/registry/metadata/os.go @@ -33,7 +33,7 @@ func (d DefaultExecutor) Exec(name string, arg ...string) ([]byte, error) { var executor CommandExecutor = DefaultExecutor{} -func GetOSMetadata() map[string]interface{} { +func GetOSMetadata() map[string]any { var osInfo OSInfo switch runtime.GOOS { @@ -56,9 +56,9 @@ func GetOSMetadata() map[string]interface{} { } } - return map[string]interface{}{ + return map[string]any{ "type": osInfo.Name, - "details": map[string]interface{}{ + "details": map[string]any{ "arch": osInfo.Arch, "version": osInfo.Version, }, diff --git a/internal/hcp/registry/metadata/vcs.go b/internal/hcp/registry/metadata/vcs.go index 86d03005ac8..2761713c335 100644 --- a/internal/hcp/registry/metadata/vcs.go +++ b/internal/hcp/registry/metadata/vcs.go @@ -12,7 +12,7 @@ import ( type MetadataProvider interface { Detect() error - Details() map[string]interface{} + Details() map[string]any Type() string } @@ -55,14 +55,14 @@ func (g *Git) Type() string { return "git" } -func (g *Git) Details() map[string]interface{} { +func (g *Git) Details() map[string]any { headRef, err := g.repo.Head() if err != nil { log.Printf("[ERROR] failed to get reference to git HEAD: %s", err) return nil } - resp := map[string]interface{}{ + resp := map[string]any{ "ref": headRef.Name().Short(), } @@ -78,7 +78,7 @@ func (g *Git) Details() map[string]interface{} { return resp } -func GetVcsMetadata() map[string]interface{} { +func GetVcsMetadata() map[string]any { vcsSystems := []MetadataProvider{ &Git{}, } @@ -86,7 +86,7 @@ func GetVcsMetadata() map[string]interface{} { for _, vcs := range vcsSystems { err := vcs.Detect() if err == nil { - return map[string]interface{}{ + return map[string]any{ "type": vcs.Type(), "details": vcs.Details(), } diff --git a/internal/hcp/registry/types.bucket_test.go b/internal/hcp/registry/types.bucket_test.go index 6f9c6cb78e0..8a451df1c36 100644 --- a/internal/hcp/registry/types.bucket_test.go +++ b/internal/hcp/registry/types.bucket_test.go @@ -425,7 +425,7 @@ func TestCompleteBuild(t *testing.T) { BuilderIdValue: "builder.test", FilesValue: []string{"file.one"}, IdValue: "Test", - StateValues: map[string]interface{}{ + StateValues: map[string]any{ "builder.test": "OK", image.ArtifactStateURI: &image.Image{ ImageID: "hcp-test", @@ -442,7 +442,7 @@ func TestCompleteBuild(t *testing.T) { BuilderIdValue: "builder.test", FilesValue: []string{"file.one"}, IdValue: "Test", - StateValues: map[string]interface{}{ + StateValues: map[string]any{ "builder.test": "OK", }, DestroyCalled: false, @@ -645,7 +645,7 @@ func TestBucket_DoCompleteBuild_WithChannels(t *testing.T) { BuilderIdValue: "builder.test", FilesValue: []string{"file.one"}, IdValue: "test-artifact", - StateValues: map[string]interface{}{ + StateValues: map[string]any{ "builder.test": "OK", image.ArtifactStateURI: &image.Image{ ImageID: "hcp-test-image", diff --git a/internal/hcp/registry/types.metadata_store.go b/internal/hcp/registry/types.metadata_store.go index fdbc2f6eb4b..c9bc6d88c23 100644 --- a/internal/hcp/registry/types.metadata_store.go +++ b/internal/hcp/registry/types.metadata_store.go @@ -11,7 +11,7 @@ import "github.com/hashicorp/packer/internal/hcp/registry/metadata" type Metadata interface { // Gather is the point where we vacuum all the information // relevant from the environment in order to expose it to HCP Packer. - Gather(args map[string]interface{}) + Gather(args map[string]any) } // MetadataStore is the effective implementation of a global store for metadata @@ -20,13 +20,13 @@ type Metadata interface { // If HCP is enabled during a build, this is populated with a curated list of // arguments to the build command, and environment-related information. type MetadataStore struct { - PackerBuildCommandOptions map[string]interface{} - OperatingSystem map[string]interface{} - Vcs map[string]interface{} - Cicd map[string]interface{} + PackerBuildCommandOptions map[string]any + OperatingSystem map[string]any + Vcs map[string]any + Cicd map[string]any } -func (ms *MetadataStore) Gather(args map[string]interface{}) { +func (ms *MetadataStore) Gather(args map[string]any) { ms.OperatingSystem = metadata.GetOSMetadata() ms.Cicd = metadata.GetCicdMetadata() ms.Vcs = metadata.GetVcsMetadata() @@ -39,4 +39,4 @@ func (ms *MetadataStore) Gather(args map[string]interface{}) { // collected or kept in memory in this case. type NilMetadata struct{} -func (ns NilMetadata) Gather(args map[string]interface{}) {} +func (ns NilMetadata) Gather(args map[string]any) {} diff --git a/internal/hcp/registry/types.version.go b/internal/hcp/registry/types.version.go index 85be81e6c54..6eceb693e50 100644 --- a/internal/hcp/registry/types.version.go +++ b/internal/hcp/registry/types.version.go @@ -186,12 +186,12 @@ func (version *Version) AddMetadataToBuild( return err } - packerMetadata := make(map[string]interface{}) + packerMetadata := make(map[string]any) packerMetadata["version"] = buildMetadata.PackerVersion - var pluginsMetadata []map[string]interface{} + var pluginsMetadata []map[string]any for _, plugin := range buildMetadata.Plugins { - pluginMetadata := map[string]interface{}{ + pluginMetadata := map[string]any{ "version": plugin.Description.Version, "name": plugin.Name, } diff --git a/internal/provenance/predicate.go b/internal/provenance/predicate.go index 939f9b4fa29..5cb015794e8 100644 --- a/internal/provenance/predicate.go +++ b/internal/provenance/predicate.go @@ -13,8 +13,8 @@ const ( type PredicateInput struct { BuildType string - ExternalParameters map[string]interface{} - InternalParameters map[string]interface{} + ExternalParameters map[string]any + InternalParameters map[string]any ResolvedDependencies []ResolvedDependency BuilderID string Byproducts []Byproduct @@ -29,10 +29,10 @@ type SLSAProvenancePredicate struct { } type BuildDefinition struct { - BuildType string `json:"buildType"` - ExternalParameters map[string]interface{} `json:"externalParameters"` - InternalParameters map[string]interface{} `json:"internalParameters,omitempty"` - ResolvedDependencies []ResolvedDependency `json:"resolvedDependencies,omitempty"` + BuildType string `json:"buildType"` + ExternalParameters map[string]any `json:"externalParameters"` + InternalParameters map[string]any `json:"internalParameters,omitempty"` + ResolvedDependencies []ResolvedDependency `json:"resolvedDependencies,omitempty"` } type ResolvedDependency struct { @@ -58,8 +58,8 @@ type Metadata struct { } type Byproduct struct { - Name string `json:"name"` - Content interface{} `json:"content,omitempty"` + Name string `json:"name"` + Content any `json:"content,omitempty"` } func BuildSLSAPredicate(input PredicateInput) SLSAProvenancePredicate { @@ -73,12 +73,12 @@ func BuildSLSAPredicate(input PredicateInput) SLSAProvenancePredicate { builderID = DefaultLocalBuilderID } - externalParameters := map[string]interface{}{} + externalParameters := map[string]any{} for key, value := range input.ExternalParameters { externalParameters[key] = value } - internalParameters := map[string]interface{}{ + internalParameters := map[string]any{ "packerVersion": packerversion.String(), } for key, value := range input.InternalParameters { diff --git a/internal/provenance/predicate_test.go b/internal/provenance/predicate_test.go index e4629b0d2df..541afd83cb0 100644 --- a/internal/provenance/predicate_test.go +++ b/internal/provenance/predicate_test.go @@ -30,7 +30,7 @@ func TestBuildSLSAPredicateIncludesByproducts(t *testing.T) { BuildType: "https://packer.io/buildtypes/json/v1", Byproducts: []Byproduct{{ Name: "cloud-artifact-identity", - Content: map[string]interface{}{ + Content: map[string]any{ "builderId": "packer.null", }, }}, diff --git a/internal/provenance/statement.go b/internal/provenance/statement.go index af3c01565f9..fd13db56460 100644 --- a/internal/provenance/statement.go +++ b/internal/provenance/statement.go @@ -6,13 +6,13 @@ package provenance const StatementType = "https://in-toto.io/Statement/v1" type Statement struct { - Type string `json:"_type"` - Subject []Subject `json:"subject"` - PredicateType string `json:"predicateType"` - Predicate interface{} `json:"predicate"` + Type string `json:"_type"` + Subject []Subject `json:"subject"` + PredicateType string `json:"predicateType"` + Predicate any `json:"predicate"` } -func WrapInToto(subjects []Subject, predicateType string, predicate interface{}) Statement { +func WrapInToto(subjects []Subject, predicateType string, predicate any) Statement { return Statement{ Type: StatementType, Subject: subjects, diff --git a/internal/provenance/subject.go b/internal/provenance/subject.go index 28f24ed4694..f0550faa919 100644 --- a/internal/provenance/subject.go +++ b/internal/provenance/subject.go @@ -27,7 +27,7 @@ func DeriveSubjects(artifact packersdk.Artifact) ([]Subject, error) { return deriveSubjects(artifact) } -func DeriveIdentityRecord(artifact packersdk.Artifact) (map[string]interface{}, error) { +func DeriveIdentityRecord(artifact packersdk.Artifact) (map[string]any, error) { return deriveIdentityRecord(artifact) } @@ -76,12 +76,12 @@ func deriveSubjects(artifact packersdk.Artifact) ([]Subject, error) { }}, nil } -func deriveIdentityRecord(artifact packersdk.Artifact) (map[string]interface{}, error) { +func deriveIdentityRecord(artifact packersdk.Artifact) (map[string]any, error) { if artifact == nil { return nil, fmt.Errorf("artifact is nil") } - record := map[string]interface{}{ + record := map[string]any{ "builderId": artifact.BuilderId(), "id": artifact.Id(), } @@ -100,13 +100,13 @@ func deriveIdentityRecord(artifact packersdk.Artifact) (map[string]interface{}, return record, nil } -func normalizeJSONValue(value interface{}) (interface{}, error) { +func normalizeJSONValue(value any) (any, error) { encoded, err := json.Marshal(value) if err != nil { return nil, err } - var decoded interface{} + var decoded any if err := json.Unmarshal(encoded, &decoded); err != nil { return nil, err } diff --git a/internal/provenance/subject_test.go b/internal/provenance/subject_test.go index 39007709c66..2647395746e 100644 --- a/internal/provenance/subject_test.go +++ b/internal/provenance/subject_test.go @@ -87,7 +87,7 @@ func buildFileArtifact(t *testing.T) packersdk.Artifact { t.Helper() target := filepath.Join(t.TempDir(), "package.txt") - config := mustTemplateJSON(t, map[string]interface{}{ + config := mustTemplateJSON(t, map[string]any{ "builders": []map[string]string{{ "type": "file", "target": target, @@ -116,7 +116,7 @@ func buildFileArtifact(t *testing.T) packersdk.Artifact { return artifact } -func mustTemplateJSON(t *testing.T, value interface{}) string { +func mustTemplateJSON(t *testing.T, value any) string { t.Helper() encoded, err := json.Marshal(value) diff --git a/main.go b/main.go index 176ecb77326..eb6c20d34b1 100644 --- a/main.go +++ b/main.go @@ -295,7 +295,7 @@ func wrappedMain() int { func excludeHelpFunc(commands map[string]cli.CommandFactory, exclude []string) cli.HelpFunc { // Make search slice into a map so we can use use the `if found` idiom // instead of a nested loop. - var excludes = make(map[string]interface{}, len(exclude)) + var excludes = make(map[string]any, len(exclude)) for _, item := range exclude { excludes[item] = nil } diff --git a/packer/build.go b/packer/build.go index 7ea8cd37777..c592ae02d4c 100644 --- a/packer/build.go +++ b/packer/build.go @@ -29,7 +29,7 @@ type CoreBuild struct { // // Is is deserialised directly from the JSON template, // and is only populated for legacy JSON templates. - BuilderConfig interface{} + BuilderConfig any // HCLConfig is the HCL config for the builder // // Its only use is for telemetry, since we use it to extract the @@ -118,7 +118,7 @@ type CoreBuildPostProcessor struct { HCLConfig cty.Value // config is JSON-specific, the configuration for the post-processor // deserialised directly from the JSON template - config map[string]interface{} + config map[string]any KeepInputArtifact *bool } @@ -135,7 +135,7 @@ type CoreBuildProvisioner struct { HCLConfig cty.Value // config is JSON-specific, and is the configuration of the // provisioner, with overrides - config []interface{} + config []any } // Returns the name of the build. @@ -146,8 +146,8 @@ func (b *CoreBuild) Name() string { return b.Type } -func (b *CoreBuild) packerConfig() map[string]interface{} { - return map[string]interface{}{ +func (b *CoreBuild) packerConfig() map[string]any { + return map[string]any{ common.BuildNameConfigKey: b.Type, common.BuilderTypeConfigKey: b.BuilderType, common.CoreVersionConfigKey: version.FormattedVersion(), @@ -160,11 +160,11 @@ func (b *CoreBuild) packerConfig() map[string]interface{} { } } -func (b *CoreBuild) prepareProvisioners(provisioners []CoreBuildProvisioner, packerConfig map[string]interface{}, generatedVars []string) error { +func (b *CoreBuild) prepareProvisioners(provisioners []CoreBuildProvisioner, packerConfig map[string]any, generatedVars []string) error { generatedPlaceholderMap := placeholderDataFromGeneratedVars(generatedVars) for _, coreProv := range provisioners { - configs := make([]interface{}, len(coreProv.config), len(coreProv.config)+2) + configs := make([]any, len(coreProv.config), len(coreProv.config)+2) copy(configs, coreProv.config) configs = append(configs, packerConfig, generatedPlaceholderMap) @@ -243,7 +243,7 @@ func (b *CoreBuild) Prepare() (warn []string, err error) { // Prepare the on-error-cleanup provisioner if b.CleanupProvisioner.PType != "" { - configs := make([]interface{}, len(b.CleanupProvisioner.config), len(b.CleanupProvisioner.config)+2) + configs := make([]any, len(b.CleanupProvisioner.config), len(b.CleanupProvisioner.config)+2) copy(configs, b.CleanupProvisioner.config) configs = append(configs, packerConfig, generatedPlaceholderMap) err = b.CleanupProvisioner.Provisioner.Prepare(configs...) @@ -282,7 +282,7 @@ func (b *CoreBuild) Run(ctx context.Context, originalUi packersdk.Ui) ([]packers if len(b.Provisioners) > 0 { hookedProvisioners := make([]*HookedProvisioner, len(b.Provisioners)) for i, p := range b.Provisioners { - var pConfig interface{} + var pConfig any if len(p.config) > 0 { pConfig = p.config[0] } else { diff --git a/packer/build_test.go b/packer/build_test.go index 9f810381954..3eca7b5d6bf 100644 --- a/packer/build_test.go +++ b/packer/build_test.go @@ -32,11 +32,11 @@ func testBuild() *CoreBuild { { PType: "mock-provisioner", Provisioner: &packersdk.MockProvisioner{}, - config: []interface{}{42}}, + config: []any{42}}, }, PostProcessors: [][]CoreBuildPostProcessor{ { - {&MockPostProcessor{ArtifactId: "pp"}, "testPP", "testPPName", cty.Value{}, make(map[string]interface{}), boolPointer(true)}, + {&MockPostProcessor{ArtifactId: "pp"}, "testPP", "testPPName", cty.Value{}, make(map[string]any), boolPointer(true)}, }, }, Variables: make(map[string]string), @@ -45,8 +45,8 @@ func testBuild() *CoreBuild { } } -func testDefaultPackerConfig() map[string]interface{} { - return map[string]interface{}{ +func testDefaultPackerConfig() map[string]any { + return map[string]any{ common.BuildNameConfigKey: "test", common.BuilderTypeConfigKey: "foo", common.CoreVersionConfigKey: version.FormattedVersion(), @@ -75,7 +75,7 @@ func TestBuild_Prepare(t *testing.T) { if !builder.PrepareCalled { t.Fatal("should be called") } - if !reflect.DeepEqual(builder.PrepareConfig, []interface{}{42, packerConfig}) { + if !reflect.DeepEqual(builder.PrepareConfig, []any{42, packerConfig}) { t.Fatalf("bad: %#v", builder.PrepareConfig) } @@ -84,7 +84,7 @@ func TestBuild_Prepare(t *testing.T) { if !prov.PrepCalled { t.Fatal("prep should be called") } - if !reflect.DeepEqual(prov.PrepConfigs, []interface{}{42, packerConfig, BasicPlaceholderData()}) { + if !reflect.DeepEqual(prov.PrepConfigs, []any{42, packerConfig, BasicPlaceholderData()}) { t.Fatalf("bad: %#v", prov.PrepConfigs) } @@ -93,7 +93,7 @@ func TestBuild_Prepare(t *testing.T) { if !pp.ConfigureCalled { t.Fatal("should be called") } - if !reflect.DeepEqual(pp.ConfigureConfigs, []interface{}{make(map[string]interface{}), packerConfig, BasicPlaceholderData()}) { + if !reflect.DeepEqual(pp.ConfigureConfigs, []any{make(map[string]any), packerConfig, BasicPlaceholderData()}) { t.Fatalf("bad: %#v", pp.ConfigureConfigs) } } @@ -161,7 +161,7 @@ func TestBuild_Prepare_Debug(t *testing.T) { if !builder.PrepareCalled { t.Fatalf("should be called") } - if !reflect.DeepEqual(builder.PrepareConfig, []interface{}{42, packerConfig}) { + if !reflect.DeepEqual(builder.PrepareConfig, []any{42, packerConfig}) { t.Fatalf("bad: %#v", builder.PrepareConfig) } @@ -170,7 +170,7 @@ func TestBuild_Prepare_Debug(t *testing.T) { if !prov.PrepCalled { t.Fatal("prepare should be called") } - if !reflect.DeepEqual(prov.PrepConfigs, []interface{}{42, packerConfig, BasicPlaceholderData()}) { + if !reflect.DeepEqual(prov.PrepConfigs, []any{42, packerConfig, BasicPlaceholderData()}) { t.Fatalf("bad: %#v", prov.PrepConfigs) } } @@ -213,7 +213,7 @@ func TestBuildPrepare_ProvisionerGetsGeneratedMap(t *testing.T) { if !builder.PrepareCalled { t.Fatalf("should be called") } - if !reflect.DeepEqual(builder.PrepareConfig, []interface{}{42, packerConfig}) { + if !reflect.DeepEqual(builder.PrepareConfig, []any{42, packerConfig}) { t.Fatalf("bad: %#v", builder.PrepareConfig) } @@ -225,7 +225,7 @@ func TestBuildPrepare_ProvisionerGetsGeneratedMap(t *testing.T) { generated := BasicPlaceholderData() generated["PartyVar"] = "Build_PartyVar. " + packerbuilderdata.PlaceholderMsg - if !reflect.DeepEqual(prov.PrepConfigs, []interface{}{42, packerConfig, generated}) { + if !reflect.DeepEqual(prov.PrepConfigs, []any{42, packerConfig, generated}) { t.Fatalf("bad: %#v", prov.PrepConfigs) } } @@ -246,7 +246,7 @@ func TestBuild_PrepareProvisioners_ReusesStoredGeneratedVars(t *testing.T) { lateProv := CoreBuildProvisioner{ PType: "mock-provisioner", Provisioner: &packersdk.MockProvisioner{}, - config: []interface{}{84}, + config: []any{84}, } if err := build.PrepareProvisioners(lateProv); err != nil { @@ -260,7 +260,7 @@ func TestBuild_PrepareProvisioners_ReusesStoredGeneratedVars(t *testing.T) { prov := lateProv.Provisioner.(*packersdk.MockProvisioner) generated := BasicPlaceholderData() generated["PartyVar"] = "Build_PartyVar. " + packerbuilderdata.PlaceholderMsg - if !reflect.DeepEqual(prov.PrepConfigs, []interface{}{84, packerConfig, generated}) { + if !reflect.DeepEqual(prov.PrepConfigs, []any{84, packerConfig, generated}) { t.Fatalf("bad: %#v", prov.PrepConfigs) } } @@ -280,7 +280,7 @@ func TestBuild_PrepareProvisioners_ReusesStoredGeneratedVarsForPreparedBuild(t * lateProv := CoreBuildProvisioner{ PType: "mock-provisioner", Provisioner: &packersdk.MockProvisioner{}, - config: []interface{}{84}, + config: []any{84}, } if err := build.PrepareProvisioners(lateProv); err != nil { @@ -294,7 +294,7 @@ func TestBuild_PrepareProvisioners_ReusesStoredGeneratedVarsForPreparedBuild(t * prov := lateProv.Provisioner.(*packersdk.MockProvisioner) generated := BasicPlaceholderData() generated["PartyVar"] = "Build_PartyVar. " + packerbuilderdata.PlaceholderMsg - if !reflect.DeepEqual(prov.PrepConfigs, []interface{}{84, packerConfig, generated}) { + if !reflect.DeepEqual(prov.PrepConfigs, []any{84, packerConfig, generated}) { t.Fatalf("bad: %#v", prov.PrepConfigs) } } @@ -304,7 +304,7 @@ func TestBuild_PrepareProvisioners_RequiresPrepare(t *testing.T) { lateProv := CoreBuildProvisioner{ PType: "mock-provisioner", Provisioner: &packersdk.MockProvisioner{}, - config: []interface{}{84}, + config: []any{84}, } err := build.PrepareProvisioners(lateProv) @@ -394,7 +394,7 @@ func TestBuild_Run_Artifacts(t *testing.T) { build = testBuild() build.PostProcessors = [][]CoreBuildPostProcessor{ { - {&MockPostProcessor{ArtifactId: "pp"}, "pp", "testPPName", cty.Value{}, make(map[string]interface{}), boolPointer(false)}, + {&MockPostProcessor{ArtifactId: "pp"}, "pp", "testPPName", cty.Value{}, make(map[string]any), boolPointer(false)}, }, } @@ -419,10 +419,10 @@ func TestBuild_Run_Artifacts(t *testing.T) { build = testBuild() build.PostProcessors = [][]CoreBuildPostProcessor{ { - {&MockPostProcessor{ArtifactId: "pp1"}, "pp", "testPPName", cty.Value{}, make(map[string]interface{}), boolPointer(false)}, + {&MockPostProcessor{ArtifactId: "pp1"}, "pp", "testPPName", cty.Value{}, make(map[string]any), boolPointer(false)}, }, { - {&MockPostProcessor{ArtifactId: "pp2"}, "pp", "testPPName", cty.Value{}, make(map[string]interface{}), boolPointer(true)}, + {&MockPostProcessor{ArtifactId: "pp2"}, "pp", "testPPName", cty.Value{}, make(map[string]any), boolPointer(true)}, }, } @@ -447,12 +447,12 @@ func TestBuild_Run_Artifacts(t *testing.T) { build = testBuild() build.PostProcessors = [][]CoreBuildPostProcessor{ { - {&MockPostProcessor{ArtifactId: "pp1a"}, "pp", "testPPName", cty.Value{}, make(map[string]interface{}), boolPointer(false)}, - {&MockPostProcessor{ArtifactId: "pp1b"}, "pp", "testPPName", cty.Value{}, make(map[string]interface{}), boolPointer(true)}, + {&MockPostProcessor{ArtifactId: "pp1a"}, "pp", "testPPName", cty.Value{}, make(map[string]any), boolPointer(false)}, + {&MockPostProcessor{ArtifactId: "pp1b"}, "pp", "testPPName", cty.Value{}, make(map[string]any), boolPointer(true)}, }, { - {&MockPostProcessor{ArtifactId: "pp2a"}, "pp", "testPPName", cty.Value{}, make(map[string]interface{}), boolPointer(false)}, - {&MockPostProcessor{ArtifactId: "pp2b"}, "pp", "testPPName", cty.Value{}, make(map[string]interface{}), boolPointer(false)}, + {&MockPostProcessor{ArtifactId: "pp2a"}, "pp", "testPPName", cty.Value{}, make(map[string]any), boolPointer(false)}, + {&MockPostProcessor{ArtifactId: "pp2b"}, "pp", "testPPName", cty.Value{}, make(map[string]any), boolPointer(false)}, }, } @@ -478,7 +478,7 @@ func TestBuild_Run_Artifacts(t *testing.T) { build.PostProcessors = [][]CoreBuildPostProcessor{ { { - &MockPostProcessor{ArtifactId: "pp", Keep: true, ForceOverride: true}, "pp", "testPPName", cty.Value{}, make(map[string]interface{}), boolPointer(false), + &MockPostProcessor{ArtifactId: "pp", Keep: true, ForceOverride: true}, "pp", "testPPName", cty.Value{}, make(map[string]any), boolPointer(false), }, }, } @@ -506,7 +506,7 @@ func TestBuild_Run_Artifacts(t *testing.T) { build.PostProcessors = [][]CoreBuildPostProcessor{ { { - &MockPostProcessor{ArtifactId: "pp", Keep: true, ForceOverride: false}, "pp", "testPPName", cty.Value{}, make(map[string]interface{}), boolPointer(false), + &MockPostProcessor{ArtifactId: "pp", Keep: true, ForceOverride: false}, "pp", "testPPName", cty.Value{}, make(map[string]any), boolPointer(false), }, }, } @@ -533,7 +533,7 @@ func TestBuild_Run_Artifacts(t *testing.T) { build.PostProcessors = [][]CoreBuildPostProcessor{ { { - &MockPostProcessor{ArtifactId: "pp", Keep: true, ForceOverride: false}, "pp", "testPPName", cty.Value{}, make(map[string]interface{}), nil, + &MockPostProcessor{ArtifactId: "pp", Keep: true, ForceOverride: false}, "pp", "testPPName", cty.Value{}, make(map[string]any), nil, }, }, } diff --git a/packer/cmd_builder.go b/packer/cmd_builder.go index 177d86f14d4..0018d57c3dc 100644 --- a/packer/cmd_builder.go +++ b/packer/cmd_builder.go @@ -25,7 +25,7 @@ func (b *cmdBuilder) ConfigSpec() hcldec.ObjectSpec { return b.builder.ConfigSpec() } -func (b *cmdBuilder) Prepare(config ...interface{}) ([]string, []string, error) { +func (b *cmdBuilder) Prepare(config ...any) ([]string, []string, error) { defer func() { r := recover() b.checkExit(r, nil) @@ -43,7 +43,7 @@ func (b *cmdBuilder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Ho return b.builder.Run(ctx, ui, hook) } -func (c *cmdBuilder) checkExit(p interface{}, cb func()) { +func (c *cmdBuilder) checkExit(p any, cb func()) { if c.client.Exited() && cb != nil { cb() } else if p != nil && !Killed { diff --git a/packer/cmd_datasource.go b/packer/cmd_datasource.go index 4efd768fec6..39537a00ed2 100644 --- a/packer/cmd_datasource.go +++ b/packer/cmd_datasource.go @@ -25,7 +25,7 @@ func (d *cmdDatasource) ConfigSpec() hcldec.ObjectSpec { return d.d.ConfigSpec() } -func (d *cmdDatasource) Configure(configs ...interface{}) error { +func (d *cmdDatasource) Configure(configs ...any) error { defer func() { r := recover() d.checkExit(r, nil) @@ -52,7 +52,7 @@ func (d *cmdDatasource) Execute() (cty.Value, error) { return d.d.Execute() } -func (d *cmdDatasource) checkExit(p interface{}, cb func()) { +func (d *cmdDatasource) checkExit(p any, cb func()) { if d.client.Exited() && cb != nil { cb() } else if p != nil && !Killed { diff --git a/packer/cmd_hook.go b/packer/cmd_hook.go index 3dc7d518a3e..120c1890e21 100644 --- a/packer/cmd_hook.go +++ b/packer/cmd_hook.go @@ -15,7 +15,7 @@ type cmdHook struct { client *PluginClient } -func (c *cmdHook) Run(ctx context.Context, name string, ui packersdk.Ui, comm packersdk.Communicator, data interface{}) error { +func (c *cmdHook) Run(ctx context.Context, name string, ui packersdk.Ui, comm packersdk.Communicator, data any) error { defer func() { r := recover() c.checkExit(r, nil) @@ -24,7 +24,7 @@ func (c *cmdHook) Run(ctx context.Context, name string, ui packersdk.Ui, comm pa return c.hook.Run(ctx, name, ui, comm, data) } -func (c *cmdHook) checkExit(p interface{}, cb func()) { +func (c *cmdHook) checkExit(p any, cb func()) { if c.client.Exited() && cb != nil { cb() } else if p != nil && !Killed { diff --git a/packer/cmd_post_processor.go b/packer/cmd_post_processor.go index 4c6d92033bf..22b914f194d 100644 --- a/packer/cmd_post_processor.go +++ b/packer/cmd_post_processor.go @@ -25,7 +25,7 @@ func (b *cmdPostProcessor) ConfigSpec() hcldec.ObjectSpec { return b.p.ConfigSpec() } -func (c *cmdPostProcessor) Configure(config ...interface{}) error { +func (c *cmdPostProcessor) Configure(config ...any) error { defer func() { r := recover() c.checkExit(r, nil) @@ -43,7 +43,7 @@ func (c *cmdPostProcessor) PostProcess(ctx context.Context, ui packersdk.Ui, a p return c.p.PostProcess(ctx, ui, a) } -func (c *cmdPostProcessor) checkExit(p interface{}, cb func()) { +func (c *cmdPostProcessor) checkExit(p any, cb func()) { if c.client.Exited() && cb != nil { cb() } else if p != nil && !Killed { diff --git a/packer/cmd_post_processor_test.go b/packer/cmd_post_processor_test.go index fbc29987f3c..f54e9f6a56c 100644 --- a/packer/cmd_post_processor_test.go +++ b/packer/cmd_post_processor_test.go @@ -16,7 +16,7 @@ type helperPostProcessor byte func (helperPostProcessor) ConfigSpec() hcldec.ObjectSpec { return nil } -func (helperPostProcessor) Configure(...interface{}) error { +func (helperPostProcessor) Configure(...any) error { return nil } diff --git a/packer/cmd_provisioner.go b/packer/cmd_provisioner.go index 67ced8efdac..4614efd710e 100644 --- a/packer/cmd_provisioner.go +++ b/packer/cmd_provisioner.go @@ -25,7 +25,7 @@ func (p *cmdProvisioner) ConfigSpec() hcldec.ObjectSpec { return p.p.ConfigSpec() } -func (c *cmdProvisioner) Prepare(configs ...interface{}) error { +func (c *cmdProvisioner) Prepare(configs ...any) error { defer func() { r := recover() c.checkExit(r, nil) @@ -34,7 +34,7 @@ func (c *cmdProvisioner) Prepare(configs ...interface{}) error { return c.p.Prepare(configs...) } -func (c *cmdProvisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, generatedData map[string]interface{}) error { +func (c *cmdProvisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, generatedData map[string]any) error { defer func() { r := recover() c.checkExit(r, nil) @@ -43,7 +43,7 @@ func (c *cmdProvisioner) Provision(ctx context.Context, ui packersdk.Ui, comm pa return c.p.Provision(ctx, ui, comm, generatedData) } -func (c *cmdProvisioner) checkExit(p interface{}, cb func()) { +func (c *cmdProvisioner) checkExit(p any, cb func()) { if c.client.Exited() && cb != nil { cb() } else if p != nil && !Killed { diff --git a/packer/core.go b/packer/core.go index f3788c24641..8f5fbe4689c 100644 --- a/packer/core.go +++ b/packer/core.go @@ -270,7 +270,7 @@ func (c *Core) generateCoreBuildProvisionerWithProvisioner(rawP *template.Provis cbp := CoreBuildProvisioner{} // Get the configuration - config := make([]interface{}, 1, 2) + config := make([]any, 1, 2) config[0] = rawP.Config if rawP.Override != nil { if override, ok := rawP.Override[rawName]; ok { @@ -327,7 +327,7 @@ func (c *Core) generateCoreBuildProvisionerWithProvisioner(rawP *template.Provis func (c *Core) GenerateCoreBuildProvisionerFromHCLBody( provisionerType string, configBody hcl.Body, - override map[string]interface{}, + override map[string]any, pauseBefore time.Duration, maxRetries int, timeout time.Duration, @@ -367,9 +367,9 @@ func (c *Core) GenerateCoreBuildProvisionerFromHCLBody( flatProvisionerCfg = hcl2shim.WriteUnknownPlaceholderValues(flatProvisionerCfg) decodedConfig := hcl2shim.ConfigValueFromHCL2(flatProvisionerCfg) - configMap, _ := decodedConfig.(map[string]interface{}) + configMap, _ := decodedConfig.(map[string]any) if configMap == nil { - configMap = make(map[string]interface{}) + configMap = make(map[string]any) } rawProvisioner := &template.Provisioner{ @@ -799,9 +799,9 @@ func (c *Core) FixConfig(opts FixConfigOptions) hcl.Diagnostics { return diags } - var rawTemplateData map[string]interface{} - input := make(map[string]interface{}) - templateData := make(map[string]interface{}) + var rawTemplateData map[string]any + input := make(map[string]any) + templateData := make(map[string]any) if err := json.Unmarshal(c.Template.RawContents, &rawTemplateData); err != nil { diags = append(diags, &hcl.Diagnostic{ Severity: hcl.DiagError, @@ -814,7 +814,7 @@ func (c *Core) FixConfig(opts FixConfigOptions) hcl.Diagnostics { // delete empty top-level keys since the fixers seem to add them // willy-nilly for k := range input { - ml, ok := input[k].([]map[string]interface{}) + ml, ok := input[k].([]map[string]any) if !ok { continue } @@ -823,7 +823,7 @@ func (c *Core) FixConfig(opts FixConfigOptions) hcl.Diagnostics { } } // marshal/unmarshal to make comparable to templateData - var fixedData map[string]interface{} + var fixedData map[string]any // Guaranteed to be valid json, so we can ignore errors j, _ := json.Marshal(input) if err := json.Unmarshal(j, &fixedData); err != nil { diff --git a/packer/core_test.go b/packer/core_test.go index da06e6d49c8..15d5fedda93 100644 --- a/packer/core_test.go +++ b/packer/core_test.go @@ -146,7 +146,7 @@ func TestCoreBuild_env(t *testing.T) { } // Interpolate the config - var result map[string]interface{} + var result map[string]any err = configHelper.Decode(&result, nil, b.PrepareConfig...) if err != nil { t.Fatalf("err: %s", err) @@ -204,7 +204,7 @@ func TestCoreBuild_buildNameVar(t *testing.T) { } // Interpolate the config - var result map[string]interface{} + var result map[string]any err = configHelper.Decode(&result, nil, b.PrepareConfig...) if err != nil { t.Fatalf("err: %s", err) @@ -233,7 +233,7 @@ func TestCoreBuild_buildTypeVar(t *testing.T) { } // Interpolate the config - var result map[string]interface{} + var result map[string]any err = configHelper.Decode(&result, nil, b.PrepareConfig...) if err != nil { t.Fatalf("err: %s", err) @@ -393,7 +393,7 @@ func TestCoreBuild_provOverride(t *testing.T) { found := false for _, raw := range p.PrepConfigs { - if m, ok := raw.(map[string]interface{}); ok { + if m, ok := raw.(map[string]any); ok { if _, ok := m["foo"]; ok { found = true break @@ -459,7 +459,7 @@ func TestCoreBuild_templatePath(t *testing.T) { } // Interpolate the config - var result map[string]interface{} + var result map[string]any err = configHelper.Decode(&result, nil, b.PrepareConfig...) if err != nil { t.Fatalf("err: %s", err) @@ -866,7 +866,7 @@ func TestCoreBuild_packerVersion(t *testing.T) { t.Fatalf("err: %s", err) } // Interpolate the config - var result map[string]interface{} + var result map[string]any err = configHelper.Decode(&result, nil, b.PrepareConfig...) if err != nil { t.Fatalf("err: %s", err) diff --git a/packer/plugin-getter/plugins_test.go b/packer/plugin-getter/plugins_test.go index 0e47a023c01..f1c55b14adc 100644 --- a/packer/plugin-getter/plugins_test.go +++ b/packer/plugin-getter/plugins_test.go @@ -900,7 +900,7 @@ func (g *mockPluginGetter) ExpectedFileName(pr *Requirement, version string, ent func (g *mockPluginGetter) Get(what string, options GetOptions) (io.ReadCloser, error) { - var toEncode interface{} + var toEncode any switch what { case "releases": toEncode = g.Releases diff --git a/packer/post_processor_mock.go b/packer/post_processor_mock.go index 6fa30af6a70..51b4079e178 100644 --- a/packer/post_processor_mock.go +++ b/packer/post_processor_mock.go @@ -20,7 +20,7 @@ type MockPostProcessor struct { Error error ConfigureCalled bool - ConfigureConfigs []interface{} + ConfigureConfigs []any ConfigureError error PostProcessCalled bool @@ -30,7 +30,7 @@ type MockPostProcessor struct { func (t *MockPostProcessor) ConfigSpec() hcldec.ObjectSpec { return t.FlatMapstructure().HCL2Spec() } -func (t *MockPostProcessor) Configure(configs ...interface{}) error { +func (t *MockPostProcessor) Configure(configs ...any) error { t.ConfigureCalled = true t.ConfigureConfigs = configs return t.ConfigureError diff --git a/packer/post_processor_mock.hcl2spec.go b/packer/post_processor_mock.hcl2spec.go index 51829b0e487..5c72865df54 100644 --- a/packer/post_processor_mock.hcl2spec.go +++ b/packer/post_processor_mock.hcl2spec.go @@ -16,7 +16,7 @@ type FlatMockPostProcessor struct { ForceOverride *bool `cty:"force_override" hcl:"force_override"` Error error `cty:"error" hcl:"error"` ConfigureCalled *bool `cty:"configure_called" hcl:"configure_called"` - ConfigureConfigs []interface{} `cty:"configure_configs" hcl:"configure_configs"` + ConfigureConfigs []any `cty:"configure_configs" hcl:"configure_configs"` ConfigureError error `cty:"configure_error" hcl:"configure_error"` PostProcessCalled *bool `cty:"post_process_called" hcl:"post_process_called"` PostProcessArtifact packer.Artifact `cty:"post_process_artifact" hcl:"post_process_artifact"` diff --git a/packer/provisioner.go b/packer/provisioner.go index 69dfadcfd99..ce2b02b5ee0 100644 --- a/packer/provisioner.go +++ b/packer/provisioner.go @@ -25,7 +25,7 @@ import ( // A HookedProvisioner represents a provisioner and information describing it type HookedProvisioner struct { Provisioner packersdk.Provisioner - Config interface{} + Config any TypeName string } @@ -83,9 +83,9 @@ func BasicPlaceholderData() map[string]string { return placeholderData } -func CastDataToMap(data interface{}) map[string]interface{} { +func CastDataToMap(data any) map[string]any { - if interMap, ok := data.(map[string]interface{}); ok { + if interMap, ok := data.(map[string]any); ok { // null and file builder sometimes don't use a communicator and // therefore don't go through RPC return interMap @@ -94,8 +94,8 @@ func CastDataToMap(data interface{}) map[string]interface{} { // Provisioners expect a map[string]interface{} in their data field, but // it gets converted into a map[interface]interface on the way over the // RPC. Check that data can be cast into such a form, and cast it. - cast := make(map[string]interface{}) - interMap, ok := data.(map[interface{}]interface{}) + cast := make(map[string]any) + interMap, ok := data.(map[any]any) if !ok { log.Printf("Unable to read map[string]interface out of data."+ "Using empty interface: %#v", data) @@ -113,7 +113,7 @@ func CastDataToMap(data interface{}) map[string]interface{} { } // Runs the provisioners in order. -func (h *ProvisionHook) Run(ctx context.Context, name string, ui packersdk.Ui, comm packersdk.Communicator, data interface{}) error { +func (h *ProvisionHook) Run(ctx context.Context, name string, ui packersdk.Ui, comm packersdk.Communicator, data any) error { // Shortcut if len(h.Provisioners) == 0 { return nil @@ -191,13 +191,20 @@ type PausedProvisioner struct { Provisioner packersdk.Provisioner } -func (p *PausedProvisioner) ConfigSpec() hcldec.ObjectSpec { return p.ConfigSpec() } -func (p *PausedProvisioner) FlatConfig() interface{} { return p.FlatConfig() } -func (p *PausedProvisioner) Prepare(raws ...interface{}) error { +func (p *PausedProvisioner) ConfigSpec() hcldec.ObjectSpec { + return p.Provisioner.ConfigSpec() +} +func (p *PausedProvisioner) FlatConfig() any { + if fc, ok := p.Provisioner.(interface{ FlatConfig() any }); ok { + return fc.FlatConfig() + } + return nil +} +func (p *PausedProvisioner) Prepare(raws ...any) error { return p.Provisioner.Prepare(raws...) } -func (p *PausedProvisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, generatedData map[string]interface{}) error { +func (p *PausedProvisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, generatedData map[string]any) error { // Use a select to determine if we get cancelled during the wait ui.Say(fmt.Sprintf("Pausing %s before the next provisioner...", p.PauseBefore)) @@ -217,13 +224,20 @@ type RetriedProvisioner struct { Provisioner packersdk.Provisioner } -func (r *RetriedProvisioner) ConfigSpec() hcldec.ObjectSpec { return r.ConfigSpec() } -func (r *RetriedProvisioner) FlatConfig() interface{} { return r.FlatConfig() } -func (r *RetriedProvisioner) Prepare(raws ...interface{}) error { +func (r *RetriedProvisioner) ConfigSpec() hcldec.ObjectSpec { + return r.Provisioner.ConfigSpec() +} +func (r *RetriedProvisioner) FlatConfig() any { + if fc, ok := r.Provisioner.(interface{ FlatConfig() any }); ok { + return fc.FlatConfig() + } + return nil +} +func (r *RetriedProvisioner) Prepare(raws ...any) error { return r.Provisioner.Prepare(raws...) } -func (r *RetriedProvisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, generatedData map[string]interface{}) error { +func (r *RetriedProvisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, generatedData map[string]any) error { if ctx.Err() != nil { // context was cancelled return ctx.Err() } @@ -261,17 +275,17 @@ type ContinueOnErrorProvisioner struct { func (p *ContinueOnErrorProvisioner) ConfigSpec() hcldec.ObjectSpec { return p.Provisioner.ConfigSpec() } -func (p *ContinueOnErrorProvisioner) FlatConfig() interface{} { - if fc, ok := p.Provisioner.(interface{ FlatConfig() interface{} }); ok { +func (p *ContinueOnErrorProvisioner) FlatConfig() any { + if fc, ok := p.Provisioner.(interface{ FlatConfig() any }); ok { return fc.FlatConfig() } return nil } -func (p *ContinueOnErrorProvisioner) Prepare(raws ...interface{}) error { +func (p *ContinueOnErrorProvisioner) Prepare(raws ...any) error { return p.Provisioner.Prepare(raws...) } -func (p *ContinueOnErrorProvisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, generatedData map[string]interface{}) error { +func (p *ContinueOnErrorProvisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, generatedData map[string]any) error { err := p.Provisioner.Provision(ctx, ui, comm, generatedData) if err == nil { return nil @@ -295,13 +309,20 @@ type DebuggedProvisioner struct { Provisioner packersdk.Provisioner } -func (p *DebuggedProvisioner) ConfigSpec() hcldec.ObjectSpec { return p.ConfigSpec() } -func (p *DebuggedProvisioner) FlatConfig() interface{} { return p.FlatConfig() } -func (p *DebuggedProvisioner) Prepare(raws ...interface{}) error { +func (p *DebuggedProvisioner) ConfigSpec() hcldec.ObjectSpec { + return p.Provisioner.ConfigSpec() +} +func (p *DebuggedProvisioner) FlatConfig() any { + if fc, ok := p.Provisioner.(interface{ FlatConfig() any }); ok { + return fc.FlatConfig() + } + return nil +} +func (p *DebuggedProvisioner) Prepare(raws ...any) error { return p.Provisioner.Prepare(raws...) } -func (p *DebuggedProvisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, generatedData map[string]interface{}) error { +func (p *DebuggedProvisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, generatedData map[string]any) error { // Use a select to determine if we get cancelled during the wait message := "Pausing before the next provisioner . Press enter to continue." @@ -336,21 +357,21 @@ type SBOMInternalProvisioner struct { } func (p *SBOMInternalProvisioner) ConfigSpec() hcldec.ObjectSpec { return p.Provisioner.ConfigSpec() } -func (p *SBOMInternalProvisioner) FlatConfig() interface{} { +func (p *SBOMInternalProvisioner) FlatConfig() any { // Try to delegate to inner provisioner if it implements FlatConfig - if fc, ok := p.Provisioner.(interface{ FlatConfig() interface{} }); ok { + if fc, ok := p.Provisioner.(interface{ FlatConfig() any }); ok { return fc.FlatConfig() } return nil } -func (p *SBOMInternalProvisioner) Prepare(raws ...interface{}) error { +func (p *SBOMInternalProvisioner) Prepare(raws ...any) error { return p.Provisioner.Prepare(raws...) } func (p *SBOMInternalProvisioner) Provision( ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, - generatedData map[string]interface{}, + generatedData map[string]any, ) error { // Original implementation - all logic now in hcp-sbom provisioner cwd, err := os.Getwd() diff --git a/packer/provisioner_test.go b/packer/provisioner_test.go index 46490a22232..6330875bc8b 100644 --- a/packer/provisioner_test.go +++ b/packer/provisioner_test.go @@ -14,8 +14,7 @@ import ( ) func TestProvisionHook_Impl(t *testing.T) { - var raw interface{} - raw = &ProvisionHook{} + var raw any = &ProvisionHook{} if _, ok := raw.(packersdk.Hook); !ok { t.Fatalf("must be a Hook") } @@ -27,7 +26,7 @@ func TestProvisionHook(t *testing.T) { ui := testUi() var comm packersdk.Communicator = new(packersdk.MockCommunicator) - var data interface{} = nil + var data any = nil hook := &ProvisionHook{ Provisioners: []*HookedProvisioner{ @@ -53,7 +52,7 @@ func TestProvisionHook_nilComm(t *testing.T) { ui := testUi() var comm packersdk.Communicator = nil - var data interface{} = nil + var data any = nil hook := &ProvisionHook{ Provisioners: []*HookedProvisioner{ @@ -120,7 +119,9 @@ func TestPausedProvisionerProvision(t *testing.T) { ui := testUi() comm := new(packersdk.MockCommunicator) - prov.Provision(context.Background(), ui, comm, make(map[string]interface{})) + if err := prov.Provision(context.Background(), ui, comm, make(map[string]any)); err != nil { + t.Fatalf("provision failed: %v", err) + } if !mock.ProvCalled { t.Fatal("prov should be called") } @@ -149,7 +150,7 @@ func TestPausedProvisionerProvision_waits(t *testing.T) { }, } - err := prov.Provision(context.Background(), testUi(), new(packersdk.MockCommunicator), make(map[string]interface{})) + err := prov.Provision(context.Background(), testUi(), new(packersdk.MockCommunicator), make(map[string]any)) if err != nil { t.Fatalf("prov failed: %v", err) @@ -170,7 +171,7 @@ func TestPausedProvisionerCancel(t *testing.T) { return ctx.Err() } - err := prov.Provision(topCtx, testUi(), new(packersdk.MockCommunicator), make(map[string]interface{})) + err := prov.Provision(topCtx, testUi(), new(packersdk.MockCommunicator), make(map[string]any)) if err == nil { t.Fatal("should have err") } @@ -204,7 +205,9 @@ func TestDebuggedProvisionerProvision(t *testing.T) { ui := testUi() comm := new(packersdk.MockCommunicator) writeReader(ui, "\n") - prov.Provision(context.Background(), ui, comm, make(map[string]interface{})) + if err := prov.Provision(context.Background(), ui, comm, make(map[string]any)); err != nil { + t.Fatalf("provision failed: %v", err) + } if !mock.ProvCalled { t.Fatal("prov should be called") } @@ -230,7 +233,7 @@ func TestDebuggedProvisionerCancel(t *testing.T) { return ctx.Err() } - err := prov.Provision(topCtx, testUi(), new(packersdk.MockCommunicator), make(map[string]interface{})) + err := prov.Provision(topCtx, testUi(), new(packersdk.MockCommunicator), make(map[string]any)) if err == nil { t.Fatal("should have error") } @@ -272,7 +275,7 @@ func TestRetriedProvisionerProvision(t *testing.T) { ui := testUi() comm := new(packersdk.MockCommunicator) - err := prov.Provision(context.Background(), ui, comm, make(map[string]interface{})) + err := prov.Provision(context.Background(), ui, comm, make(map[string]any)) if err != nil { t.Fatal("should not have errored") } @@ -309,7 +312,7 @@ func TestRetriedProvisionerCancelledProvision(t *testing.T) { ui := testUi() comm := new(packersdk.MockCommunicator) - err := prov.Provision(ctx, ui, comm, make(map[string]interface{})) + err := prov.Provision(ctx, ui, comm, make(map[string]any)) if err == nil { t.Fatal("should have errored") } @@ -341,7 +344,7 @@ func TestRetriedProvisionerCancel(t *testing.T) { return ctx.Err() } - err := prov.Provision(topCtx, testUi(), new(packersdk.MockCommunicator), make(map[string]interface{})) + err := prov.Provision(topCtx, testUi(), new(packersdk.MockCommunicator), make(map[string]any)) if err == nil { t.Fatal("should have err") } @@ -390,7 +393,7 @@ func TestContinueOnErrorProvisionerProvision(t *testing.T) { ui := testUi() comm := new(packersdk.MockCommunicator) - err := prov.Provision(context.Background(), ui, comm, make(map[string]interface{})) + err := prov.Provision(context.Background(), ui, comm, make(map[string]any)) if err != nil { t.Fatalf("should have swallowed the error, got: %s", err) } @@ -407,7 +410,7 @@ func TestContinueOnErrorProvisionerProvision_success(t *testing.T) { Provisioner: mock, } - err := prov.Provision(context.Background(), testUi(), new(packersdk.MockCommunicator), make(map[string]interface{})) + err := prov.Provision(context.Background(), testUi(), new(packersdk.MockCommunicator), make(map[string]any)) if err != nil { t.Fatalf("should not have errored, got: %s", err) } @@ -432,7 +435,7 @@ func TestContinueOnErrorProvisionerCancelledProvision(t *testing.T) { Provisioner: mock, } - err := prov.Provision(ctx, testUi(), new(packersdk.MockCommunicator), make(map[string]interface{})) + err := prov.Provision(ctx, testUi(), new(packersdk.MockCommunicator), make(map[string]any)) if err == nil { t.Fatal("should have propagated the cancellation error") } diff --git a/packer/provisioner_timeout.go b/packer/provisioner_timeout.go index 913a4826256..1190ffec150 100644 --- a/packer/provisioner_timeout.go +++ b/packer/provisioner_timeout.go @@ -18,14 +18,14 @@ type TimeoutProvisioner struct { Timeout time.Duration } -func (p *TimeoutProvisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, generatedData map[string]interface{}) error { +func (p *TimeoutProvisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, generatedData map[string]any) error { ctx, cancel := context.WithTimeout(ctx, p.Timeout) defer cancel() // Use a select to determine if we get cancelled during the wait ui.Say(fmt.Sprintf("Setting a %s timeout for the next provisioner...", p.Timeout)) - errC := make(chan interface{}) + errC := make(chan any) go func() { select { diff --git a/packer/telemetry.go b/packer/telemetry.go index fcd8971df32..df13fd16f9e 100644 --- a/packer/telemetry.go +++ b/packer/telemetry.go @@ -105,7 +105,7 @@ func (c *CheckpointTelemetry) ReportPanic(m string) error { return checkpoint.Report(ctx, panicParams) } -func (c *CheckpointTelemetry) AddSpan(name, pluginType string, options interface{}) *TelemetrySpan { +func (c *CheckpointTelemetry) AddSpan(name, pluginType string, options any) *TelemetrySpan { if c == nil { return nil } @@ -188,12 +188,10 @@ func (s *TelemetrySpan) End(err error) { } } -func flattenConfigKeys(options interface{}) []string { - var flatten func(string, interface{}) []string - - flatten = func(prefix string, options interface{}) (strOpts []string) { +func flattenConfigKeys(options any) []string { + flatten := func(prefix string, options any) (strOpts []string) { switch opt := options.(type) { - case map[string]interface{}: + case map[string]any: return flattenJSON(prefix, options) case cty.Value: return flattenHCL(prefix, opt) @@ -207,13 +205,13 @@ func flattenConfigKeys(options interface{}) []string { return flattened } -func flattenJSON(prefix string, options interface{}) (strOpts []string) { - if m, ok := options.(map[string]interface{}); ok { +func flattenJSON(prefix string, options any) (strOpts []string) { + if m, ok := options.(map[string]any); ok { for k, v := range m { if prefix != "" { k = prefix + "/" + k } - if n, ok := v.(map[string]interface{}); ok { + if n, ok := v.(map[string]any); ok { strOpts = append(strOpts, flattenJSON(k, n)...) } else { strOpts = append(strOpts, k) diff --git a/packer/telemetry_test.go b/packer/telemetry_test.go index c7de03ddf1d..301d8ebe0e6 100644 --- a/packer/telemetry_test.go +++ b/packer/telemetry_test.go @@ -16,13 +16,13 @@ func TestFlattenConfigKeys_nil(t *testing.T) { } func TestFlattenConfigKeys_nested(t *testing.T) { - inp := make(map[string]interface{}) + inp := make(map[string]any) inp["A"] = "" inp["B"] = []string{} - c := make(map[string]interface{}) + c := make(map[string]any) c["X"] = "" - d := make(map[string]interface{}) + d := make(map[string]any) d["a"] = "" c["Y"] = d diff --git a/packer/ui_test.go b/packer/ui_test.go index 089fdd8ad6b..c8c2e9e9fa5 100644 --- a/packer/ui_test.go +++ b/packer/ui_test.go @@ -170,24 +170,21 @@ func TestTargetedUI_ScrubsMultilineSecrets(t *testing.T) { } func TestColoredUi_ImplUi(t *testing.T) { - var raw interface{} - raw = &ColoredUi{} + var raw any = &ColoredUi{} if _, ok := raw.(packersdk.Ui); !ok { t.Fatalf("ColoredUi must implement Ui") } } func TestTargetedUI_ImplUi(t *testing.T) { - var raw interface{} - raw = &TargetedUI{} + var raw any = &TargetedUI{} if _, ok := raw.(packersdk.Ui); !ok { t.Fatalf("TargetedUI must implement Ui") } } func TestBasicUi_ImplUi(t *testing.T) { - var raw interface{} - raw = &packersdk.BasicUi{} + var raw any = &packersdk.BasicUi{} if _, ok := raw.(packersdk.Ui); !ok { t.Fatalf("BasicUi must implement Ui") } @@ -273,8 +270,7 @@ func TestBasicUi_Ask(t *testing.T) { } func TestMachineReadableUi_ImplUi(t *testing.T) { - var raw interface{} - raw = &MachineReadableUi{} + var raw any = &MachineReadableUi{} if _, ok := raw.(packersdk.Ui); !ok { t.Fatalf("MachineReadableUi must implement Ui") } diff --git a/packer_test/common/plugin_tester/builder/dynamic/artifact.go b/packer_test/common/plugin_tester/builder/dynamic/artifact.go index 947352dc409..2a36a3cef61 100644 --- a/packer_test/common/plugin_tester/builder/dynamic/artifact.go +++ b/packer_test/common/plugin_tester/builder/dynamic/artifact.go @@ -7,7 +7,7 @@ package dynamic type Artifact struct { // StateData should store data such as GeneratedData // to be shared with post-processors - StateData map[string]interface{} + StateData map[string]any } func (*Artifact) BuilderId() string { @@ -26,7 +26,7 @@ func (a *Artifact) String() string { return "" } -func (a *Artifact) State(name string) interface{} { +func (a *Artifact) State(name string) any { return a.StateData[name] } diff --git a/packer_test/common/plugin_tester/builder/dynamic/builder.go b/packer_test/common/plugin_tester/builder/dynamic/builder.go index a4d14a101c7..5b7df6a5b94 100644 --- a/packer_test/common/plugin_tester/builder/dynamic/builder.go +++ b/packer_test/common/plugin_tester/builder/dynamic/builder.go @@ -39,7 +39,7 @@ type Builder struct { func (b *Builder) ConfigSpec() hcldec.ObjectSpec { return b.config.FlatMapstructure().HCL2Spec() } -func (b *Builder) Prepare(raws ...interface{}) (generatedVars []string, warnings []string, err error) { +func (b *Builder) Prepare(raws ...any) (generatedVars []string, warnings []string, err error) { err = config.Decode(&b.config, &config.DecodeOpts{ PluginType: "packer.builder.dynamic", Interpolate: true, @@ -70,7 +70,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack // Set the value of the generated data that will become available to provisioners. // To share the data with post-processors, use the StateData in the artifact. - state.Put("generated_data", map[string]interface{}{ + state.Put("generated_data", map[string]any{ "GeneratedMockData": "mock-build-data", }) @@ -86,7 +86,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack artifact := &Artifact{ // Add the builder generated data to the artifact StateData so that post-processors // can access them. - StateData: map[string]interface{}{"generated_data": state.Get("generated_data")}, + StateData: map[string]any{"generated_data": state.Get("generated_data")}, } return artifact, nil } diff --git a/packer_test/common/plugin_tester/datasource/dynamic/data.go b/packer_test/common/plugin_tester/datasource/dynamic/data.go index dae90d7a5fb..bb73c40a0f5 100644 --- a/packer_test/common/plugin_tester/datasource/dynamic/data.go +++ b/packer_test/common/plugin_tester/datasource/dynamic/data.go @@ -38,7 +38,7 @@ func (d *Datasource) ConfigSpec() hcldec.ObjectSpec { return d.config.FlatMapstructure().HCL2Spec() } -func (d *Datasource) Configure(raws ...interface{}) error { +func (d *Datasource) Configure(raws ...any) error { err := config.Decode(&d.config, nil, raws...) if err != nil { return err diff --git a/packer_test/common/plugin_tester/datasource/parrot/data.go b/packer_test/common/plugin_tester/datasource/parrot/data.go index 922e363a7d3..149b5ba2972 100644 --- a/packer_test/common/plugin_tester/datasource/parrot/data.go +++ b/packer_test/common/plugin_tester/datasource/parrot/data.go @@ -27,7 +27,7 @@ func (d *Datasource) ConfigSpec() hcldec.ObjectSpec { return d.config.FlatMapstructure().HCL2Spec() } -func (d *Datasource) Configure(raws ...interface{}) error { +func (d *Datasource) Configure(raws ...any) error { err := config.Decode(&d.config, nil, raws...) if err != nil { return err diff --git a/packer_test/common/plugin_tester/datasource/sleeper/data.go b/packer_test/common/plugin_tester/datasource/sleeper/data.go index 1adc98c5557..dcb98eb8344 100644 --- a/packer_test/common/plugin_tester/datasource/sleeper/data.go +++ b/packer_test/common/plugin_tester/datasource/sleeper/data.go @@ -31,7 +31,7 @@ func (d *Datasource) ConfigSpec() hcldec.ObjectSpec { return d.config.FlatMapstructure().HCL2Spec() } -func (d *Datasource) Configure(raws ...interface{}) error { +func (d *Datasource) Configure(raws ...any) error { err := config.Decode(&d.config, nil, raws...) if err != nil { return err diff --git a/packer_test/common/plugin_tester/post-processor/dynamic/post-processor.go b/packer_test/common/plugin_tester/post-processor/dynamic/post-processor.go index 84e680d2b93..198ea216e41 100644 --- a/packer_test/common/plugin_tester/post-processor/dynamic/post-processor.go +++ b/packer_test/common/plugin_tester/post-processor/dynamic/post-processor.go @@ -35,7 +35,7 @@ type PostProcessor struct { func (p *PostProcessor) ConfigSpec() hcldec.ObjectSpec { return p.config.FlatMapstructure().HCL2Spec() } -func (p *PostProcessor) Configure(raws ...interface{}) error { +func (p *PostProcessor) Configure(raws ...any) error { err := config.Decode(&p.config, &config.DecodeOpts{ PluginType: "packer.post-processor.dynamic", Interpolate: true, diff --git a/packer_test/common/plugin_tester/provisioner/dynamic/provisioner.go b/packer_test/common/plugin_tester/provisioner/dynamic/provisioner.go index b04fd930a40..933bf51504d 100644 --- a/packer_test/common/plugin_tester/provisioner/dynamic/provisioner.go +++ b/packer_test/common/plugin_tester/provisioner/dynamic/provisioner.go @@ -37,7 +37,7 @@ func (p *Provisioner) ConfigSpec() hcldec.ObjectSpec { return p.config.FlatMapstructure().HCL2Spec() } -func (p *Provisioner) Prepare(raws ...interface{}) error { +func (p *Provisioner) Prepare(raws ...any) error { err := config.Decode(&p.config, &config.DecodeOpts{ PluginType: "packer.provisioner.dynamic", Interpolate: true, @@ -52,7 +52,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { return nil } -func (p *Provisioner) Provision(_ context.Context, ui packer.Ui, _ packer.Communicator, generatedData map[string]interface{}) error { +func (p *Provisioner) Provision(_ context.Context, ui packer.Ui, _ packer.Communicator, generatedData map[string]any) error { ui.Say(fmt.Sprintf("Called dynamic provisioner")) for _, nst := range p.config.Nesteds { ui.Say(fmt.Sprintf("Provisioner: nested one %s", nst.Name)) diff --git a/post-processor/artifice/artifact.go b/post-processor/artifice/artifact.go index 49aacc2699b..36d3fc7b4d7 100644 --- a/post-processor/artifice/artifact.go +++ b/post-processor/artifice/artifact.go @@ -50,7 +50,7 @@ func (a *Artifact) String() string { return fmt.Sprintf("Created artifact from files: %s", files) } -func (a *Artifact) State(name string) interface{} { +func (a *Artifact) State(name string) any { return nil } diff --git a/post-processor/artifice/post-processor.go b/post-processor/artifice/post-processor.go index 02666ff5590..2bd8990ca69 100644 --- a/post-processor/artifice/post-processor.go +++ b/post-processor/artifice/post-processor.go @@ -38,7 +38,7 @@ type PostProcessor struct { func (p *PostProcessor) ConfigSpec() hcldec.ObjectSpec { return p.config.FlatMapstructure().HCL2Spec() } -func (p *PostProcessor) Configure(raws ...interface{}) error { +func (p *PostProcessor) Configure(raws ...any) error { err := config.Decode(&p.config, &config.DecodeOpts{ PluginType: "artifice", Interpolate: true, diff --git a/post-processor/checksum/artifact.go b/post-processor/checksum/artifact.go index 09f90bb802e..142d39590e8 100644 --- a/post-processor/checksum/artifact.go +++ b/post-processor/checksum/artifact.go @@ -36,7 +36,7 @@ func (a *Artifact) String() string { return fmt.Sprintf("Created artifact from files: %s", files) } -func (a *Artifact) State(name string) interface{} { +func (a *Artifact) State(name string) any { return nil } diff --git a/post-processor/checksum/post-processor.go b/post-processor/checksum/post-processor.go index 0ebf62bc3e8..611b4622ec4 100644 --- a/post-processor/checksum/post-processor.go +++ b/post-processor/checksum/post-processor.go @@ -57,7 +57,7 @@ func getHash(t string) hash.Hash { func (p *PostProcessor) ConfigSpec() hcldec.ObjectSpec { return p.config.FlatMapstructure().HCL2Spec() } -func (p *PostProcessor) Configure(raws ...interface{}) error { +func (p *PostProcessor) Configure(raws ...any) error { err := config.Decode(&p.config, &config.DecodeOpts{ PluginType: "checksum", Interpolate: true, @@ -102,16 +102,16 @@ func (p *PostProcessor) PostProcess(ctx context.Context, ui packersdk.Ui, artifa files := artifact.Files() var h hash.Hash - var generatedData map[interface{}]interface{} + var generatedData map[any]any stateData := artifact.State("generated_data") if stateData != nil { // Make sure it's not a nil map so we can assign to it later. - generatedData = stateData.(map[interface{}]interface{}) + generatedData = stateData.(map[any]any) } // If stateData has a nil map generatedData will be nil // and we need to make sure it's not if generatedData == nil { - generatedData = make(map[interface{}]interface{}) + generatedData = make(map[any]any) } generatedData["BuildName"] = p.config.PackerBuildName generatedData["BuilderType"] = p.config.PackerBuilderType diff --git a/post-processor/compress/artifact.go b/post-processor/compress/artifact.go index 8f8d2c6507f..1373e289b93 100644 --- a/post-processor/compress/artifact.go +++ b/post-processor/compress/artifact.go @@ -30,7 +30,7 @@ func (a *Artifact) String() string { return fmt.Sprintf("compressed artifacts in: %s", a.Path) } -func (*Artifact) State(name string) interface{} { +func (*Artifact) State(name string) any { return nil } diff --git a/post-processor/compress/artifact_test.go b/post-processor/compress/artifact_test.go index 614e856b7eb..7c68ab174d5 100644 --- a/post-processor/compress/artifact_test.go +++ b/post-processor/compress/artifact_test.go @@ -10,8 +10,7 @@ import ( ) func TestArtifact_ImplementsArtifact(t *testing.T) { - var raw interface{} - raw = &Artifact{} + var raw any = &Artifact{} if _, ok := raw.(packersdk.Artifact); !ok { t.Fatalf("Artifact should be a Artifact!") } diff --git a/post-processor/compress/post-processor.go b/post-processor/compress/post-processor.go index 9f4b5cecdad..fd24b741877 100644 --- a/post-processor/compress/post-processor.go +++ b/post-processor/compress/post-processor.go @@ -61,7 +61,7 @@ type PostProcessor struct { func (p *PostProcessor) ConfigSpec() hcldec.ObjectSpec { return p.config.FlatMapstructure().HCL2Spec() } -func (p *PostProcessor) Configure(raws ...interface{}) error { +func (p *PostProcessor) Configure(raws ...any) error { err := config.Decode(&p.config, &config.DecodeOpts{ PluginType: "compress", Interpolate: true, @@ -114,16 +114,16 @@ func (p *PostProcessor) PostProcess( ui packersdk.Ui, artifact packersdk.Artifact, ) (packersdk.Artifact, bool, bool, error) { - var generatedData map[interface{}]interface{} + var generatedData map[any]any stateData := artifact.State("generated_data") if stateData != nil { // Make sure it's not a nil map so we can assign to it later. - generatedData = stateData.(map[interface{}]interface{}) + generatedData = stateData.(map[any]any) } // If stateData has a nil map generatedData will be nil // and we need to make sure it's not if generatedData == nil { - generatedData = make(map[interface{}]interface{}) + generatedData = make(map[any]any) } // These are extra variables that will be made available for interpolation. diff --git a/post-processor/manifest/artifact.go b/post-processor/manifest/artifact.go index f9b8f85e6de..3d181794d79 100644 --- a/post-processor/manifest/artifact.go +++ b/post-processor/manifest/artifact.go @@ -42,7 +42,7 @@ func (a *Artifact) String() string { return fmt.Sprintf("%s-%s", a.BuildName, a.ArtifactId) } -func (a *Artifact) State(name string) interface{} { +func (a *Artifact) State(name string) any { return nil } diff --git a/post-processor/manifest/post-processor.go b/post-processor/manifest/post-processor.go index b38947fe487..eba9927964d 100644 --- a/post-processor/manifest/post-processor.go +++ b/post-processor/manifest/post-processor.go @@ -51,7 +51,7 @@ type ManifestFile struct { func (p *PostProcessor) ConfigSpec() hcldec.ObjectSpec { return p.config.FlatMapstructure().HCL2Spec() } -func (p *PostProcessor) Configure(raws ...interface{}) error { +func (p *PostProcessor) Configure(raws ...any) error { err := config.Decode(&p.config, &config.DecodeOpts{ PluginType: "packer.post-processor.manifest", Interpolate: true, @@ -79,7 +79,7 @@ func (p *PostProcessor) PostProcess(ctx context.Context, ui packersdk.Ui, source generatedData := source.State("generated_data") if generatedData == nil { // Make sure it's not a nil map so we can assign to it later. - generatedData = make(map[string]interface{}) + generatedData = make(map[string]any) } p.config.ctx.Data = generatedData diff --git a/post-processor/provenance/post-processor.go b/post-processor/provenance/post-processor.go index 071e3739ec2..98b3b284372 100644 --- a/post-processor/provenance/post-processor.go +++ b/post-processor/provenance/post-processor.go @@ -119,7 +119,7 @@ type PostProcessor struct { func (p *PostProcessor) ConfigSpec() hcldec.ObjectSpec { return p.config.FlatMapstructure().HCL2Spec() } -func (p *PostProcessor) Configure(raws ...interface{}) error { +func (p *PostProcessor) Configure(raws ...any) error { err := config.Decode(&p.config, &config.DecodeOpts{ PluginType: "packer.post-processor.provenance", Interpolate: true, @@ -278,7 +278,7 @@ func (p *PostProcessor) writeSBOMAttestation(ctx context.Context, ui packersdk.U return nil } -func (p *PostProcessor) writeAttestation(ctx context.Context, ui packersdk.Ui, statement interface{}, outputPath string) error { +func (p *PostProcessor) writeAttestation(ctx context.Context, ui packersdk.Ui, statement any, outputPath string) error { if p.config.SigningMode == internalattestation.SigningModeNone { payload, err := json.MarshalIndent(statement, "", " ") if err != nil { @@ -495,11 +495,11 @@ func (p *PostProcessor) resolveSBOMScanPath(source packersdk.Artifact) (string, return "", fmt.Errorf("sbom=true requires local artifact files or sbom_scan_path") } -func buildSBOMPredicate(rawSBOM []byte, format internalsbom.Format) (interface{}, string, error) { +func buildSBOMPredicate(rawSBOM []byte, format internalsbom.Format) (any, string, error) { decoder := json.NewDecoder(bytes.NewReader(rawSBOM)) decoder.UseNumber() - var predicate interface{} + var predicate any if err := decoder.Decode(&predicate); err != nil { return nil, "", fmt.Errorf("decode SBOM payload: %w", err) } @@ -514,8 +514,8 @@ func buildSBOMPredicate(rawSBOM []byte, format internalsbom.Format) (interface{} } } -func (p *PostProcessor) externalParameters(env map[string]string) map[string]interface{} { - externalParameters := map[string]interface{}{} +func (p *PostProcessor) externalParameters(env map[string]string) map[string]any { + externalParameters := map[string]any{} if p.config.TemplatePath != "" { externalParameters["template"] = p.config.TemplatePath @@ -540,8 +540,8 @@ func (p *PostProcessor) externalParameters(env map[string]string) map[string]int return externalParameters } -func (p *PostProcessor) internalParameters() map[string]interface{} { - return map[string]interface{}{ +func (p *PostProcessor) internalParameters() map[string]any { + return map[string]any{ "packerBuildName": p.config.PackerBuildName, "packerBuilderType": p.config.PackerBuilderType, } diff --git a/post-processor/provenance/post-processor_test.go b/post-processor/provenance/post-processor_test.go index d3c0412ca39..54dc9e05a3f 100644 --- a/post-processor/provenance/post-processor_test.go +++ b/post-processor/provenance/post-processor_test.go @@ -31,7 +31,7 @@ func TestPostProcessorWritesUnsignedStatementAndPreservesArtifact(t *testing.T) defer func() { _ = artifact.Destroy() }() outputDir := t.TempDir() - config := mustTemplateJSON(t, map[string]interface{}{ + config := mustTemplateJSON(t, map[string]any{ "post-processors": []map[string]string{{ "type": "provenance", "output_dir": outputDir, @@ -100,7 +100,7 @@ func TestPostProcessorChainsWithoutModifyingArtifact(t *testing.T) { } outputDir := t.TempDir() - config := mustTemplateJSON(t, map[string]interface{}{ + config := mustTemplateJSON(t, map[string]any{ "post-processors": []map[string]string{{ "type": "provenance", "output_dir": outputDir, @@ -156,8 +156,8 @@ func TestPostProcessorEnrichesPredicateFromConfigAndCIEnv(t *testing.T) { defer func() { _ = artifact.Destroy() }() outputDir := t.TempDir() - config := mustTemplateJSON(t, map[string]interface{}{ - "post-processors": []map[string]interface{}{{ + config := mustTemplateJSON(t, map[string]any{ + "post-processors": []map[string]any{{ "type": "provenance", "output_dir": outputDir, "template": "ubuntu.pkr.hcl", @@ -236,7 +236,7 @@ func TestPostProcessorEnrichesPredicateFromConfigAndCIEnv(t *testing.T) { t.Fatalf("unexpected source digest %q, want %q", got, want) } - userVariables, ok := externalParameters["userVariables"].(map[string]interface{}) + userVariables, ok := externalParameters["userVariables"].(map[string]any) if !ok { t.Fatalf("expected userVariables map, got %T", externalParameters["userVariables"]) } @@ -247,7 +247,7 @@ func TestPostProcessorEnrichesPredicateFromConfigAndCIEnv(t *testing.T) { t.Fatalf("unexpected config user variable %v, want %q", got, want) } - onlyBuilds, ok := externalParameters["onlyBuilds"].([]interface{}) + onlyBuilds, ok := externalParameters["onlyBuilds"].([]any) if !ok || len(onlyBuilds) != 1 || onlyBuilds[0] != "qemu.ubuntu" { t.Fatalf("unexpected onlyBuilds value %#v", externalParameters["onlyBuilds"]) } @@ -282,8 +282,8 @@ func TestPostProcessorWritesSBOMAttestation(t *testing.T) { defer func() { _ = artifact.Destroy() }() outputDir := t.TempDir() - config := mustTemplateJSON(t, map[string]interface{}{ - "post-processors": []map[string]interface{}{{ + config := mustTemplateJSON(t, map[string]any{ + "post-processors": []map[string]any{{ "type": "provenance", "output_dir": outputDir, "sbom": true, @@ -335,8 +335,8 @@ func TestPostProcessorRegeneratesStaleSBOM(t *testing.T) { t.Fatalf("write stale sbom: %v", err) } - config := mustTemplateJSON(t, map[string]interface{}{ - "post-processors": []map[string]interface{}{{ + config := mustTemplateJSON(t, map[string]any{ + "post-processors": []map[string]any{{ "type": "provenance", "output_dir": outputDir, "sbom": true, @@ -390,8 +390,8 @@ func TestPostProcessorSignsAttestationsWithConfiguredVerifier(t *testing.T) { privateKeyPath, publicKeyPath := writeSigningKeypair(t) outputDir := t.TempDir() - config := mustTemplateJSON(t, map[string]interface{}{ - "post-processors": []map[string]interface{}{{ + config := mustTemplateJSON(t, map[string]any{ + "post-processors": []map[string]any{{ "type": "provenance", "output_dir": outputDir, "signing_mode": "key", @@ -432,8 +432,8 @@ func TestPostProcessorRejectsMismatchedVerifier(t *testing.T) { privateKeyPath, _ := writeSigningKeypair(t) _, mismatchedVerifierPath := writeSigningKeypair(t) outputDir := t.TempDir() - config := mustTemplateJSON(t, map[string]interface{}{ - "post-processors": []map[string]interface{}{{ + config := mustTemplateJSON(t, map[string]any{ + "post-processors": []map[string]any{{ "type": "provenance", "output_dir": outputDir, "signing_mode": "key", @@ -462,8 +462,8 @@ func TestPostProcessorWritesSigstoreBundleForKeylessAttestations(t *testing.T) { defer func() { _ = artifact.Destroy() }() outputDir := t.TempDir() - config := mustTemplateJSON(t, map[string]interface{}{ - "post-processors": []map[string]interface{}{{ + config := mustTemplateJSON(t, map[string]any{ + "post-processors": []map[string]any{{ "type": "provenance", "output_dir": outputDir, "signing_mode": "keyless", @@ -799,7 +799,7 @@ func buildFileArtifact(t *testing.T) packersdk.Artifact { t.Helper() target := filepath.Join(t.TempDir(), "package.txt") - config := mustTemplateJSON(t, map[string]interface{}{ + config := mustTemplateJSON(t, map[string]any{ "builders": []map[string]string{{ "type": "file", "target": target, @@ -828,7 +828,7 @@ func buildFileArtifact(t *testing.T) packersdk.Artifact { return artifact } -func mustTemplateJSON(t *testing.T, value interface{}) string { +func mustTemplateJSON(t *testing.T, value any) string { t.Helper() encoded, err := json.Marshal(value) diff --git a/post-processor/shell-local/post-processor.go b/post-processor/shell-local/post-processor.go index 3653c15c3a7..df46b19c616 100644 --- a/post-processor/shell-local/post-processor.go +++ b/post-processor/shell-local/post-processor.go @@ -22,7 +22,7 @@ type ExecuteCommandTemplate struct { func (p *PostProcessor) ConfigSpec() hcldec.ObjectSpec { return p.config.FlatMapstructure().HCL2Spec() } -func (p *PostProcessor) Configure(raws ...interface{}) error { +func (p *PostProcessor) Configure(raws ...any) error { err := sl.Decode(&p.config, raws...) if err != nil { return err @@ -44,10 +44,10 @@ func (p *PostProcessor) Configure(raws ...interface{}) error { } func (p *PostProcessor) PostProcess(ctx context.Context, ui packersdk.Ui, artifact packersdk.Artifact) (packersdk.Artifact, bool, bool, error) { - generatedData := make(map[string]interface{}) + generatedData := make(map[string]any) artifactStateData := artifact.State("generated_data") if artifactStateData != nil { - for k, v := range artifactStateData.(map[interface{}]interface{}) { + for k, v := range artifactStateData.(map[any]any) { generatedData[k.(string)] = v } } diff --git a/post-processor/shell-local/post-processor_test.go b/post-processor/shell-local/post-processor_test.go index d1f0e9840cd..4385a4c12a2 100644 --- a/post-processor/shell-local/post-processor_test.go +++ b/post-processor/shell-local/post-processor_test.go @@ -16,15 +16,14 @@ func TestPostProcessor_ImplementsPostProcessor(t *testing.T) { var _ packersdk.PostProcessor = new(PostProcessor) } -func testConfig() map[string]interface{} { - return map[string]interface{}{ - "inline": []interface{}{"foo", "bar"}, +func testConfig() map[string]any { + return map[string]any{ + "inline": []any{"foo", "bar"}, } } func TestPostProcessor_Impl(t *testing.T) { - var raw interface{} - raw = &PostProcessor{} + var raw any = &PostProcessor{} if _, ok := raw.(packersdk.PostProcessor); !ok { t.Fatalf("must be a post processor") } @@ -168,7 +167,7 @@ func TestPostProcessorPrepare_ScriptAndInline(t *testing.T) { } defer os.Remove(tf.Name()) - raws["inline"] = []interface{}{"foo"} + raws["inline"] = []any{"foo"} raws["script"] = tf.Name() err = p.Configure(raws) if err == nil { @@ -187,7 +186,7 @@ func TestPostProcessorPrepare_ScriptAndScripts(t *testing.T) { } defer os.Remove(tf.Name()) - raws["inline"] = []interface{}{"foo"} + raws["inline"] = []any{"foo"} raws["scripts"] = []string{tf.Name()} err = p.Configure(raws) if err == nil { diff --git a/provisioner/breakpoint/provisioner.go b/provisioner/breakpoint/provisioner.go index 208e193c2a5..c1bdb222e9a 100644 --- a/provisioner/breakpoint/provisioner.go +++ b/provisioner/breakpoint/provisioner.go @@ -33,7 +33,7 @@ type Provisioner struct { func (p *Provisioner) ConfigSpec() hcldec.ObjectSpec { return p.config.FlatMapstructure().HCL2Spec() } -func (p *Provisioner) Prepare(raws ...interface{}) error { +func (p *Provisioner) Prepare(raws ...any) error { err := config.Decode(&p.config, &config.DecodeOpts{ PluginType: "breakpoint", Interpolate: true, @@ -49,7 +49,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { return nil } -func (p *Provisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, _ map[string]interface{}) error { +func (p *Provisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, _ map[string]any) error { if p.config.Disable { if p.config.Note != "" { ui.Say(fmt.Sprintf( diff --git a/provisioner/file/provisioner.go b/provisioner/file/provisioner.go index 8b9b1d76124..6b1a65a9f2b 100644 --- a/provisioner/file/provisioner.go +++ b/provisioner/file/provisioner.go @@ -77,7 +77,7 @@ type Provisioner struct { func (p *Provisioner) ConfigSpec() hcldec.ObjectSpec { return p.config.FlatMapstructure().HCL2Spec() } -func (p *Provisioner) Prepare(raws ...interface{}) error { +func (p *Provisioner) Prepare(raws ...any) error { err := config.Decode(&p.config, &config.DecodeOpts{ PluginType: "file", Interpolate: true, @@ -130,9 +130,9 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { return nil } -func (p *Provisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, generatedData map[string]interface{}) error { +func (p *Provisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, generatedData map[string]any) error { if generatedData == nil { - generatedData = make(map[string]interface{}) + generatedData = make(map[string]any) } p.config.ctx.Data = generatedData diff --git a/provisioner/file/provisioner_test.go b/provisioner/file/provisioner_test.go index 6e522172d33..a42d19004f3 100644 --- a/provisioner/file/provisioner_test.go +++ b/provisioner/file/provisioner_test.go @@ -15,15 +15,14 @@ import ( packersdk "github.com/hashicorp/packer-plugin-sdk/packer" ) -func testConfig() map[string]interface{} { - return map[string]interface{}{ +func testConfig() map[string]any { + return map[string]any{ "destination": "something", } } func TestProvisioner_Impl(t *testing.T) { - var raw interface{} - raw = &Provisioner{} + var raw any = &Provisioner{} if _, ok := raw.(packersdk.Provisioner); !ok { t.Fatalf("must be a provisioner") } @@ -116,7 +115,7 @@ func TestProvisionerProvision_SendsFile(t *testing.T) { t.Fatalf("error writing tempfile: %s", err) } - config := map[string]interface{}{ + config := map[string]any{ "source": tf.Name(), "destination": "something", } @@ -131,7 +130,7 @@ func TestProvisionerProvision_SendsFile(t *testing.T) { PB: &packersdk.NoopProgressTracker{}, } comm := &packersdk.MockCommunicator{} - err = p.Provision(context.Background(), ui, comm, make(map[string]interface{})) + err = p.Provision(context.Background(), ui, comm, make(map[string]any)) if err != nil { t.Fatalf("should successfully provision: %s", err) } @@ -158,7 +157,7 @@ func TestProvisionerProvision_SendsContent(t *testing.T) { dst := "something.txt" content := "hello" - config := map[string]interface{}{ + config := map[string]any{ "content": content, "destination": dst, } @@ -173,7 +172,7 @@ func TestProvisionerProvision_SendsContent(t *testing.T) { PB: &packersdk.NoopProgressTracker{}, } comm := &packersdk.MockCommunicator{} - err := p.Provision(context.Background(), ui, comm, make(map[string]interface{})) + err := p.Provision(context.Background(), ui, comm, make(map[string]any)) if err != nil { t.Fatalf("should successfully provision: %s", err) } @@ -214,7 +213,7 @@ func TestProvisionerProvision_SendsFileMultipleFiles(t *testing.T) { t.Fatalf("error writing tempfile: %s", err) } - config := map[string]interface{}{ + config := map[string]any{ "sources": []string{tf1.Name(), tf2.Name()}, "destination": "something", } @@ -229,7 +228,7 @@ func TestProvisionerProvision_SendsFileMultipleFiles(t *testing.T) { PB: &packersdk.NoopProgressTracker{}, } comm := &packersdk.MockCommunicator{} - err = p.Provision(context.Background(), ui, comm, make(map[string]interface{})) + err = p.Provision(context.Background(), ui, comm, make(map[string]any)) if err != nil { t.Fatalf("should successfully provision: %s", err) } @@ -284,7 +283,7 @@ func TestProvisionerProvision_SendsFileMultipleDirs(t *testing.T) { // Run Provision - config := map[string]interface{}{ + config := map[string]any{ "sources": []string{td1, td2}, "destination": "something", } @@ -299,7 +298,7 @@ func TestProvisionerProvision_SendsFileMultipleDirs(t *testing.T) { PB: &packersdk.NoopProgressTracker{}, } comm := &packersdk.MockCommunicator{} - err = p.Provision(context.Background(), ui, comm, make(map[string]interface{})) + err = p.Provision(context.Background(), ui, comm, make(map[string]any)) if err != nil { t.Fatalf("should successfully provision: %s", err) } @@ -336,7 +335,7 @@ func TestProvisionerProvision_DownloadsMultipleFilesToFolder(t *testing.T) { t.Fatalf("error writing tempfile: %s", err) } - config := map[string]interface{}{ + config := map[string]any{ "sources": []string{tf1.Name(), tf2.Name()}, "destination": "something/", "direction": "download", @@ -360,7 +359,7 @@ func TestProvisionerProvision_DownloadsMultipleFilesToFolder(t *testing.T) { PB: &packersdk.NoopProgressTracker{}, } comm := &packersdk.MockCommunicator{} - err = p.Provision(context.Background(), ui, comm, make(map[string]interface{})) + err = p.Provision(context.Background(), ui, comm, make(map[string]any)) if err != nil { t.Fatalf("should successfully provision: %s", err) } @@ -407,7 +406,7 @@ func TestProvisionerProvision_SendsFileMultipleFilesToFolder(t *testing.T) { t.Fatalf("error writing tempfile: %s", err) } - config := map[string]interface{}{ + config := map[string]any{ "sources": []string{tf1.Name(), tf2.Name()}, "destination": "something/", } @@ -422,7 +421,7 @@ func TestProvisionerProvision_SendsFileMultipleFilesToFolder(t *testing.T) { PB: &packersdk.NoopProgressTracker{}, } comm := &packersdk.MockCommunicator{} - err = p.Provision(context.Background(), ui, comm, make(map[string]interface{})) + err = p.Provision(context.Background(), ui, comm, make(map[string]any)) if err != nil { t.Fatalf("should successfully provision: %s", err) } @@ -464,7 +463,7 @@ func TestProvisionDownloadMkdirAll(t *testing.T) { } defer os.Remove(tf.Name()) - config := map[string]interface{}{ + config := map[string]any{ "source": tf.Name(), } var p Provisioner diff --git a/provisioner/hcp-sbom/provisioner.go b/provisioner/hcp-sbom/provisioner.go index f53fa4f870e..4a249a65d2a 100644 --- a/provisioner/hcp-sbom/provisioner.go +++ b/provisioner/hcp-sbom/provisioner.go @@ -117,7 +117,7 @@ type Config struct { type Provisioner struct { config Config communicator packersdk.Communicator - generatedData map[string]interface{} + generatedData map[string]any } func formatUIWarning(message string) string { @@ -140,7 +140,7 @@ func (p *Provisioner) ConfigSpec() hcldec.ObjectSpec { return p.config.FlatMapstructure().HCL2Spec() } -func (p *Provisioner) FlatConfig() interface{} { +func (p *Provisioner) FlatConfig() any { return p.config.FlatMapstructure() } @@ -178,7 +178,7 @@ var scannerPathTokenRegexp = regexp.MustCompile(`\{\{\s*\.Path\s*\}\}`) // && chmod +x {{.Path}} var scannerArgsOrScanPathTokenPrefixRegexp = regexp.MustCompile(`^\{\{\s*\.(Args|ScanPath)\s*\}\}`) -func (p *Provisioner) Prepare(raws ...interface{}) error { +func (p *Provisioner) Prepare(raws ...any) error { err := config.Decode(&p.config, &config.DecodeOpts{ PluginType: "hcp-sbom", Interpolate: true, @@ -280,7 +280,7 @@ type PackerSBOM struct { func (p *Provisioner) Provision( ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, - generatedData map[string]interface{}, + generatedData map[string]any, ) error { // Store communicator and generatedData for elevated execution p.communicator = comm @@ -288,7 +288,7 @@ func (p *Provisioner) Provision( log.Println("Starting to provision with `hcp-sbom` provisioner") if generatedData == nil { - generatedData = make(map[string]interface{}) + generatedData = make(map[string]any) } p.config.ctx.Data = generatedData @@ -323,7 +323,7 @@ func (p *Provisioner) Provision( // provisionWithExistingSBOM handles the original flow where user provides an SBOM file func (p *Provisioner) provisionWithExistingSBOM( ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, - generatedData map[string]interface{}, + generatedData map[string]any, ) error { src := p.config.Source @@ -348,7 +348,7 @@ func (p *Provisioner) provisionWithExistingSBOM( // detectRemoteOS performs OS detection on the remote host func (p *Provisioner) detectRemoteOS(ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, - generatedData map[string]interface{}) (string, string, error) { + generatedData map[string]any) (string, string, error) { // First check if already detected (from generatedData) if osType, ok := generatedData["OSType"].(string); ok { if osArch, ok := generatedData["OSArch"].(string); ok { @@ -612,7 +612,7 @@ func (p *Provisioner) runRemoteCmd(ctx context.Context, comm packersdk.Communica // to the remote host via the communicator before running `packer sbom-generate`. func (p *Provisioner) provisionWithNativeGeneration( ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, - generatedData map[string]interface{}, osType, osArch string, + generatedData map[string]any, osType, osArch string, ) error { ui.Say("Starting Automatic SBOM generation workflow...") @@ -874,7 +874,7 @@ func (p *Provisioner) cleanupRemoteFile(ctx context.Context, ui packersdk.Ui, } // processSBOMForHCP validates, compresses, and prepares SBOM for HCP upload -func (p *Provisioner) processSBOMForHCP(generatedData map[string]interface{}, sbomData []byte) error { +func (p *Provisioner) processSBOMForHCP(generatedData map[string]any, sbomData []byte) error { // Validate SBOM format format, err := validateSBOM(sbomData) if err != nil { diff --git a/provisioner/hcp-sbom/provisioner_test.go b/provisioner/hcp-sbom/provisioner_test.go index d5e9e477dec..ffeb92e05c5 100644 --- a/provisioner/hcp-sbom/provisioner_test.go +++ b/provisioner/hcp-sbom/provisioner_test.go @@ -15,7 +15,7 @@ import ( func TestConfigPrepare(t *testing.T) { tests := []struct { name string - inputConfig map[string]interface{} + inputConfig map[string]any interpolateContext interpolate.Context expectConfig *Config expectError bool @@ -23,7 +23,7 @@ func TestConfigPrepare(t *testing.T) { }{ { "empty config, should error without a source", - map[string]interface{}{}, + map[string]any{}, interpolate.Context{}, nil, true, @@ -31,7 +31,7 @@ func TestConfigPrepare(t *testing.T) { }, { "config with full context for interpolation: success", - map[string]interface{}{ + map[string]any{ "source": "{{ .Name }}", }, interpolate.Context{ @@ -53,7 +53,7 @@ func TestConfigPrepare(t *testing.T) { // Refer to the comment in `Prepare` for context as to WHY // this cannot be considered an error. "config with sbom name as interpolated value, without it in context, replace with a placeholder", - map[string]interface{}{ + map[string]any{ "source": "test", "sbom_name": "{{ .Name }}", }, @@ -67,7 +67,7 @@ func TestConfigPrepare(t *testing.T) { }, { "auto_generate enabled with defaults", - map[string]interface{}{ + map[string]any{ "auto_generate": true, }, interpolate.Context{}, @@ -82,7 +82,7 @@ func TestConfigPrepare(t *testing.T) { }, { "auto_generate with custom scan path", - map[string]interface{}{ + map[string]any{ "auto_generate": true, "scan_path": "/opt/app", }, @@ -98,7 +98,7 @@ func TestConfigPrepare(t *testing.T) { }, { "auto_generate with custom execute_command", - map[string]interface{}{ + map[string]any{ "auto_generate": true, "execute_command": "{{.Path}} {{.Args}} {{.ScanPath}} > {{.Output}}", }, @@ -114,7 +114,7 @@ func TestConfigPrepare(t *testing.T) { }, { "auto_generate with deprecated scanner_url (should warn but not fail)", - map[string]interface{}{ + map[string]any{ "auto_generate": true, "scanner_url": "https://example.com/scanner", "scan_path": "/opt/app", @@ -132,7 +132,7 @@ func TestConfigPrepare(t *testing.T) { }, { "deprecated scanner_checksum with scanner_url (should warn but not fail)", - map[string]interface{}{ + map[string]any{ "auto_generate": true, "scanner_url": "https://example.com/scanner", "scanner_checksum": "abc123def456", @@ -151,7 +151,7 @@ func TestConfigPrepare(t *testing.T) { }, { "deprecated scanner_checksum without scanner_url - should still error for clarity", - map[string]interface{}{ + map[string]any{ "auto_generate": true, "scanner_checksum": "abc123", }, @@ -162,7 +162,7 @@ func TestConfigPrepare(t *testing.T) { }, { "auto_generate with elevated user and password", - map[string]interface{}{ + map[string]any{ "auto_generate": true, "elevated_user": "admin", "elevated_password": "password123", @@ -181,7 +181,7 @@ func TestConfigPrepare(t *testing.T) { }, { "source and auto_generate both set - should error", - map[string]interface{}{ + map[string]any{ "source": "sbom.json", "auto_generate": true, }, @@ -192,7 +192,7 @@ func TestConfigPrepare(t *testing.T) { }, { "elevated_password without elevated_user - should error", - map[string]interface{}{ + map[string]any{ "auto_generate": true, "elevated_password": "password123", }, @@ -203,7 +203,7 @@ func TestConfigPrepare(t *testing.T) { }, { "source mode with scanner fields - should succeed (allows toggling auto_generate)", - map[string]interface{}{ + map[string]any{ "source": "sbom.json", "scanner_args": []string{"-o", "json"}, "scan_path": "/opt/app", diff --git a/provisioner/powershell/execution_policy.go b/provisioner/powershell/execution_policy.go index 79e00804715..f6d646d125b 100644 --- a/provisioner/powershell/execution_policy.go +++ b/provisioner/powershell/execution_policy.go @@ -25,7 +25,7 @@ const ( ExecutionPolicyNone // not set ) -func StringToExecutionPolicyHook(f reflect.Kind, t reflect.Kind, data interface{}) (interface{}, error) { +func StringToExecutionPolicyHook(f reflect.Kind, t reflect.Kind, data any) (any, error) { if f != reflect.String || t != reflect.Int { return data, nil } diff --git a/provisioner/powershell/execution_policy_test.go b/provisioner/powershell/execution_policy_test.go index 7bed341a710..7b04b8f4fd8 100644 --- a/provisioner/powershell/execution_policy_test.go +++ b/provisioner/powershell/execution_policy_test.go @@ -8,8 +8,8 @@ import ( ) func TestExecutionPolicy_Decode(t *testing.T) { - config := map[string]interface{}{ - "inline": []interface{}{"foo", "bar"}, + config := map[string]any{ + "inline": []any{"foo", "bar"}, "execution_policy": "allsigned", } p := new(Provisioner) diff --git a/provisioner/powershell/provisioner.go b/provisioner/powershell/provisioner.go index 3724d2d44e8..d5fe36720b4 100644 --- a/provisioner/powershell/provisioner.go +++ b/provisioner/powershell/provisioner.go @@ -125,7 +125,7 @@ type Config struct { type Provisioner struct { config Config communicator packersdk.Communicator - generatedData map[string]interface{} + generatedData map[string]any } func (p *Provisioner) defaultExecuteCommand() string { @@ -166,7 +166,7 @@ func (p *Provisioner) defaultScriptCommand() string { func (p *Provisioner) ConfigSpec() hcldec.ObjectSpec { return p.config.FlatMapstructure().HCL2Spec() } -func (p *Provisioner) Prepare(raws ...interface{}) error { +func (p *Provisioner) Prepare(raws ...any) error { err := config.Decode(&p.config, &config.DecodeOpts{ PluginType: "powershell", Interpolate: true, @@ -338,7 +338,7 @@ func extractInlineScript(p *Provisioner) (string, error) { return temp.Name(), nil } -func (p *Provisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, generatedData map[string]interface{}) error { +func (p *Provisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, generatedData map[string]any) error { ui.Say("Provisioning with Powershell...") p.communicator = comm p.generatedData = generatedData diff --git a/provisioner/powershell/provisioner_test.go b/provisioner/powershell/provisioner_test.go index 028500756b9..9969a27b8e7 100644 --- a/provisioner/powershell/provisioner_test.go +++ b/provisioner/powershell/provisioner_test.go @@ -49,8 +49,7 @@ func TestProvisionerPrepare_extractScript(t *testing.T) { } func TestProvisioner_Impl(t *testing.T) { - var raw interface{} - raw = &Provisioner{} + var raw any = &Provisioner{} if _, ok := raw.(packersdk.Provisioner); !ok { t.Fatalf("must be a Provisioner") } @@ -223,7 +222,7 @@ func TestProvisionerPrepare_ScriptAndInline(t *testing.T) { defer os.Remove(tf.Name()) defer tf.Close() - config["inline"] = []interface{}{"foo"} + config["inline"] = []any{"foo"} config["script"] = tf.Name() err = p.Prepare(config) if err == nil { @@ -243,7 +242,7 @@ func TestProvisionerPrepare_ScriptAndScripts(t *testing.T) { defer os.Remove(tf.Name()) defer tf.Close() - config["inline"] = []interface{}{"foo"} + config["inline"] = []any{"foo"} config["scripts"] = []string{tf.Name()} err = p.Prepare(config) if err == nil { @@ -588,7 +587,7 @@ func TestProvisionerProvision_SkipClean(t *testing.T) { os.Remove(tempFile.Name()) }() - config := map[string]interface{}{ + config := map[string]any{ "scripts": []string{tempFile.Name()}, "remote_path": "c:/Windows/Temp/script.ps1", } @@ -726,7 +725,7 @@ func TestProvisioner_createFlattenedElevatedEnvVars_windows(t *testing.T) { func TestProvisionerCorrectlyInterpolatesValidExitCodes(t *testing.T) { type testCases struct { - Input interface{} + Input any Expected []int } validExitCodeTests := []testCases{ @@ -753,7 +752,7 @@ func TestProvisionerCorrectlyInterpolatesValidExitCodes(t *testing.T) { func TestProvisionerCorrectlyInterpolatesExecutionPolicy(t *testing.T) { type testCases struct { - Input interface{} + Input any Expected ExecutionPolicy ErrExpected bool } @@ -918,7 +917,7 @@ func TestProvision_createCommandText(t *testing.T) { p.config.PackerBuilderType = "iso" // Non-elevated - p.generatedData = make(map[string]interface{}) + p.generatedData = make(map[string]any) cmd, _ := p.createCommandText() re := regexp.MustCompile(`powershell -executionpolicy bypass -file c:/Windows/Temp/script.ps1`) @@ -949,7 +948,7 @@ func TestProvision_createCommandTextNoneExecutionPolicy(t *testing.T) { _ = p.Prepare(config) // Non-elevated - p.generatedData = make(map[string]interface{}) + p.generatedData = make(map[string]any) cmd, _ := p.createCommandText() re := regexp.MustCompile(`-file c:/Windows/Temp/script.ps1`) @@ -982,21 +981,21 @@ func TestCancel(t *testing.T) { // which kills the 'go test' tool } -func testConfig() map[string]interface{} { - return map[string]interface{}{ - "inline": []interface{}{"foo", "bar"}, +func testConfig() map[string]any { + return map[string]any{ + "inline": []any{"foo", "bar"}, } } -func testConfigWithSkipClean() map[string]interface{} { - return map[string]interface{}{ - "inline": []interface{}{"foo", "bar"}, +func testConfigWithSkipClean() map[string]any { + return map[string]any{ + "inline": []any{"foo", "bar"}, "skip_clean": true, } } -func generatedData() map[string]interface{} { - return map[string]interface{}{ +func generatedData() map[string]any { + return map[string]any{ "PackerHTTPAddr": commonsteps.HttpAddrNotImplemented, "PackerHTTPIP": commonsteps.HttpIPNotImplemented, "PackerHTTPPort": commonsteps.HttpPortNotImplemented, diff --git a/provisioner/shell-local/provisioner.go b/provisioner/shell-local/provisioner.go index 0f1f2e05ebf..1adeab01ebb 100644 --- a/provisioner/shell-local/provisioner.go +++ b/provisioner/shell-local/provisioner.go @@ -17,7 +17,7 @@ type Provisioner struct { func (p *Provisioner) ConfigSpec() hcldec.ObjectSpec { return p.config.FlatMapstructure().HCL2Spec() } -func (p *Provisioner) Prepare(raws ...interface{}) error { +func (p *Provisioner) Prepare(raws ...any) error { err := sl.Decode(&p.config, raws...) if err != nil { return err @@ -31,7 +31,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { return nil } -func (p *Provisioner) Provision(ctx context.Context, ui packersdk.Ui, _ packersdk.Communicator, generatedData map[string]interface{}) error { +func (p *Provisioner) Provision(ctx context.Context, ui packersdk.Ui, _ packersdk.Communicator, generatedData map[string]any) error { _, retErr := sl.Run(ctx, ui, &p.config, generatedData) return retErr diff --git a/provisioner/shell-local/provisioner_test.go b/provisioner/shell-local/provisioner_test.go index 95dd120fb9d..ee69771f650 100644 --- a/provisioner/shell-local/provisioner_test.go +++ b/provisioner/shell-local/provisioner_test.go @@ -16,7 +16,7 @@ func TestProvisioner_impl(t *testing.T) { func TestConfigPrepare(t *testing.T) { cases := []struct { Key string - Value interface{} + Value any Err bool }{ { @@ -51,8 +51,8 @@ func TestConfigPrepare(t *testing.T) { } } -func testConfig(t *testing.T) map[string]interface{} { - return map[string]interface{}{ +func testConfig(t *testing.T) map[string]any { + return map[string]any{ "command": "echo foo", } } diff --git a/provisioner/shell/provisioner.go b/provisioner/shell/provisioner.go index 44e2505134e..ea5097ec55c 100644 --- a/provisioner/shell/provisioner.go +++ b/provisioner/shell/provisioner.go @@ -76,12 +76,12 @@ type Config struct { type Provisioner struct { config Config - generatedData map[string]interface{} + generatedData map[string]any } func (p *Provisioner) ConfigSpec() hcldec.ObjectSpec { return p.config.FlatMapstructure().HCL2Spec() } -func (p *Provisioner) Prepare(raws ...interface{}) error { +func (p *Provisioner) Prepare(raws ...any) error { err := config.Decode(&p.config, &config.DecodeOpts{ PluginType: "shell", Interpolate: true, @@ -187,9 +187,9 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { return nil } -func (p *Provisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, generatedData map[string]interface{}) error { +func (p *Provisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, generatedData map[string]any) error { if generatedData == nil { - generatedData = make(map[string]interface{}) + generatedData = make(map[string]any) } p.generatedData = generatedData diff --git a/provisioner/shell/provisioner_test.go b/provisioner/shell/provisioner_test.go index 0fd33fcc1d7..3f8aedba526 100644 --- a/provisioner/shell/provisioner_test.go +++ b/provisioner/shell/provisioner_test.go @@ -13,15 +13,14 @@ import ( packersdk "github.com/hashicorp/packer-plugin-sdk/packer" ) -func testConfig() map[string]interface{} { - return map[string]interface{}{ - "inline": []interface{}{"foo", "bar"}, +func testConfig() map[string]any { + return map[string]any{ + "inline": []any{"foo", "bar"}, } } func TestProvisioner_Impl(t *testing.T) { - var raw interface{} - raw = &Provisioner{} + var raw any = &Provisioner{} if _, ok := raw.(packersdk.Provisioner); !ok { t.Fatalf("must be a Provisioner") } @@ -154,7 +153,7 @@ func TestProvisionerPrepare_ScriptAndInline(t *testing.T) { } defer os.Remove(tf.Name()) - config["inline"] = []interface{}{"foo"} + config["inline"] = []any{"foo"} config["script"] = tf.Name() err = p.Prepare(config) if err == nil { @@ -173,7 +172,7 @@ func TestProvisionerPrepare_ScriptAndScripts(t *testing.T) { } defer os.Remove(tf.Name()) - config["inline"] = []interface{}{"foo"} + config["inline"] = []any{"foo"} config["scripts"] = []string{tf.Name()} err = p.Prepare(config) if err == nil { @@ -647,8 +646,8 @@ func TestProvisionerRemotePathDefaultsSuccessfully(t *testing.T) { } } -func generatedData() map[string]interface{} { - return map[string]interface{}{ +func generatedData() map[string]any { + return map[string]any{ "PackerHTTPAddr": commonsteps.HttpAddrNotImplemented, "PackerHTTPIP": commonsteps.HttpIPNotImplemented, "PackerHTTPPort": commonsteps.HttpPortNotImplemented, diff --git a/provisioner/shell/unix_reader_test.go b/provisioner/shell/unix_reader_test.go index c174654acdc..cd537359c8c 100644 --- a/provisioner/shell/unix_reader_test.go +++ b/provisioner/shell/unix_reader_test.go @@ -10,8 +10,7 @@ import ( ) func TestUnixReader_impl(t *testing.T) { - var raw interface{} - raw = new(UnixReader) + var raw any = new(UnixReader) if _, ok := raw.(io.Reader); !ok { t.Fatal("should be reader") } diff --git a/provisioner/sleep/provisioner.go b/provisioner/sleep/provisioner.go index d6a9ed80067..861ea2cc472 100644 --- a/provisioner/sleep/provisioner.go +++ b/provisioner/sleep/provisioner.go @@ -22,13 +22,13 @@ var _ packersdk.Provisioner = new(Provisioner) func (p *Provisioner) ConfigSpec() hcldec.ObjectSpec { return p.FlatMapstructure().HCL2Spec() } -func (p *Provisioner) FlatConfig() interface{} { return p.FlatMapstructure() } +func (p *Provisioner) FlatConfig() any { return p.FlatMapstructure() } -func (p *Provisioner) Prepare(raws ...interface{}) error { +func (p *Provisioner) Prepare(raws ...any) error { return config.Decode(&p, &config.DecodeOpts{}, raws...) } -func (p *Provisioner) Provision(ctx context.Context, _ packersdk.Ui, _ packersdk.Communicator, _ map[string]interface{}) error { +func (p *Provisioner) Provision(ctx context.Context, _ packersdk.Ui, _ packersdk.Communicator, _ map[string]any) error { select { case <-ctx.Done(): return ctx.Err() diff --git a/provisioner/sleep/provisioner_test.go b/provisioner/sleep/provisioner_test.go index 061ee747f8f..d9e96560d57 100644 --- a/provisioner/sleep/provisioner_test.go +++ b/provisioner/sleep/provisioner_test.go @@ -9,8 +9,8 @@ import ( "time" ) -func test1sConfig() map[string]interface{} { - return map[string]interface{}{ +func test1sConfig() map[string]any { + return map[string]any{ "duration": "1s", } } @@ -51,7 +51,7 @@ func TestProvisioner_Provision(t *testing.T) { p := &Provisioner{ Duration: tt.fields.Duration, } - if err := p.Provision(tt.args.ctx, nil, nil, make(map[string]interface{})); (err != nil) != tt.wantErr { + if err := p.Provision(tt.args.ctx, nil, nil, make(map[string]any)); (err != nil) != tt.wantErr { t.Errorf("Provisioner.Provision() error = %v, wantErr %v", err, tt.wantErr) } }) diff --git a/provisioner/windows-restart/provisioner.go b/provisioner/windows-restart/provisioner.go index ea3090244c3..f0769a458fe 100644 --- a/provisioner/windows-restart/provisioner.go +++ b/provisioner/windows-restart/provisioner.go @@ -70,7 +70,7 @@ type Provisioner struct { func (p *Provisioner) ConfigSpec() hcldec.ObjectSpec { return p.config.FlatMapstructure().HCL2Spec() } -func (p *Provisioner) Prepare(raws ...interface{}) error { +func (p *Provisioner) Prepare(raws ...any) error { err := config.Decode(&p.config, &config.DecodeOpts{ PluginType: "windows-restart", Interpolate: true, @@ -104,7 +104,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { return nil } -func (p *Provisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, _ map[string]interface{}) error { +func (p *Provisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, _ map[string]any) error { p.cancelLock.Lock() p.cancel = make(chan struct{}) p.cancelLock.Unlock() diff --git a/provisioner/windows-restart/provisioner_test.go b/provisioner/windows-restart/provisioner_test.go index 49d769fb959..a0d06ee905a 100644 --- a/provisioner/windows-restart/provisioner_test.go +++ b/provisioner/windows-restart/provisioner_test.go @@ -13,13 +13,12 @@ import ( packersdk "github.com/hashicorp/packer-plugin-sdk/packer" ) -func testConfig() map[string]interface{} { - return map[string]interface{}{} +func testConfig() map[string]any { + return map[string]any{} } func TestProvisioner_Impl(t *testing.T) { - var raw interface{} - raw = &Provisioner{} + var raw any = &Provisioner{} if _, ok := raw.(packersdk.Provisioner); !ok { t.Fatalf("must be a Provisioner") } @@ -107,7 +106,7 @@ func TestProvisionerProvision_Success(t *testing.T) { waitForRestart = func(context.Context, *Provisioner, packersdk.Communicator) error { return nil } - err := p.Provision(context.Background(), ui, comm, make(map[string]interface{})) + err := p.Provision(context.Background(), ui, comm, make(map[string]any)) if err != nil { t.Fatal("should not have error") } @@ -143,7 +142,7 @@ func TestProvisionerProvision_CustomCommand(t *testing.T) { waitForRestart = func(context.Context, *Provisioner, packersdk.Communicator) error { return nil } - err := p.Provision(context.Background(), ui, comm, make(map[string]interface{})) + err := p.Provision(context.Background(), ui, comm, make(map[string]any)) if err != nil { t.Fatal("should not have error") } @@ -166,7 +165,7 @@ func TestProvisionerProvision_RestartCommandFail(t *testing.T) { comm.StartExitStatus = 1 p.Prepare(config) - err := p.Provision(context.Background(), ui, comm, make(map[string]interface{})) + err := p.Provision(context.Background(), ui, comm, make(map[string]any)) if err == nil { t.Fatal("should have error") } @@ -185,7 +184,7 @@ func TestProvisionerProvision_WaitForRestartFail(t *testing.T) { waitForCommunicator = func(context.Context, *Provisioner) error { return fmt.Errorf("Machine did not restart properly") } - err := p.Provision(context.Background(), ui, comm, make(map[string]interface{})) + err := p.Provision(context.Background(), ui, comm, make(map[string]any)) if err == nil { t.Fatal("should have error") } @@ -217,7 +216,7 @@ func TestProvision_waitForRestartTimeout(t *testing.T) { } go func() { - err = p.Provision(context.Background(), ui, comm, make(map[string]interface{})) + err = p.Provision(context.Background(), ui, comm, make(map[string]any)) close(waitDone) }() <-waitContinue @@ -328,7 +327,7 @@ func TestProvision_Cancel(t *testing.T) { // Create two go routines to provision and cancel in parallel // Provision will block until cancel happens go func() { - done <- p.Provision(topCtx, ui, comm, make(map[string]interface{})) + done <- p.Provision(topCtx, ui, comm, make(map[string]any)) }() // Expect interrupt error diff --git a/provisioner/windows-shell/provisioner.go b/provisioner/windows-shell/provisioner.go index 7bed5abb39c..87e9e7cf387 100644 --- a/provisioner/windows-shell/provisioner.go +++ b/provisioner/windows-shell/provisioner.go @@ -46,7 +46,7 @@ type Config struct { type Provisioner struct { config Config - generatedData map[string]interface{} + generatedData map[string]any } type ExecuteCommandTemplate struct { @@ -56,7 +56,7 @@ type ExecuteCommandTemplate struct { func (p *Provisioner) ConfigSpec() hcldec.ObjectSpec { return p.config.FlatMapstructure().HCL2Spec() } -func (p *Provisioner) Prepare(raws ...interface{}) error { +func (p *Provisioner) Prepare(raws ...any) error { err := config.Decode(&p.config, &config.DecodeOpts{ PluginType: "windows-shell", Interpolate: true, @@ -162,7 +162,7 @@ func extractScript(p *Provisioner) (string, error) { return temp.Name(), nil } -func (p *Provisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, generatedData map[string]interface{}) error { +func (p *Provisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, generatedData map[string]any) error { ui.Say("Provisioning with windows-shell...") scripts := make([]string, len(p.config.Scripts)) copy(scripts, p.config.Scripts) diff --git a/provisioner/windows-shell/provisioner_test.go b/provisioner/windows-shell/provisioner_test.go index ed9a0082d54..947b697d564 100644 --- a/provisioner/windows-shell/provisioner_test.go +++ b/provisioner/windows-shell/provisioner_test.go @@ -15,9 +15,9 @@ import ( packersdk "github.com/hashicorp/packer-plugin-sdk/packer" ) -func testConfig() map[string]interface{} { - return map[string]interface{}{ - "inline": []interface{}{"foo", "bar"}, +func testConfig() map[string]any { + return map[string]any{ + "inline": []any{"foo", "bar"}, } } @@ -48,8 +48,7 @@ func TestProvisionerPrepare_extractScript(t *testing.T) { } func TestProvisioner_Impl(t *testing.T) { - var raw interface{} - raw = &Provisioner{} + var raw any = &Provisioner{} if _, ok := raw.(packersdk.Provisioner); !ok { t.Fatalf("must be a Provisioner") } @@ -135,7 +134,7 @@ func TestProvisionerPrepare_ScriptAndInline(t *testing.T) { defer os.Remove(tf.Name()) defer tf.Close() - config["inline"] = []interface{}{"foo"} + config["inline"] = []any{"foo"} config["script"] = tf.Name() err = p.Prepare(config) if err == nil { @@ -155,7 +154,7 @@ func TestProvisionerPrepare_ScriptAndScripts(t *testing.T) { defer os.Remove(tf.Name()) defer tf.Close() - config["inline"] = []interface{}{"foo"} + config["inline"] = []any{"foo"} config["scripts"] = []string{tf.Name()} err = p.Prepare(config) if err == nil { @@ -450,8 +449,8 @@ func TestCancel(t *testing.T) { // Don't actually call Cancel() as it performs an os.Exit(0) // which kills the 'go test' tool } -func generatedData() map[string]interface{} { - return map[string]interface{}{ +func generatedData() map[string]any { + return map[string]any{ "PackerHTTPAddr": commonsteps.HttpAddrNotImplemented, "PackerHTTPIP": commonsteps.HttpIPNotImplemented, "PackerHTTPPort": commonsteps.HttpPortNotImplemented,