mirror of
https://github.com/letic/terraform-provider-proxmox.git
synced 2024-10-05 02:01:04 +00:00
-support optional insecure TLS proxmox nodes
-restore previous ssh key behavior (works in 0.11.x)
This commit is contained in:
parent
d200eddfcd
commit
ac80ff229d
@ -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" {
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -252,6 +249,7 @@ func resourceVmQemuCreate(d *schema.ResourceData, meta interface{}) error {
|
|||||||
"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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user