0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-07-05 05:24:01 +00:00

Merge remote-tracking branch 'origin/main' into breakdown-vm-code

This commit is contained in:
Pavel Boldyrev 2024-02-16 18:13:32 -05:00
commit 24ae837776
No known key found for this signature in database
GPG Key ID: 02A24794ADAC7455
18 changed files with 82 additions and 63 deletions

View File

@ -21,7 +21,7 @@ jobs:
fetch-depth: 0
- name: Filter paths
uses: dorny/paths-filter@0bc4621a3135347011ad047f9ecf449bf72ce2bd # v3.0.0
uses: dorny/paths-filter@ebc4d7e9ebcb0b1eb21480bb8f43113e996ac77a # v3.0.1
id: filter
with:
filters: |

View File

@ -17,7 +17,7 @@ jobs:
fetch-depth: 1
- name: Filter paths
uses: dorny/paths-filter@0bc4621a3135347011ad047f9ecf449bf72ce2bd # v3.0.0
uses: dorny/paths-filter@ebc4d7e9ebcb0b1eb21480bb8f43113e996ac77a # v3.0.1
id: filter
with:
filters: |
@ -48,7 +48,7 @@ jobs:
fetch-depth: 1
- name: Filter paths
uses: dorny/paths-filter@0bc4621a3135347011ad047f9ecf449bf72ce2bd # v3.0.0
uses: dorny/paths-filter@ebc4d7e9ebcb0b1eb21480bb8f43113e996ac77a # v3.0.1
id: filter
with:
filters: |

View File

@ -1,3 +1,3 @@
{
".": "0.46.3"
".": "0.46.4"
}

View File

