Skip to content

Commit

Permalink
Fix panic
Browse files Browse the repository at this point in the history
=== RUN   TestAccContainerFile_content
67
panic: mode: '' expected type 'string', got unconvertible type 'int'
68

69
goroutine 16536 [running]:
70
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*ResourceData).Set(0xc00108a400, 0x1af4fe9, 0x4, 0x18dbfc0, 0x25716a0, 0x0, 0x0)
71
	/home/runner/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/v2@v2.4.3/helper/schema/resource_data.go:230 +0x574
72
github.com/terraform-lxd/terraform-provider-lxd/lxd.resourceLxdContainerFileRead(0xc00108a400, 0x1aad460, 0xc0011ffa00, 0x7facf43a8858, 0x68)
73
	/home/runner/work/terraform-provider-lxd/terraform-provider-lxd/lxd/resource_lxd_container_file.go:146 +0x776
...
  • Loading branch information
c10l committed Oct 17, 2021
1 parent 41030e9 commit 089b53a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
4 changes: 2 additions & 2 deletions lxd/resource_lxd_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func resourceLxdContainerCreate(d *schema.ResourceData, meta interface{}) error
Source: f["source"].(string),
UID: f["uid"].(int),
GID: f["gid"].(int),
Mode: f["mode"].(string),
Mode: f["mode"].(int),
CreateDirectories: f["create_directories"].(bool),
}

Expand Down Expand Up @@ -652,7 +652,7 @@ func resourceLxdContainerUpdate(d *schema.ResourceData, meta interface{}) error
Source: f["source"].(string),
UID: f["uid"].(int),
GID: f["gid"].(int),
Mode: f["mode"].(string),
Mode: f["mode"].(int),
CreateDirectories: f["create_directories"].(bool),
}

Expand Down
4 changes: 2 additions & 2 deletions lxd/resource_lxd_container_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func resourceLxdContainerFile() *schema.Resource {
},

"mode": {
Type: schema.TypeString,
Type: schema.TypeInt,
ForceNew: true,
Optional: true,
},
Expand Down Expand Up @@ -102,7 +102,7 @@ func resourceLxdContainerFileCreate(d *schema.ResourceData, meta interface{}) er
Source: d.Get("source").(string),
UID: d.Get("uid").(int),
GID: d.Get("gid").(int),
Mode: d.Get("mode").(string),
Mode: d.Get("mode").(int),
CreateDirectories: d.Get("create_directories").(bool),
Append: d.Get("append").(bool),
}
Expand Down
18 changes: 5 additions & 13 deletions lxd/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"os"
"path"
"path/filepath"
"strconv"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -66,7 +65,7 @@ type File struct {
Source string
UID int
GID int
Mode string
Mode int
CreateDirectories bool
Append bool
}
Expand Down Expand Up @@ -229,23 +228,16 @@ func containerUploadFile(server lxd.ContainerServer, container string, file File
return fmt.Errorf("Target must be an absolute path with filename")
}

mode := os.FileMode(0755)
if len(file.Mode) != 3 {
file.Mode = "0" + file.Mode
mode := os.FileMode(file.Mode)
if mode == 0 {
mode = os.FileMode(0755)
}

m, err := strconv.ParseInt(file.Mode, 0, 0)
if err != nil {
return fmt.Errorf("Could not determine file mode %s", file.Mode)
}

mode = os.FileMode(m)

// Build the file creation request, without the content.
uid := int64(file.UID)
gid := int64(file.GID)
args := lxd.ContainerFileArgs{
Mode: int(mode.Perm()),
Mode: int(mode),
UID: int64(uid),
GID: int64(gid),
Type: "file",
Expand Down

0 comments on commit 089b53a

Please sign in to comment.