From 5ba8121e0808071fa8d3870c3e18328dd2a231d0 Mon Sep 17 00:00:00 2001 From: Dragan Milic Date: Tue, 22 Oct 2024 12:21:36 +0200 Subject: [PATCH] add optional sudo arg for text_file_resource datasource --- datasource/textfile/text_file_resource.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/datasource/textfile/text_file_resource.go b/datasource/textfile/text_file_resource.go index 76876fd..3382a88 100644 --- a/datasource/textfile/text_file_resource.go +++ b/datasource/textfile/text_file_resource.go @@ -31,6 +31,12 @@ func Resource() *schema.Resource { Required: true, }, + "sudo": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + "path": { Type: schema.TypeString, Required: true, @@ -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)