@ -1,5 +1,24 @@
# Changelog
## [0.46.4](https://github.com/bpg/terraform-provider-proxmox/compare/v0.46.3...v0.46.4) (2024-02-16)
### Bug Fixes
* **vm:** fix panic when a config block is empty ([#1033](https://github.com/bpg/terraform-provider-proxmox/issues/1033)) ([027cf1e](https://github.com/bpg/terraform-provider-proxmox/commit/027cf1e81a2ab25f9d934921c6510d091870e3ee))
* **vm:** multi-line description field is always marked as changed ([#1030](https://github.com/bpg/terraform-provider-proxmox/issues/1030)) ([797873b](https://github.com/bpg/terraform-provider-proxmox/commit/797873b257614246fbadf167e7649cc5ed8e17e8))
### Miscellaneous
* **ci:** update actions/create-github-app-token action (v1.7.0 → v1.8.0) ([#1022](https://github.com/bpg/terraform-provider-proxmox/issues/1022)) ([0469192](https://github.com/bpg/terraform-provider-proxmox/commit/046919275607986c4ff380a846171f0c56e5e5f2))
* **ci:** update dorny/paths-filter action (v3.0.0 → v3.0.1) ([#1032](https://github.com/bpg/terraform-provider-proxmox/issues/1032)) ([d444202](https://github.com/bpg/terraform-provider-proxmox/commit/d444202ab8b2f80f6d144d46ea2af55f25aa8af7))
* **ci:** update mergify config to auto-approve renovate PRs ([#1023](https://github.com/bpg/terraform-provider-proxmox/issues/1023)) ([dfb95a8](https://github.com/bpg/terraform-provider-proxmox/commit/dfb95a85f437c3e414f2e8c7020d0077ebe01bc7))
* **deps:** update golang.org/x/exp digest (v0.0.0-20240205201215-2c58cdc269a3 → ) ([#1031](https://github.com/bpg/terraform-provider-proxmox/issues/1031)) ([4fab30e](https://github.com/bpg/terraform-provider-proxmox/commit/4fab30e5dfd62d63e29986b86dca57943f13d8af))
* **deps:** update module golang.org/x/crypto (v0.18.0 → v0.19.0) ([#1018](https://github.com/bpg/terraform-provider-proxmox/issues/1018)) ([34d31e2](https://github.com/bpg/terraform-provider-proxmox/commit/34d31e2ed080dc944900f5219338dbe9846a3aad))
* **deps:** update module golang.org/x/net (v0.20.0 → v0.21.0) ([#1020](https://github.com/bpg/terraform-provider-proxmox/issues/1020)) ([ed3bdb5](https://github.com/bpg/terraform-provider-proxmox/commit/ed3bdb5187dbf5588eedfc8d9ed193ab108edd64))
* **docs:** update links disk image link in examples ([#1028](https://github.com/bpg/terraform-provider-proxmox/issues/1028)) ([62a2130](https://github.com/bpg/terraform-provider-proxmox/commit/62a2130554c9ad09a7406d40e19678c4471f9364))
## [0.46.3](https://github.com/bpg/terraform-provider-proxmox/compare/v0.46.2...v0.46.3) (2024-02-07)

View File

@ -1,7 +1,7 @@
NAME=terraform-provider-proxmox
TARGETS=darwin linux windows
TERRAFORM_PLUGIN_EXTENSION=
VERSION=0.46.3# x-release-please-version
VERSION=0.46.4# x-release-please-version
# check if opentofu is installed and use it if it is,
# otherwise use terraform

View File

@ -2,7 +2,7 @@ terraform {
required_providers {
proxmox = {
source = "bpg/proxmox"
version = "0.46.3" # x-release-please-version
version = "0.46.4" # x-release-please-version
}
}
}

View File

@ -2,7 +2,7 @@ terraform {
required_providers {
proxmox = {
source = "bpg/proxmox"
version = "0.46.3" # x-release-please-version
version = "0.46.4" # x-release-please-version
}
}
}

View File

@ -2,7 +2,7 @@ terraform {
required_providers {
proxmox = {
source = "bpg/proxmox"
version = "0.46.3" # x-release-please-version
version = "0.46.4" # x-release-please-version
}
}
}

View File

@ -2,7 +2,7 @@ terraform {
required_providers {
proxmox = {
source = "bpg/proxmox"
version = "0.46.3" # x-release-please-version
version = "0.46.4" # x-release-please-version
}
}
}

View File

@ -2,7 +2,7 @@ terraform {
required_providers {
proxmox = {
source = "bpg/proxmox"
version = "0.46.3" # x-release-please-version
version = "0.46.4" # x-release-please-version
}
}
}

View File

@ -43,12 +43,12 @@ func TestAccResourceContainer(t *testing.T) {
func testAccResourceContainerCreateConfig(isTemplate bool) string {
return fmt.Sprintf(`
// resource "proxmox_virtual_environment_download_file" "ubuntu_container_template" {
// content_type = "vztmpl"
// datastore_id = "local"
// node_name = "pve"
// url = "http://download.proxmox.com/images/system/ubuntu-20.04-standard_20.04-1_amd64.tar.gz"
// }
resource "proxmox_virtual_environment_download_file" "ubuntu_container_template" {
content_type = "vztmpl"
datastore_id = "local"
node_name = "pve"
url = "http://download.proxmox.com/images/system/ubuntu-23.04-standard_23.04-1_amd64.tar.zst"
}
resource "proxmox_virtual_environment_container" "test_container" {
node_name = "%s"
vm_id = 1100
@ -59,11 +59,11 @@ resource "proxmox_virtual_environment_container" "test_container" {
size = 8
}
// description = <<-EOT
// my
// description
// value
// EOT
description = <<-EOT
my
description
value
EOT
initialization {
hostname = "test"
@ -80,9 +80,7 @@ resource "proxmox_virtual_environment_container" "test_container" {
}
operating_system {
# TODO: this file needs to be upload to PVE first
//template_file_id = proxmox_virtual_environment_download_file.ubuntu_container_template.id
template_file_id = "local:vztmpl/ubuntu-20.04-standard_20.04-1_amd64.tar.gz"
template_file_id = proxmox_virtual_environment_download_file.ubuntu_container_template.id
type = "ubuntu"
}
}
@ -93,7 +91,7 @@ func testAccResourceContainerCreateCheck(t *testing.T) resource.TestCheckFunc {
t.Helper()
return resource.ComposeTestCheckFunc(
// resource.TestCheckResourceAttr(accTestContainerName, "description", "my\ndescription\nvalue\n"),
resource.TestCheckResourceAttr(accTestContainerName, "description", "my\ndescription\nvalue\n"),
func(*terraform.State) error {
err := getNodesClient().Container(1100).WaitForContainerStatus(context.Background(), "running", 10, 1)
require.NoError(t, err, "container did not start")

View File

@ -23,7 +23,6 @@ import (
"github.com/bpg/terraform-provider-proxmox/proxmox/api"
"github.com/bpg/terraform-provider-proxmox/proxmox/ssh"
resourceSsh "github.com/bpg/terraform-provider-proxmox/proxmoxtf/resource/ssh"
"github.com/bpg/terraform-provider-proxmox/utils"
)
@ -157,7 +156,7 @@ func uploadSnippetFile(t *testing.T, file *os.File) {
_, err = sshClient.ExecuteNodeCommands(context.Background(), "pve", []string{
fmt.Sprintf(`%s; try_sudo "mv /tmp/tfpve/testacc/snippets/%s /var/lib/vz/snippets/%s" && rm -rf /tmp/tfpve/testacc/`,
resourceSsh.TrySudo,
ssh.TrySudo,
fname, fname,
),
})

4
go.mod
View File

@ -19,7 +19,7 @@ require (
github.com/skeema/knownhosts v1.2.1
github.com/stretchr/testify v1.8.4
golang.org/x/crypto v0.19.0
golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a
golang.org/x/net v0.21.0
)
@ -62,7 +62,7 @@ require (
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/zclconf/go-cty v1.14.2 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/mod v0.15.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/appengine v1.6.8 // indirect

12
go.sum
View File

@ -180,12 +180,12 @@ golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2Uz
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3 h1:/RIbNt/Zr7rVhIkQhooTxCxFcdWLGIKnZA4IXNFSrvo=
golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08=
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a h1:HinSgX1tJRX3KsL//Gxynpw5CTOAIPhgL4W8PNiIpVE=
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8=
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
@ -240,8 +240,8 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc=
golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps=
golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ=
golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=

View File

@ -28,6 +28,18 @@ import (
"github.com/bpg/terraform-provider-proxmox/utils"
)
const (
// TrySudo is a shell function that tries to execute a command with sudo if the user has sudo permissions.
TrySudo = `try_sudo(){ if [ $(sudo -n pvesm apiinfo 2>&1 | grep "APIVER" | wc -l) -gt 0 ]; then sudo $1; else $1; fi }`
)
// NewErrUserHasNoPermission creates a new error indicating that the SSH user does not have required permissions.
func NewErrUserHasNoPermission(username string) error {
return fmt.Errorf("the SSH user '%s' does not have required permissions. "+
"Make sure 'sudo' is installed and the user is configured in sudoers file. "+
"Refer to the documentation for more details", username)
}
// Client is an interface for performing SSH requests against the Proxmox Nodes.
type Client interface {
// Username returns the SSH username.

View File

@ -285,7 +285,10 @@ func Container() *schema.Resource {
StateFunc: func(i interface{}) string {
// PVE always adds a newline to the description, so we have to do the same,
// also taking in account the CLRF case (Windows)
return strings.ReplaceAll(strings.TrimSpace(i.(string)), "\r\n", "\n") + "\n"
if i.(string) != "" {
return strings.ReplaceAll(strings.TrimSpace(i.(string)), "\r\n", "\n") + "\n"
}
return ""
},
},
mkResourceVirtualEnvironmentContainerDisk: {

View File

@ -32,6 +32,7 @@ import (
"golang.org/x/exp/slices"
"github.com/bpg/terraform-provider-proxmox/proxmox/api"
"github.com/bpg/terraform-provider-proxmox/proxmox/ssh"
"github.com/bpg/terraform-provider-proxmox/proxmoxtf"
"github.com/bpg/terraform-provider-proxmox/proxmoxtf/resource/validator"
"github.com/bpg/terraform-provider-proxmox/utils"
@ -605,7 +606,7 @@ func fileCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag
})
if err != nil {
if matches, e := regexp.MatchString(`cannot move .* Permission denied`, err.Error()); e == nil && matches {
return diag.FromErr(ssh.NewErrSSHUserNoPermission(capi.SSH().Username()))
return diag.FromErr(ssh.NewErrUserHasNoPermission(capi.SSH().Username()))
}
diags = append(diags, diag.Errorf("error moving file: %s", err.Error())...)
@ -875,7 +876,6 @@ func readFile(
return fileModificationDate, fileSize, fileTag, nil
}
//nolint:nonamedreturns
func readURL(
httClient *http.Client,
) func(
@ -885,15 +885,22 @@ func readURL(
return func(
ctx context.Context,
sourceFilePath string,
) (fileModificationDate string, fileSize int64, fileTag string, err error) {
res, err := httClient.Head(sourceFilePath)
) (string, int64, string, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodHead, sourceFilePath, nil)
if err != nil {
return
return "", 0, "", fmt.Errorf("failed to create a new request: %w", err)
}
res, err := httClient.Do(req) //nolint:bodyclose
if err != nil {
return "", 0, "", fmt.Errorf("failed to HEAD the URL: %w", err)
}
defer utils.CloseOrLogError(ctx)(res.Body)
fileSize = res.ContentLength
fileModificationDate := ""
fileSize := res.ContentLength
fileTag := ""
httpLastModified := res.Header.Get("Last-Modified")
if httpLastModified != "" {
@ -903,7 +910,7 @@ func readURL(
if err != nil {
timeParsed, err = time.Parse(time.RFC1123Z, httpLastModified)
if err != nil {
return
return fileModificationDate, fileSize, fileTag, fmt.Errorf("failed to parse Last-Modified header: %w", err)
}
}
@ -917,14 +924,10 @@ func readURL(
if len(httpTagParts) > 1 {
fileTag = httpTagParts[1]
} else {
fileTag = ""
}
} else {
fileTag = ""
}
return
return fileModificationDate, fileSize, fileTag, nil
}
}

View File

@ -1,15 +0,0 @@
package ssh
import (
"fmt"
)
const (
TrySudo = `try_sudo(){ if [ $(sudo -n pvesm apiinfo 2>&1 | grep "APIVER" | wc -l) -gt 0 ]; then sudo $1; else $1; fi }`
)
func NewErrSSHUserNoPermission(username string) error {
return fmt.Errorf("the SSH user '%s' does not have required permissions. "+
"Make sure 'sudo' is installed and the user is configured in sudoers file. "+
"Refer to the documentation for more details", username)
}