From 39a47f793f8d92a565fbec0e1750df9676021a8c Mon Sep 17 00:00:00 2001 From: Grant Gongaware Date: Wed, 15 Feb 2017 15:32:37 -0800 Subject: [PATCH] support retry on first ssh commands --- proxmox/preprovision.go | 18 +++++++++++++++--- proxmox/provider.go | 1 + proxmox/resource_vm_qemu.go | 7 ++++--- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/proxmox/preprovision.go b/proxmox/preprovision.go index 7714305..1de308c 100644 --- a/proxmox/preprovision.go +++ b/proxmox/preprovision.go @@ -11,6 +11,7 @@ import ( "log" "strconv" "strings" + "time" ) const eth0Payload = "echo $'%s' > /tmp/tf_eth0_payload" @@ -59,9 +60,20 @@ func preProvisionUbuntu(d *schema.ResourceData) error { } log.Print("[DEBUG] sending os_network_config") - err = runCommand(comm, fmt.Sprintf(eth0Payload, strings.Trim(strconv.Quote(d.Get("os_network_config").(string)), "\""))) - if err != nil { - return err + + // on this first one allow some retries to connect + rr := 0 + for { + rr++ + err = runCommand(comm, fmt.Sprintf(eth0Payload, strings.Trim(strconv.Quote(d.Get("os_network_config").(string)), "\""))) + if err != nil { + if rr > 3 { + return err + } + time.Sleep(2 * time.Second) + continue + } + break } hostname := d.Get("name").(string) diff --git a/proxmox/provider.go b/proxmox/provider.go index 8ba9278..01ed805 100644 --- a/proxmox/provider.go +++ b/proxmox/provider.go @@ -25,6 +25,7 @@ func Provider() *schema.Provider { Required: true, DefaultFunc: schema.EnvDefaultFunc("PM_PASS", nil), Description: "secret", + Sensitive: true, }, "pm_api_url": { Type: schema.TypeString, diff --git a/proxmox/resource_vm_qemu.go b/proxmox/resource_vm_qemu.go index 1c180a8..b502973 100644 --- a/proxmox/resource_vm_qemu.go +++ b/proxmox/resource_vm_qemu.go @@ -95,9 +95,10 @@ func resourceVmQemu() *schema.Resource { ForceNew: true, }, "ssh_private_key": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Sensitive: true, }, }, }