github.com/hs0210/hashicorp-terraform@v0.11.12-beta1/website/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 ```hcl 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 52 relative to the current working directory or as an absolute path. This 53 attribute cannot be specified with `content`. 54 55 * `content` - This is the content to copy on the destination. If destination is a file, 56 the content will be written on that file, in case of a directory a file named 57 `tf-file-content` is created. It's recommended to use a file as the destination. A 58 [`template_file`](/docs/providers/template/d/file.html) might be referenced in here, or 59 any interpolation syntax. This attribute cannot be specified with `source`. 60 61 * `destination` - (Required) This is the destination path. It must be specified as an 62 absolute path. 63 64 ## Directory Uploads 65 66 The file provisioner is also able to upload a complete directory to the remote machine. 67 When uploading a directory, there are a few important things you should know. 68 69 First, when using the `ssh` connection type the destination directory must already exist. 70 If you need to create it, use a remote-exec provisioner just prior to the file provisioner 71 in order to create the directory. When using the `winrm` connection type the destination 72 directory will be created for you if it doesn't already exist. 73 74 Next, the existence of a trailing slash on the source path will determine whether the 75 directory name will be embedded within the destination, or whether the destination will 76 be created. An example explains this best: 77 78 If the source is `/foo` (no trailing slash), and the destination is `/tmp`, then the contents 79 of `/foo` on the local machine will be uploaded to `/tmp/foo` on the remote machine. The 80 `foo` directory on the remote machine will be created by Terraform. 81 82 If the source, however, is `/foo/` (a trailing slash is present), and the destination is 83 `/tmp`, then the contents of `/foo` will be uploaded directly into `/tmp`. 84 85 This behavior was adopted from the standard behavior of 86 [rsync](https://linux.die.net/man/1/rsync). 87 88 -> **Note:** Under the covers, rsync may or may not be used.