github.com/hashicorp/packer@v1.14.3/fix/fixer_ssh_timeout.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 // FixerSSHTimout replaces ssh_wait_timeout with ssh_timeout 11 type FixerSSHTimout struct{} 12 13 func (FixerSSHTimout) DeprecatedOptions() map[string][]string { 14 return map[string][]string{ 15 "*": {"ssh_wait_timeout"}, 16 } 17 } 18 19 func (FixerSSHTimout) Fix(input map[string]interface{}) (map[string]interface{}, error) { 20 type template struct { 21 Builders []interface{} 22 } 23 24 // Decode the input into our structure, if we can 25 var tpl template 26 if err := mapstructure.WeakDecode(input, &tpl); err != nil { 27 return nil, err 28 } 29 30 for i, raw := range tpl.Builders { 31 var builders map[string]interface{} 32 if err := mapstructure.Decode(raw, &builders); err != nil { 33 // Ignore errors, could be a non-map 34 continue 35 } 36 37 if _, ok := builders["ssh_timeout"]; ok { 38 // drop ssh_wait_timeout if it is also included 39 delete(builders, "ssh_wait_timeout") 40 } else { 41 42 // replace ssh_wait_timeout with ssh_timeout if it exists 43 sshWaitTimeoutRaw, ok := builders["ssh_wait_timeout"] 44 if !ok { 45 continue 46 } 47 48 sshWaitTimeoutString, ok := sshWaitTimeoutRaw.(string) 49 if !ok { 50 continue 51 } 52 53 delete(builders, "ssh_wait_timeout") 54 builders["ssh_timeout"] = sshWaitTimeoutString 55 } 56 57 // Write all changes back to template 58 tpl.Builders[i] = builders 59 } 60 61 if len(tpl.Builders) > 0 { 62 input["builders"] = tpl.Builders 63 } 64 65 return input, nil 66 } 67 68 func (FixerSSHTimout) Synopsis() string { 69 return `Replaces "ssh_wait_timeout" with "ssh_timeout"` 70 }