2014-09-27 21:28:07 +02:00
---
layout: "docs"
page_title: "Command: init"
sidebar_current: "docs-commands-init"
2014-10-22 05:21:56 +02:00
description: |-
2017-02-15 22:14:32 +01:00
The `terraform init` command is used to initialize a Terraform configuration. This is the first command that should be run for any new or existing Terraform configuration. It is safe to run this command multiple times.
2014-09-27 21:28:07 +02:00
---
# Command: init
2017-06-03 01:59:52 +02:00
The `terraform init` command is used to initialize a working directory
containing Terraform configuration files. This is the first command that should
be run after writing a new Terraform configuration or cloning an existing one
from version control. It is safe to run this command multiple times.
2014-09-27 21:28:07 +02:00
## Usage
2017-02-15 22:14:32 +01:00
Usage: `terraform init [options] [SOURCE] [PATH]`
2014-09-27 21:28:07 +02:00
2017-06-03 01:59:52 +02:00
Initialize a new or existing Terraform working directory by creating
2017-02-15 22:14:32 +01:00
initial files, loading any remote state, downloading modules, etc.
2014-09-27 21:28:07 +02:00
2017-02-15 22:14:32 +01:00
This is the first command that should be run for any new or existing
Terraform configuration per machine. This sets up all the local data
2017-04-26 16:10:04 +02:00
necessary to run Terraform that is typically not committed to version
2017-02-15 22:14:32 +01:00
control.
2014-12-06 00:29:00 +01:00
2017-02-15 22:14:32 +01:00
This command is always safe to run multiple times. Though subsequent runs
2017-06-03 01:59:52 +02:00
may give errors, this command will never delete your configuration or state.
2017-02-15 22:14:32 +01:00
Even so, if you have important information, please back it up prior to
running this command just in case.
2017-06-03 01:59:52 +02:00
If no arguments are given, the configuration in the current working directory
2017-02-15 22:14:32 +01:00
is initialized.
If one or two arguments are given, the first is a SOURCE of a module to
download to the second argument PATH. After downloading the module to PATH,
the configuration will be initialized as if this command were called pointing
only to that PATH. PATH must be empty of any Terraform files. Any
conflicting non-Terraform files will be overwritten. The module download
is a copy. If you're downloading a module from Git, it will not preserve
Git history.
2014-12-06 00:29:00 +01:00
The command-line flags are all optional. The list of available flags are:
2017-06-03 01:59:52 +02:00
* `-backend=true` - Initialize the [backend ](/docs/backends ) for this configuration.
2014-12-06 00:29:00 +01:00
2017-03-17 07:27:05 +01:00
* `-backend-config=value` - Value can be a path to an HCL file or a string
in the format of 'key=value'. This specifies additional configuration to merge
for the backend. This can be specified multiple times. Flags specified
later in the line override those specified earlier if they conflict.
2014-12-06 00:29:00 +01:00
2017-04-20 23:34:14 +02:00
* `-force-copy` - Suppress prompts about copying state data. This is equivalent
to providing a "yes" to all confirmation prompts.
2017-02-15 22:14:32 +01:00
* `-get=true` - Download any modules for this configuration.
2014-12-06 00:29:00 +01:00
2017-02-15 22:14:32 +01:00
* `-input=true` - Ask for input interactively if necessary. If this is false
and input is required, `init` will error.
2015-10-19 01:23:13 +02:00
2017-04-04 19:48:59 +02:00
* `-lock=true` - Lock the state file when locking is supported.
* `-lock-timeout=0s` - Duration to retry a state lock.
* `-no-color` - If specified, output won't contain any color.
2017-04-20 23:34:14 +02:00
* `-reconfigure` - Reconfigure the backend, ignoring any saved configuration.
2017-04-04 19:48:59 +02:00
2017-03-17 07:32:45 +01:00
## Backend Config
2015-10-19 01:23:13 +02:00
2017-03-17 07:32:45 +01:00
The `-backend-config` can take a path or `key=value` pair to specify additional
2017-04-13 16:07:48 +02:00
backend configuration when [initializing a backend ](/docs/backends/init.html ).
2015-10-19 01:23:13 +02:00
2017-02-15 22:14:32 +01:00
This is particularly useful for
[partial configuration of backends ](/docs/backends/config.html ). Partial
configuration lets you keep sensitive information out of your Terraform
configuration.
2014-12-06 00:29:00 +01:00
2017-03-17 07:32:45 +01:00
For path values, the backend configuration file is a basic HCL file with key/value pairs.
2017-02-15 22:14:32 +01:00
The keys are configuration keys for your backend. You do not need to wrap it
in a `terraform` block. For example, the following file is a valid backend
configuration file for the Consul backend type:
2014-12-06 00:29:00 +01:00
2017-02-15 22:14:32 +01:00
```hcl
address = "demo.consul.io"
path = "newpath"
2015-10-19 01:23:13 +02:00
```
2017-03-17 07:27:05 +01:00
2017-03-17 07:32:45 +01:00
If the value contains an equal sign (`=`), it is parsed as a `key=value` pair.
2017-03-17 07:27:05 +01:00
The format of this flag is identical to the `-var` flag for plan, apply,
etc. but applies to configuration keys for backends. For example:
2017-04-05 17:29:27 +02:00
```shell
2017-03-17 07:27:05 +01:00
$ terraform init \
-backend-config 'address=demo.consul.io' \
-backend-config 'path=newpath'
```
2017-03-17 07:32:45 +01:00
These two formats can be mixed. In this case, the values will be merged by
key with keys specified later in the command-line overriding conflicting
keys specified earlier.