-support optional insecure TLS proxmox nodes

-restore previous ssh key behavior (works in 0.11.x)
This commit is contained in:
Grant Gongaware 2018-07-10 14:50:35 -07:00
parent 6cb6133735
commit 90d504fa0d
4 changed files with 24 additions and 15 deletions

View File

@ -31,6 +31,7 @@ terraform apply
main.tf: main.tf:
``` ```
provider "proxmox" { provider "proxmox" {
pm_tls_insecure = true
} }
resource "proxmox_vm_qemu" "test" { resource "proxmox_vm_qemu" "test" {

View File

@ -1,6 +1,7 @@
package proxmox package proxmox
import ( import (
"crypto/tls"
"fmt" "fmt"
"regexp" "regexp"
"strconv" "strconv"
@ -47,6 +48,11 @@ func Provider() *schema.Provider {
Optional: true, Optional: true,
Default: 4, Default: 4,
}, },
"pm_tls_insecure": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
}, },
ResourcesMap: map[string]*schema.Resource{ ResourcesMap: map[string]*schema.Resource{
@ -61,7 +67,7 @@ func Provider() *schema.Provider {
} }
func providerConfigure(d *schema.ResourceData) (interface{}, error) { func providerConfigure(d *schema.ResourceData) (interface{}, error) {
client, err := getClient(d.Get("pm_api_url").(string), d.Get("pm_user").(string), d.Get("pm_password").(string)) client, err := getClient(d.Get("pm_api_url").(string), d.Get("pm_user").(string), d.Get("pm_password").(string), d.Get("pm_tls_insecure").(bool))
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -76,8 +82,12 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
}, nil }, nil
} }
func getClient(pm_api_url string, pm_user string, pm_password string) (*pxapi.Client, error) { func getClient(pm_api_url string, pm_user string, pm_password string, pm_tls_insecure bool) (*pxapi.Client, error) {
client, _ := pxapi.NewClient(pm_api_url, nil, nil) tlsconf := &tls.Config{InsecureSkipVerify: true}
if !pm_tls_insecure {
tlsconf = nil
}
client, _ := pxapi.NewClient(pm_api_url, nil, tlsconf)
err := client.Login(pm_user, pm_password) err := client.Login(pm_user, pm_password)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -44,7 +44,7 @@ func applyFn(ctx context.Context) error {
vmr.SetNode(targetNode) vmr.SetNode(targetNode)
client := currentClient client := currentClient
if client == nil { if client == nil {
client, err = getClient(connInfo["pm_api_url"], connInfo["pm_user"], connInfo["pm_password"]) client, err = getClient(connInfo["pm_api_url"], connInfo["pm_user"], connInfo["pm_password"], connInfo["pm_tls_insecure"] == "true")
if err != nil { if err != nil {
return err return err
} }

View File

@ -111,9 +111,6 @@ func resourceVmQemu() *schema.Resource {
Optional: true, Optional: true,
Sensitive: true, Sensitive: true,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
if old == "" {
return true
}
return strings.TrimSpace(old) == strings.TrimSpace(new) return strings.TrimSpace(old) == strings.TrimSpace(new)
}, },
}, },
@ -244,14 +241,15 @@ func resourceVmQemuCreate(d *schema.ResourceData, meta interface{}) error {
pmParallelEnd(pconf) pmParallelEnd(pconf)
d.SetConnInfo(map[string]string{ d.SetConnInfo(map[string]string{
"type": "ssh", "type": "ssh",
"host": d.Get("ssh_forward_ip").(string), "host": d.Get("ssh_forward_ip").(string),
"port": sshPort, "port": sshPort,
"user": d.Get("ssh_user").(string), "user": d.Get("ssh_user").(string),
"private_key": d.Get("ssh_private_key").(string), "private_key": d.Get("ssh_private_key").(string),
"pm_api_url": client.ApiUrl, "pm_api_url": client.ApiUrl,
"pm_user": client.Username, "pm_user": client.Username,
"pm_password": client.Password, "pm_password": client.Password,
"pm_tls_insecure": "true", // TODO - pass pm_tls_insecure state around, but if we made it this far, default insecure
}) })
switch d.Get("os_type").(string) { switch d.Get("os_type").(string) {