Skip to content

Commit

Permalink
[Updated] Terraform guides with steps for storing state on OBJ (#7091)
Browse files Browse the repository at this point in the history
* [Updated] Terraform guides with steps for storing state on OBJ

* edit to config file code

* copy edit and code block fix
  • Loading branch information
jddocs authored Sep 9, 2024
1 parent 523412f commit 4cd3964
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: 'This article gives you step-by-step instructions on how to use Ter
authors: ["Damaso Sanoja"]
contributors: ["Damaso Sanoja"]
published: 2017-11-06
modified: 2023-07-26
modified: 2024-08-26
keywords: ["terraform", "infrastructure", "IaC"]
license: '[CC BY-ND 4.0](https://creativecommons.org/licenses/by-nd/4.0)'
aliases: ['/applications/configuration-management/terraform/how-to-build-your-infrastructure-using-terraform-and-linode/','/applications/configuration-management/how-to-build-your-infrastructure-using-terraform-and-linode/','/platform/how-to-build-your-infrastructure-using-terraform-and-linode/']
Expand Down Expand Up @@ -676,4 +676,30 @@ Create a deployment for an imaginary client:
terraform init
terraform plan
terraform apply
```
```

### Use Linode Object Storage to Store State

[State](https://developer.hashicorp.com/terraform/language/state) data files are stored on a [backend](https://developer.hashicorp.com/terraform/language/settings/backends/configuration) by Terraform to log and track metadata, map resources to a configuration, and improve performance. By default, state is stored locally in the `terraform.tfstate` file.

Using the configuration below with the `backend` block, you can set up Terraform to use Linode Object Storage to store state remotely. The `backend` block should be nested within the `terraform` block as noted in [Hashicorp's official backend documentation](https://developer.hashicorp.com/terraform/language/settings/backends/s3). In this guide, the `terraform` block is located in the `main.tf` configuration file.
Note that this module assumes an object storage bucket already exists on your account. Replace values with your bucket and key information:
```file {title="obj-backend.tf"}
# Backend Configuration
backend "s3" {
bucket = "{{< placeholder "YOUR-BUCKET-NAME" >}}" # The bucket name created on your account to which your access_key and secret_key can read and write
key = "{{< placeholder "tf/tfstate" >}}" # The folder ({{< placeholder "tf" >}}) and object ({{< placeholder "tfstate" >}}) in your bucket where you want to write state to
region = "{{< placeholder "us-southeast-1" >}}" # The region where your object storage bucket is at which is the same as the ClusterID Here https://techdocs.akamai.com/cloud-computing/docs/access-buckets-and-files-through-urls#cluster-url-s3-endpoint
access_key = "{{< placeholder "OBJ-ACCESS-KEY" >}}" # You can put your value here inline or add it as an environment variable AWS_ACCESS_KEY_ID see more here https://developer.hashicorp.com/terraform/language/settings/backends/s3#credentials-and-shared-configuration
secret_key = "{{< placeholder "OBJ-SECRET-KEY" >}}" # You can put your value here inline or add it as an environment variable AWS_SECRET_ACCESS_KEY see more here https://developer.hashicorp.com/terraform/language/settings/backends/s3#credentials-and-shared-configuration
skip_region_validation = true # All of these skip_* arguements are used since our object storage doesn't implement these additional endpoints
skip_credentials_validation = true
skip_requesting_account_id = true
skip_s3_checksum = true
endpoints = {
s3 = "{{< placeholder "https://us-southeast-1.linodeobjects.com" >}}" # The endpoint for the s3 API based on the region your bucket is located https://techdocs.akamai.com/cloud-computing/docs/access-buckets-and-files-through-urls#cluster-url-s3-endpoint
}
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: 'This guide provides a brief introduction to Terraform, and explain
authors: ["Jeff Novotny"]
contributors: ["Jeff Novotny"]
published: 2022-10-25
modified: 2022-11-28
modified: 2024-08-26
keywords: ['Linode Terraform','Terraform Linode Object Storage','Install Terraform']
license: '[CC BY-ND 4.0](https://creativecommons.org/licenses/by-nd/4.0)'
external_resources:
Expand Down Expand Up @@ -465,6 +465,12 @@ terraform plan
terraform apply
```

## Configure Terraform to Store State on Linode Object Storage

Terraform uses [state](https://developer.hashicorp.com/terraform/language/state) on a [backend](https://developer.hashicorp.com/terraform/language/settings/backends/configuration) to log and track resource information. By default, state is stored locally in a file named `terraform.tfstate`.

For steps on how to use Linode Object Storage as a remote backend to store state, see our guide [Use Terraform to Provision Infrastructure on Linode](/docs/guides/how-to-build-your-infrastructure-using-terraform-and-linode/#use-linode-object-storage-to-store-state).

## Conclusion

Terraform is a powerful and efficient *Infrastructure as Code* (IaC) application. It automates the process of deploying infrastructure. To use Terraform, use the HCL or JSON formats to describe the final state of the network. Use the `terraform plan` command from the Terraform client to preview the changes and `terraform apply` to deploy the configuration.
Expand Down

0 comments on commit 4cd3964

Please sign in to comment.