github.com/atsaki/terraform@v0.4.3-0.20150919165407-25bba5967654/website/source/docs/provisioners/file.html.markdown (about)

     1  ---
     2  layout: "docs"
     3  page_title: "Provisioner: file"
     4  sidebar_current: "docs-provisioners-file"
     5  description: |-
     6    The `file` provisioner is used to copy files or directories from the machine executing Terraform to the newly created resource. The `file` provisioner supports both `ssh` and `winrm` type connections.
     7  ---
     8  
     9  # File Provisioner
    10  
    11  The `file` provisioner is used to copy files or directories from the machine
    12  executing Terraform to the newly created resource. The `file` provisioner
    13  supports both `ssh` and `winrm` type [connections](/docs/provisioners/connection.html).
    14  
    15  ## Example usage
    16  
    17  ```
    18  resource "aws_instance" "web" {
    19      ...
    20  
    21      # Copies the myapp.conf file to /etc/myapp.conf
    22      provisioner "file" {
    23          source = "conf/myapp.conf"
    24          destination = "/etc/myapp.conf"
    25      }
    26  
    27      # Copies the configs.d folder to /etc/configs.d
    28      provisioner "file" {
    29          source = "conf/configs.d"
    30          destination = "/etc"
    31      }
    32  
    33      # Copies all files and folders in apps/app1 to D:/IIS/webapp1
    34      provisioner "file" {
    35          source = "apps/app1/"
    36          destination = "D:/IIS/webapp1"
    37      }
    38  }
    39  ```
    40  
    41  ## Argument Reference
    42  
    43  The following arguments are supported:
    44  
    45  * `source` - (Required) This is the source file or folder. It can be specified as relative
    46    to the current working directory or as an absolute path.
    47  
    48  * `destination` - (Required) This is the destination path. It must be specified as an
    49    absolute path.
    50  
    51  ## Directory Uploads
    52  
    53  The file provisioner is also able to upload a complete directory to the remote machine.
    54  When uploading a directory, there are a few important things you should know.
    55  
    56  First, when using the `ssh` connection type the destination directory must already exist.
    57  If you need to create it, use a remote-exec provisioner just prior to the file provisioner
    58  in order to create the directory. When using the `winrm` connection type the destination
    59  directory will be created for you if it doesn't already exist.
    60  
    61  Next, the existence of a trailing slash on the source path will determine whether the
    62  directory name will be embedded within the destination, or whether the destination will
    63  be created. An example explains this best:
    64  
    65  If the source is `/foo` (no trailing slash), and the destination is `/tmp`, then the contents
    66  of `/foo` on the local machine will be uploaded to `/tmp/foo` on the remote machine. The
    67  `foo` directory on the remote machine will be created by Terraform.
    68  
    69  If the source, however, is `/foo/` (a trailing slash is present), and the destination is
    70  `/tmp`, then the contents of `/foo` will be uploaded directly into `/tmp` directly.
    71  
    72  This behavior was adopted from the standard behavior of rsync. Note that under the covers,
    73  rsync may or may not be used.