Files
opentf/website/docs/cli/init/index.mdx
Kuba Martin 4d665a0091 Update website/docs/cli. (#171)
* Initial renaming, rewriting and cleaning up wave for the CLI docs.

Signed-off-by: Jakub Martin <kubam@spacelift.io>

* More renaming.

Signed-off-by: Jakub Martin <kubam@spacelift.io>

* More renaming.

Signed-off-by: Jakub Martin <kubam@spacelift.io>

* More renaming.

Signed-off-by: Jakub Martin <kubam@spacelift.io>

* Remove tutorial references.

Signed-off-by: Jakub Martin <kubam@spacelift.io>

* Post-review fixes.

Signed-off-by: Jakub Martin <kubam@spacelift.io>

---------

Signed-off-by: Jakub Martin <kubam@spacelift.io>
2023-08-25 11:09:18 +02:00

75 lines
3.1 KiB
Plaintext

---
page_title: Initializing Working Directories - OpenTF CLI
description: >-
Working directories contain configurations, settings, cached plugins and
modules, and state data. Learn how to initialize and manage working
directories.
---
# Initializing Working Directories
OpenTF expects to be invoked from a working directory that contains
configuration files written in
[the OpenTF language](/opentf/language). OpenTF uses
configuration content from this directory, and also uses the directory to store
settings, cached plugins and modules, and sometimes state data.
A working directory must be initialized before OpenTF can perform any
operations in it (like provisioning infrastructure or modifying state).
## Working Directory Contents
A OpenTF working directory typically contains:
- A OpenTF configuration describing resources OpenTF should manage. This
configuration is expected to change over time.
- A hidden `.terraform` directory, which OpenTF uses to manage cached
provider plugins and modules, record which
[workspace](/opentf/cli/workspaces) is currently active, and
record the last known backend configuration in case it needs to migrate state
on the next run. This directory is automatically managed by OpenTF, and is
created during initialization.
- State data, if the configuration uses the default `local` backend. This is
managed by OpenTF in a `terraform.tfstate` file (if the directory only uses
the default workspace) or a `terraform.tfstate.d` directory (if the directory
uses multiple workspaces).
## Initialization
Run the `opentf init` command to initialize a working directory that contains
a OpenTF configuration. After initialization, you will be able to perform
other commands, like `opentf plan` and `opentf apply`.
If you try to run a command that relies on initialization without first
initializing, the command will fail with an error and explain that you need to
run init.
Initialization performs several tasks to prepare a directory, including
accessing state in the configured backend, downloading and installing provider
plugins, and downloading modules. Under some conditions (usually when changing
from one backend to another), it might ask the user for guidance or
confirmation.
For details, see [the `opentf init` command](/opentf/cli/commands/init).
## Reinitialization
Certain types of changes to a OpenTF configuration can require
reinitialization before normal operations can continue. This includes changes to
provider requirements, module sources or version constraints, and backend
configurations.
You can reinitialize a directory by running `opentf init` again. In fact, you
can reinitialize at any time; the init command is idempotent, and will have no
effect if no changes are required.
If reinitialization is required, any commands that rely on initialization will
fail with an error and tell you so.
## Reinitializing Only Modules
The `opentf get` command will download modules referenced in the
configuration, but will not perform the other required initialization tasks.
This command is only useful for niche workflows, and most OpenTF users can
ignore it in favor of `opentf init`.