2014-07-23 11:40:15 -05:00
---
layout: "docs"
page_title: "Provisioner Connections"
sidebar_current: "docs-provisioners-connection"
2014-10-21 22:21:56 -05:00
description: |-
2016-10-09 10:42:43 -05:00
Managing connection defaults for SSH and WinRM using the `connection` block.
2014-07-23 11:40:15 -05:00
---
# Provisioner Connections
Many provisioners require access to the remote resource. For example,
2015-04-10 14:28:28 -05:00
a provisioner may need to use SSH or WinRM to connect to the resource.
2014-07-23 11:40:15 -05:00
2017-04-05 10:29:27 -05:00
Terraform uses a number of defaults when connecting to a resource, but these can
be overridden using a `connection` block in either a `resource` or
`provisioner` . Any `connection` information provided in a `resource` will apply
to all the provisioners, but it can be scoped to a single provisioner as well.
One use case is to have an initial provisioner connect as the `root` user to
setup user accounts, and have subsequent provisioners connect as a user with
more limited permissions.
2014-07-23 11:40:15 -05:00
## Example usage
2017-04-05 10:29:27 -05:00
```hcl
2015-04-10 14:28:28 -05:00
# Copies the file as the root user using SSH
2014-07-23 11:40:15 -05:00
provisioner "file" {
2017-02-18 16:48:50 -06:00
source = "conf/myapp.conf"
destination = "/etc/myapp.conf"
connection {
type = "ssh"
user = "root"
password = "${var.root_password}"
}
2014-07-23 11:40:15 -05:00
}
2015-04-10 14:28:28 -05:00
# Copies the file as the Administrator user using WinRM
provisioner "file" {
2017-02-18 16:48:50 -06:00
source = "conf/myapp.conf"
destination = "C:/App/myapp.conf"
connection {
type = "winrm"
user = "Administrator"
password = "${var.admin_password}"
}
2015-04-10 14:28:28 -05:00
}
2014-07-23 11:40:15 -05:00
```
## Argument Reference
2015-04-10 14:28:28 -05:00
**The following arguments are supported by all connection types:**
2014-07-23 11:40:15 -05:00
2016-10-09 10:42:43 -05:00
* `type` - The connection type that should be used. Valid types are `ssh` and `winrm`
Defaults to `ssh` .
2014-07-23 11:40:15 -05:00
2016-10-09 10:42:43 -05:00
* `user` - The user that we should use for the connection. Defaults to `root` when
using type `ssh` and defaults to `Administrator` when using type `winrm` .
2014-07-23 11:40:15 -05:00
2015-04-10 14:28:28 -05:00
* `password` - The password we should use for the connection. In some cases this is
2016-10-09 10:42:43 -05:00
specified by the provider.
2015-04-10 14:28:28 -05:00
2016-10-09 10:42:43 -05:00
* `host` - The address of the resource to connect to. This is usually specified by the provider.
2015-04-10 14:28:28 -05:00
2016-10-09 10:42:43 -05:00
* `port` - The port to connect to. Defaults to `22` when using type `ssh` and defaults
to `5985` when using type `winrm` .
2015-04-10 14:28:28 -05:00
* `timeout` - The timeout to wait for the connection to become available. This defaults
2016-10-09 10:42:43 -05:00
to 5 minutes. Should be provided as a string like `30s` or `5m` .
2015-04-10 14:28:28 -05:00
2016-04-15 17:05:49 -05:00
* `script_path` - The path used to copy scripts meant for remote execution.
2015-04-10 14:28:28 -05:00
2016-10-09 10:42:43 -05:00
**Additional arguments only supported by the `ssh` connection type:**
2014-07-23 11:40:15 -05:00
2015-11-12 14:39:41 -06:00
* `private_key` - The contents of an SSH key to use for the connection. These can
2018-05-13 18:59:18 -05:00
be loaded from a file on disk using
[the `file` function ](/docs/configuration/functions/file.html ). This takes
2015-11-12 14:39:41 -06:00
preference over the password if provided.
2014-07-23 11:40:15 -05:00
2016-10-09 10:42:43 -05:00
* `agent` - Set to `false` to disable using `ssh-agent` to authenticate. On Windows the
2015-12-15 09:39:23 -06:00
only supported SSH authentication agent is
2016-10-09 10:42:43 -05:00
[Pageant ](http://the.earth.li/~sgtatham/putty/0.66/htmldoc/Chapter9.html#pageant ).
2015-03-15 18:37:33 -05:00
2018-01-08 16:12:55 -06:00
* `agent_identity` - The preferred identity from the ssh agent for authentication.
2018-02-14 14:30:18 -06:00
* `host_key` - The public key from the remote host or the signing CA, used to
verify the connection.
2016-10-09 10:42:43 -05:00
**Additional arguments only supported by the `winrm` connection type:**
2014-07-23 11:40:15 -05:00
2016-10-09 10:42:43 -05:00
* `https` - Set to `true` to connect using HTTPS instead of HTTP.
2014-07-23 11:40:15 -05:00
2016-10-09 10:42:43 -05:00
* `insecure` - Set to `true` to not validate the HTTPS certificate chain.
2014-07-23 11:40:15 -05:00
2018-03-30 20:11:53 -05:00
* `use_ntlm` - Set to `true` to use NTLM authentication, rather than default (basic authentication), removing the requirement for basic authentication to be enabled within the target guest. Further reading for remote connection authentication can be found [here ](https://msdn.microsoft.com/en-us/library/aa384295(v=vs.85 ).aspx).
2015-04-10 14:28:28 -05:00
* `cacert` - The CA certificate to validate against.
2015-06-22 11:34:02 -05:00
< a id = "bastion" > < / a >
2018-05-13 18:59:18 -05:00
2015-06-22 11:34:02 -05:00
## Connecting through a Bastion Host with SSH
2016-10-09 10:42:43 -05:00
The `ssh` connection also supports the following fields to facilitate connnections via a
[bastion host ](https://en.wikipedia.org/wiki/Bastion_host ).
2015-06-22 11:34:02 -05:00
* `bastion_host` - Setting this enables the bastion Host connection. This host
2016-10-09 10:42:43 -05:00
will be connected to first, and then the `host` connection will be made from there.
2015-06-22 11:34:02 -05:00
2018-02-14 14:30:18 -06:00
* `bastion_host_key` - The public key from the remote host or the signing CA,
used to verify the host connection.
2015-06-22 11:34:02 -05:00
* `bastion_port` - The port to use connect to the bastion host. Defaults to the
2016-10-09 10:42:43 -05:00
value of the `port` field.
2015-06-22 11:34:02 -05:00
2016-10-09 10:42:43 -05:00
* `bastion_user` - The user for the connection to the bastion host. Defaults to
the value of the `user` field.
2015-06-22 11:34:02 -05:00
* `bastion_password` - The password we should use for the bastion host.
2016-10-09 10:42:43 -05:00
Defaults to the value of the `password` field.
2015-06-22 11:34:02 -05:00
2015-11-12 14:39:41 -06:00
* `bastion_private_key` - The contents of an SSH key file to use for the bastion
2018-05-13 18:59:18 -05:00
host. These can be loaded from a file on disk using
[the `file` function ](/docs/configuration/functions/file.html ).
2016-10-09 10:42:43 -05:00
Defaults to the value of the `private_key` field.