mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-06-30 02:31:10 +00:00
fix(file): proxmox_virtual_environment_file
allow changing local file path (#1982)
* fix(proxmox_virtual_environment_file): allow changing local file path * fix linter * update test --------- Signed-off-by: Bartosz Cieślik <bartoszcieslik2@gmail.com> Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Co-authored-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
This commit is contained in:
parent
b6bcfe75aa
commit
26c61e3233
@ -200,7 +200,27 @@ func TestAccResourceFile(t *testing.T) {
|
|||||||
"id": fmt.Sprintf("local:snippets/%s", filepath.Base(snippetFile2)),
|
"id": fmt.Sprintf("local:snippets/%s", filepath.Base(snippetFile2)),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
// Update testing
|
// Update testing: no original file
|
||||||
|
{
|
||||||
|
PreConfig: func() {
|
||||||
|
_ = os.Remove(snippetFile2)
|
||||||
|
deleteSnippet(te, filepath.Base(snippetFile1))
|
||||||
|
},
|
||||||
|
Config: te.RenderConfig(`
|
||||||
|
resource "proxmox_virtual_environment_file" "test" {
|
||||||
|
datastore_id = "local"
|
||||||
|
node_name = "{{.NodeName}}"
|
||||||
|
source_file {
|
||||||
|
path = "{{.SnippetFile1}}"
|
||||||
|
}
|
||||||
|
}`),
|
||||||
|
Check: ResourceAttributes("proxmox_virtual_environment_file.test", map[string]string{
|
||||||
|
"content_type": "snippets",
|
||||||
|
"file_name": filepath.Base(snippetFile1),
|
||||||
|
"id": fmt.Sprintf("local:snippets/%s", filepath.Base(snippetFile1)),
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
// Update testing: original file
|
||||||
{
|
{
|
||||||
PreConfig: func() {
|
PreConfig: func() {
|
||||||
deleteSnippet(te, filepath.Base(snippetFile1))
|
deleteSnippet(te, filepath.Base(snippetFile1))
|
||||||
|
@ -793,12 +793,15 @@ func fileRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.D
|
|||||||
fileModificationDate, fileSize, fileTag, err := readFileAttrs(ctx, sourceFilePath)
|
fileModificationDate, fileSize, fileTag, err := readFileAttrs(ctx, sourceFilePath)
|
||||||
diags = append(diags, diag.FromErr(err)...)
|
diags = append(diags, diag.FromErr(err)...)
|
||||||
|
|
||||||
err = d.Set(mkResourceVirtualEnvironmentFileFileModificationDate, fileModificationDate)
|
if fileModificationDate != "" || fileSize != 0 || fileTag != "" {
|
||||||
diags = append(diags, diag.FromErr(err)...)
|
// only when file from state exists
|
||||||
err = d.Set(mkResourceVirtualEnvironmentFileFileSize, fileSize)
|
err = d.Set(mkResourceVirtualEnvironmentFileFileModificationDate, fileModificationDate)
|
||||||
diags = append(diags, diag.FromErr(err)...)
|
diags = append(diags, diag.FromErr(err)...)
|
||||||
err = d.Set(mkResourceVirtualEnvironmentFileFileTag, fileTag)
|
err = d.Set(mkResourceVirtualEnvironmentFileFileSize, fileSize)
|
||||||
diags = append(diags, diag.FromErr(err)...)
|
diags = append(diags, diag.FromErr(err)...)
|
||||||
|
err = d.Set(mkResourceVirtualEnvironmentFileFileTag, fileTag)
|
||||||
|
diags = append(diags, diag.FromErr(err)...)
|
||||||
|
}
|
||||||
|
|
||||||
lastFileMD := d.Get(mkResourceVirtualEnvironmentFileFileModificationDate).(string)
|
lastFileMD := d.Get(mkResourceVirtualEnvironmentFileFileModificationDate).(string)
|
||||||
lastFileSize := int64(d.Get(mkResourceVirtualEnvironmentFileFileSize).(int))
|
lastFileSize := int64(d.Get(mkResourceVirtualEnvironmentFileFileSize).(int))
|
||||||
@ -837,6 +840,10 @@ func readFile(
|
|||||||
) (fileModificationDate string, fileSize int64, fileTag string, err error) {
|
) (fileModificationDate string, fileSize int64, fileTag string, err error) {
|
||||||
f, err := os.Open(sourceFilePath)
|
f, err := os.Open(sourceFilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
// File does not exist, return zero values and no error
|
||||||
|
return "", 0, "", nil
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user