github.com/minamijoyo/terraform@v0.7.8-0.20161029001309-18b3736ba44b/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 string in content into /tmp/file.log
    28      provisioner "file" {
    29          content = "ami used: ${self.ami}"
    30          destination = "/tmp/file.log"
    31      }
    32  
    33      # Copies the configs.d folder to /etc/configs.d
    34      provisioner "file" {
    35          source = "conf/configs.d"
    36          destination = "/etc"
    37      }
    38  
    39      # Copies all files and folders in apps/app1 to D:/IIS/webapp1
    40      provisioner "file" {
    41          source = "apps/app1/"
    42          destination = "D:/IIS/webapp1"
    43      }
    44  }
    45  ```
    46  
    47  ## Argument Reference
    48  
    49  The following arguments are supported:
    50  
    51  * `source` - This is the source file or folder. It can be specified as relative
    52    to the current working directory or as an absolute path. This attribute cannot be specifed with `content`.
    53  
    54  * `content` - This is the content to copy on the destination. If destination is a file,
    55    the content will be written on that file, in case of a directory a file named
    56    *tf-file-content* is created. It's recommended to use a file as destination. A
    57    [`template_file`](/docs/providers/template/d/file.html) might be referenced in here, or
    58    any interpolation syntax. This attribute cannot be specified with `source`.
    59  
    60  * `destination` - (Required) This is the destination path. It must be specified as an
    61    absolute path.
    62  
    63  ## Directory Uploads
    64  
    65  The file provisioner is also able to upload a complete directory to the remote machine.
    66  When uploading a directory, there are a few important things you should know.
    67  
    68  First, when using the `ssh` connection type the destination directory must already exist.
    69  If you need to create it, use a remote-exec provisioner just prior to the file provisioner
    70  in order to create the directory. When using the `winrm` connection type the destination
    71  directory will be created for you if it doesn't already exist.
    72  
    73  Next, the existence of a trailing slash on the source path will determine whether the
    74  directory name will be embedded within the destination, or whether the destination will
    75  be created. An example explains this best:
    76  
    77  If the source is `/foo` (no trailing slash), and the destination is `/tmp`, then the contents
    78  of `/foo` on the local machine will be uploaded to `/tmp/foo` on the remote machine. The
    79  `foo` directory on the remote machine will be created by Terraform.
    80  
    81  If the source, however, is `/foo/` (a trailing slash is present), and the destination is
    82  `/tmp`, then the contents of `/foo` will be uploaded directly into `/tmp` directly.
    83  
    84  This behavior was adopted from the standard behavior of rsync. 
    85  
    86  **Note:** Under the covers, rsync may or may not be used.