Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ pubDate: 2023-01-01
modDate: 2023-01-01
title: Terraform step configuration with Octopus
navTitle: Terraform step configuration
description: Configuring common Terraform options using the Octopus built in steps
description: Configuring common Terraform options using the Octopus built in steps
navOrder: 20
---

Octopus provides four built-in step templates for managing and interacting with your Terraform code:
Octopus provides four built-in step templates for managing and interacting with your Terraform code:

- `Apply a Terraform template`
- `Destroy Terraform resources`
- `Plan to apply a Terraform template`
- `Plan to apply a Terraform template`
- `Plan a Terraform destroy`

:::figure
Expand All @@ -26,15 +27,16 @@ While these are the options common to each step, there are additional ways to in

## Managed Accounts

You can optionally prepare the environment that Terraform runs in using the details defined in accounts managed by Octopus. If an account is selected then those credentials do not need to be included in the Terraform template.
You can optionally prepare the environment that Terraform runs in using the details defined in [accounts](/docs/infrastructure/accounts) managed by Octopus. If an account is selected then those credentials do not need to be included in the Terraform template.

:::div{.hint}
Using credentials managed by Octopus is optional, and credentials defined in the Terraform template take precedence over any credentials defined in the step. You can learn more about creating managed cloud accounts using Octopus [here](/docs/infrastructure/accounts).
Using credentials managed by Octopus is optional, and credentials defined in the Terraform template take precedence over any credentials defined in the step.
:::

## Template section
## Template section

The Terraform template can come from three sources:

- Directly entered source code
- Files in a package
- Files in a Git repository - *New!*
Expand Down Expand Up @@ -100,17 +102,17 @@ If you are storing your project configuration directly in Octopus (i.e. not in a
- URL
- Credentials (either anonymous or selecting a Git credential from the Library)

When creating a Release, you choose the tip of a branch for your files. The commit hash for this branch is saved to the Release. This means redeploying that release will only ever use that specific commit and not the _new_ tip of the branch.
When creating a Release, you choose the tip of a branch for your files. The commit hash for this branch is saved to the Release. This means redeploying that release will only ever use that specific commit and not the *new* tip of the branch.

#### Version-controlled projects

If you are storing your project configuration in a Git repository using the [Configuration as code feature](/docs/projects/version-control), in addition to the option above, you can source your files from the same Git repository as your deployment process by selecting **Project** as the Git repository source. When creating a Release using this option, the commit hash used for your deployment process will also be used to source the files.

### Variable replacements

Variable replacement is performed before the template is applied or destroyed when defined in either an inline script or a package.
Variable replacement is performed before terraform is executed.

When deploying a template from a package, all `*.tf`, `*.tfvar`, `*.tf.json` and `*.tfvar.json` files will have variable substitution applied to them. You can also have variable substitution applied to additional files by defining the file names in the `Target files` field.
When deploying a template from a package or Git repository, all `*.tf`, `*.tfvar`, `*.tf.json` and `*.tfvar.json` files will have variable substitution applied to them by default. You can disable the automatic substitution by deselecting `Replace variables in default Terraform files`. You can also have variable substitution applied to additional files by defining file names in the `Target files` field.

For example, if you were deploying from a package and your template file looked like this:

Expand All @@ -136,4 +138,4 @@ See the [variable substitution](/docs/projects/variables/variable-substitutions)

The `Additional variable files` option contains a new-line separated list of variable files to use with the deployment. All files called `terraform.tfvars`, `terraform.tfvars.json`, `*.auto.tfvars` and `*.auto.tfvars.json` are automatically loaded by Terraform, and do not need to be listed here. However, you may want to reference environment specific variable files by referencing them with files names built around variable substitution such as `#{Octopus.Environment.Name}.tfvars`.

Each line entered into this field will be passed to Terraform as `-var-file '<filename>'`.
Each line entered into this field will be passed to Terraform as `-var-file '<filename>'`.
Loading