provisioner/remote-exec: Retry SSH connections
This commit is contained in:
parent
9cd69a2b29
commit
de8ee65b2b
|
@ -47,8 +47,8 @@ type SSHConfig struct {
|
||||||
Host string
|
Host string
|
||||||
Port int
|
Port int
|
||||||
Timeout string
|
Timeout string
|
||||||
ScriptPath string `mapstructure:"script_path"`
|
ScriptPath string `mapstructure:"script_path"`
|
||||||
TimeoutVal time.Duration
|
TimeoutVal time.Duration `mapstructure:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ResourceProvisioner) Apply(s *terraform.ResourceState,
|
func (p *ResourceProvisioner) Apply(s *terraform.ResourceState,
|
||||||
|
@ -104,6 +104,7 @@ func (p *ResourceProvisioner) Validate(c *terraform.ResourceConfig) (ws []string
|
||||||
func (p *ResourceProvisioner) verifySSH(s *terraform.ResourceState) error {
|
func (p *ResourceProvisioner) verifySSH(s *terraform.ResourceState) error {
|
||||||
connType := s.ConnInfo.Raw["type"]
|
connType := s.ConnInfo.Raw["type"]
|
||||||
switch connType {
|
switch connType {
|
||||||
|
case nil:
|
||||||
case "":
|
case "":
|
||||||
case "ssh":
|
case "ssh":
|
||||||
default:
|
default:
|
||||||
|
@ -256,7 +257,18 @@ func (p *ResourceProvisioner) runScripts(conf *SSHConfig, scripts []io.ReadClose
|
||||||
ssh.KeyboardInteractive(helper.PasswordKeyboardInteractive(conf.Password)))
|
ssh.KeyboardInteractive(helper.PasswordKeyboardInteractive(conf.Password)))
|
||||||
}
|
}
|
||||||
host := fmt.Sprintf("%s:%d", conf.Host, conf.Port)
|
host := fmt.Sprintf("%s:%d", conf.Host, conf.Port)
|
||||||
comm, err := helper.New(host, &helper.Config{SSHConfig: sshConf})
|
config := &helper.Config{
|
||||||
|
SSHConfig: sshConf,
|
||||||
|
Connection: helper.ConnectFunc("tcp", host),
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait and retry until we establish the SSH connection
|
||||||
|
var comm *helper.SSHCommunicator
|
||||||
|
err := retryFunc(conf.TimeoutVal, func() error {
|
||||||
|
var err error
|
||||||
|
comm, err = helper.New(host, config)
|
||||||
|
return err
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue