Skip to content

Commit

Permalink
Merge pull request #88 from numtide/add-sudo-support
Browse files Browse the repository at this point in the history
add optional sudo arg for text_file_resource datasource
  • Loading branch information
draganm authored Oct 22, 2024
2 parents 3157f1d + 5ba8121 commit 42d99c7
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 42d99c7

Please sign in to comment.