feat: add parameter for SSH options (#335)

This commit is contained in:
Nolan Woods 2022-01-17 21:37:50 -08:00 committed by GitHub
parent 3fbe7d3a34
commit 24336bc89f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 3 deletions

View file

@ -2,6 +2,7 @@
IMPROVEMENTS IMPROVEMENTS
* add container storage opts ([#258](https://github.com/kreuzwerker/terraform-provider-docker/issues/258)) * add container storage opts ([#258](https://github.com/kreuzwerker/terraform-provider-docker/issues/258))
* add ssh_opts parameter to provider config. Allows passing additional ssh arguments when connecting via ssh. ([#29](https://github.com/kreuzwerker/terraform-provider-docker/issues/29))
BUG FIXES BUG FIXES
* add current timestamp for file upload to container ([#259](https://github.com/kreuzwerker/terraform-provider-docker/issues/259)) * add current timestamp for file upload to container ([#259](https://github.com/kreuzwerker/terraform-provider-docker/issues/259))

View file

@ -72,7 +72,8 @@ The configuration would look as follows:
```terraform ```terraform
provider "docker" { provider "docker" {
host = "ssh://user@remote-host:22" host = "ssh://user@remote-host:22"
ssh_opts = ["-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null"]
} }
``` ```
@ -178,4 +179,4 @@ Optional:
- **config_file** (String) Path to docker json file for registry auth - **config_file** (String) Path to docker json file for registry auth
- **config_file_content** (String) Plain content of the docker json file for registry auth - **config_file_content** (String) Plain content of the docker json file for registry auth
- **password** (String, Sensitive) Password for the registry - **password** (String, Sensitive) Password for the registry
- **username** (String) Username for the registry - **username** (String) Username for the registry

View file

@ -21,6 +21,7 @@ import (
// Docker API compatible host. // Docker API compatible host.
type Config struct { type Config struct {
Host string Host string
SSHOpts []string
Ca string Ca string
Cert string Cert string
Key string Key string
@ -118,7 +119,7 @@ func (c *Config) NewClient() (*client.Client, error) {
} }
// If there is no cert information, then check for ssh:// // If there is no cert information, then check for ssh://
helper, err := connhelper.GetConnectionHelper(c.Host) helper, err := connhelper.GetConnectionHelperWithSSHOpts(c.Host, c.SSHOpts)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -43,7 +43,19 @@ func New(version string) func() *schema.Provider {
DefaultFunc: schema.EnvDefaultFunc("DOCKER_HOST", "unix:///var/run/docker.sock"), DefaultFunc: schema.EnvDefaultFunc("DOCKER_HOST", "unix:///var/run/docker.sock"),
Description: "The Docker daemon address", Description: "The Docker daemon address",
}, },
"ssh_opts": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
DefaultFunc: func() (interface{}, error) {
if v := os.Getenv("DOCKER_SSH_OPTS"); v != "" {
return strings.Fields(v), nil
}
return nil, nil
},
Description: "Addtional SSH option flags to be appended when using ssh:// protocol",
},
"ca_material": { "ca_material": {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
@ -146,8 +158,14 @@ func New(version string) func() *schema.Provider {
func configure(version string, p *schema.Provider) func(context.Context, *schema.ResourceData) (interface{}, diag.Diagnostics) { func configure(version string, p *schema.Provider) func(context.Context, *schema.ResourceData) (interface{}, diag.Diagnostics) {
return func(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) { return func(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
SSHOptsI := d.Get("ssh_opts").([]interface{})
SSHOpts := make([]string, len(SSHOptsI))
for i, s := range SSHOptsI {
SSHOpts[i] = s.(string)
}
config := Config{ config := Config{
Host: d.Get("host").(string), Host: d.Get("host").(string),
SSHOpts: SSHOpts,
Ca: d.Get("ca_material").(string), Ca: d.Get("ca_material").(string),
Cert: d.Get("cert_material").(string), Cert: d.Get("cert_material").(string),
Key: d.Get("key_material").(string), Key: d.Get("key_material").(string),