Skip to content

Commit

Permalink
add optional sudo arg for text_file_resource datasource
Browse files Browse the repository at this point in the history
  • Loading branch information
draganm committed Oct 22, 2024
1 parent 3157f1d commit 5ba8121
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions datasource/textfile/text_file_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ func Resource() *schema.Resource {
Required: true,
},

"sudo": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},

"path": {
Type: schema.TypeString,
Required: true,
Expand All @@ -48,6 +54,10 @@ func resourceRead(d *schema.ResourceData, m interface{}) error {
path := d.Get("path").(string)

cmd := fmt.Sprintf("cat %s", shellescape.Quote(path))
if d.Get("sudo").(bool) {
cmd = fmt.Sprintf("sudo %s", cmd)
}

stdout, _, err := sshsession.Run(d, cmd)
if err != nil {
return fmt.Errorf("while getting content of %s: %w", path, err)
Expand Down

0 comments on commit 5ba8121

Please sign in to comment.