OpenTofu Language Documentation
This is the documentation for OpenTofu's configuration language. It is relevant to users of OpenTofu CLI, and TACOS (TF Automation and Collaboration Software). OpenTofu's language is its primary user interface. Configuration files you write in OpenTofu language tell OpenTofu what plugins to install, what infrastructure to create, and what data to fetch. OpenTofu language also lets you define dependencies between resources and create multiple similar resources from a single configuration block.
About the OpenTofu Language
The main purpose of the OpenTofu language is declaring resources, which represent infrastructure objects. All other language features exist only to make the definition of resources more flexible and convenient.
An OpenTofu configuration is a complete document in the OpenTofu language that tells OpenTofu how to manage a given collection of infrastructure. A configuration can consist of multiple files and directories.
The syntax of the OpenTofu language consists of only a few basic elements:
- Blocks are containers for other content and usually represent the configuration of some kind of object, like a resource. Blocks have a block type, can have zero or more labels, and have a body that contains any number of arguments and nested blocks. Most of OpenTofu's features are controlled by top-level blocks in a configuration file.
- Arguments assign a value to a name. They appear within blocks.
- Expressions represent a value, either literally or by referencing and combining other values. They appear as values for arguments, or within other expressions.
The OpenTofu language is declarative, describing an intended goal rather than the steps to reach that goal. The ordering of blocks and the files they are organized into are generally not significant; OpenTofu only considers implicit and explicit relationships between resources when determining an order of operations.
Example
The following example describes a simple network topology for Amazon Web Services, just to give a sense of the overall structure and syntax of the OpenTofu language. Similar configurations can be created for other virtual network services, using resource types defined by other providers, and a practical network configuration will often contain additional elements not shown here.