diff --git a/CHANGELOG.md b/CHANGELOG.md index e73552e7..82bfe21a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ IMPROVEMENTS * 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 * add current timestamp for file upload to container ([#259](https://github.com/kreuzwerker/terraform-provider-docker/issues/259)) diff --git a/docs/index.md b/docs/index.md index 59f119dd..7105e9b0 100644 --- a/docs/index.md +++ b/docs/index.md @@ -72,7 +72,8 @@ The configuration would look as follows: ```terraform 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_content** (String) Plain content of the docker json file for registry auth - **password** (String, Sensitive) Password for the registry -- **username** (String) Username for the registry \ No newline at end of file +- **username** (String) Username for the registry diff --git a/internal/provider/config.go b/internal/provider/config.go index 219cb7fe..d60609a8 100644 --- a/internal/provider/config.go +++ b/internal/provider/config.go @@ -21,6 +21,7 @@ import ( // Docker API compatible host. type Config struct { Host string + SSHOpts []string Ca string Cert string Key string @@ -118,7 +119,7 @@ func (c *Config) NewClient() (*client.Client, error) { } // 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 { return nil, err } diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 7b714dad..a11ef81e 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -43,7 +43,19 @@ func New(version string) func() *schema.Provider { DefaultFunc: schema.EnvDefaultFunc("DOCKER_HOST", "unix:///var/run/docker.sock"), 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": { Type: schema.TypeString, 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) { 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{ Host: d.Get("host").(string), + SSHOpts: SSHOpts, Ca: d.Get("ca_material").(string), Cert: d.Get("cert_material").(string), Key: d.Get("key_material").(string),