github.com/hashicorp/packer@v1.14.3/fix/fixer_scaleway_access_key.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: BUSL-1.1 3 4 package fix 5 6 import ( 7 "github.com/mitchellh/mapstructure" 8 ) 9 10 // FixerScalewayAccessKey changes the "access_key" of a template 11 // to "organization_id". 12 type FixerScalewayAccessKey struct{} 13 14 func (FixerScalewayAccessKey) DeprecatedOptions() map[string][]string { 15 return map[string][]string{ 16 "hashicorp.scaleway": []string{"access_key"}, 17 } 18 } 19 20 func (FixerScalewayAccessKey) Fix(input map[string]interface{}) (map[string]interface{}, error) { 21 // The type we'll decode into; we only care about builders 22 type template struct { 23 Builders []map[string]interface{} 24 } 25 26 // Decode the input into our structure, if we can 27 var tpl template 28 if err := mapstructure.Decode(input, &tpl); err != nil { 29 return nil, err 30 } 31 32 for _, builder := range tpl.Builders { 33 if builder["type"] != "scaleway" { 34 continue 35 } 36 37 keyRaw, ok := builder["access_key"] 38 if !ok { 39 continue 40 } 41 42 accessKey, ok := keyRaw.(string) 43 if !ok { 44 continue 45 } 46 47 // only assign to organization_id if it doesn't 48 // already exist; otherwise we'll just ignore access_key 49 _, organizationIdIncluded := builder["organization_id"] 50 if !organizationIdIncluded { 51 builder["organization_id"] = accessKey 52 } 53 54 delete(builder, "access_key") 55 } 56 57 input["builders"] = tpl.Builders 58 return input, nil 59 } 60 61 func (FixerScalewayAccessKey) Synopsis() string { 62 return `Updates builders using "access_key" to use "organization_id"` 63 }