Skip to content

Commit

Permalink
Add env var key
Browse files Browse the repository at this point in the history
  • Loading branch information
tenstad committed May 7, 2021
1 parent e82bbbb commit f9a0135
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/provider/data_source_remotefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ func dataSourceRemotefile() *schema.Resource {
Optional: true,
Description: "The path of the private key used to login to the target host.",
},
"private_key_env_var": {
Type: schema.TypeString,
Optional: true,
Description: "The env var of the private key used to login to the target host.",
},
},
},
},
Expand Down
11 changes: 11 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -115,6 +116,16 @@ func RemoteClientFromResource(d *schema.ResourceData) (*RemoteClient, error) {
clientConfig.Auth = append(clientConfig.Auth, ssh.PublicKeys(signer))
}

private_key_env_var, ok := d.GetOk("conn.0.private_key_env_var")
if ok {
private_key := os.Getenv(private_key_env_var.(string))
signer, err := ssh.ParsePrivateKey([]byte(private_key))
if err != nil {
return nil, fmt.Errorf("couldn't create a ssh client config from private key env var: %s", err.Error())
}
clientConfig.Auth = append(clientConfig.Auth, ssh.PublicKeys(signer))
}

host := fmt.Sprintf("%s:%d", d.Get("conn.0.host").(string), d.Get("conn.0.port").(int))
return NewRemoteClient(host, clientConfig)
}
Expand Down
5 changes: 5 additions & 0 deletions internal/provider/resource_remotefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ func resourceRemotefile() *schema.Resource {
Optional: true,
Description: "The path of the private key used to login to the target host.",
},
"private_key_env_var": {
Type: schema.TypeString,
Optional: true,
Description: "The env var of the private key used to login to the target host.",
},
},
},
},
Expand Down

0 comments on commit f9a0135

Please sign in to comment.