Skip to content

Commit f9a0135

Browse files
committed
Add env var key
1 parent e82bbbb commit f9a0135

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

internal/provider/data_source_remotefile.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ func dataSourceRemotefile() *schema.Resource {
6060
Optional: true,
6161
Description: "The path of the private key used to login to the target host.",
6262
},
63+
"private_key_env_var": {
64+
Type: schema.TypeString,
65+
Optional: true,
66+
Description: "The env var of the private key used to login to the target host.",
67+
},
6368
},
6469
},
6570
},

internal/provider/provider.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"io/ioutil"
7+
"os"
78
"strconv"
89
"strings"
910
"sync"
@@ -115,6 +116,16 @@ func RemoteClientFromResource(d *schema.ResourceData) (*RemoteClient, error) {
115116
clientConfig.Auth = append(clientConfig.Auth, ssh.PublicKeys(signer))
116117
}
117118

119+
private_key_env_var, ok := d.GetOk("conn.0.private_key_env_var")
120+
if ok {
121+
private_key := os.Getenv(private_key_env_var.(string))
122+
signer, err := ssh.ParsePrivateKey([]byte(private_key))
123+
if err != nil {
124+
return nil, fmt.Errorf("couldn't create a ssh client config from private key env var: %s", err.Error())
125+
}
126+
clientConfig.Auth = append(clientConfig.Auth, ssh.PublicKeys(signer))
127+
}
128+
118129
host := fmt.Sprintf("%s:%d", d.Get("conn.0.host").(string), d.Get("conn.0.port").(int))
119130
return NewRemoteClient(host, clientConfig)
120131
}

internal/provider/resource_remotefile.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ func resourceRemotefile() *schema.Resource {
6464
Optional: true,
6565
Description: "The path of the private key used to login to the target host.",
6666
},
67+
"private_key_env_var": {
68+
Type: schema.TypeString,
69+
Optional: true,
70+
Description: "The env var of the private key used to login to the target host.",
71+
},
6772
},
6873
},
6974
},

0 commit comments

Comments
 (0)