Store Terraform states in an Object Storage bucket
This guide describes the steps for uploading a Terraform state to Object Storage.
A Terraform state describes the current deployed infrastructure and is stored in files with the .tfstate
extension. The state file is created after the infrastructure is deployed and can be immediately uploaded to Object Storage. The uploaded state file is updated as the infrastructure you created changes.
-
Create a bucket with restricted access. It stores the Terraform state file.
-
Add the obtained key ID and secret key to environment variables:
BashPowerShellexport ACCESS_KEY="<key_ID>" export SECRET_KEY="<secret_key>"
$Env:ACCESS_KEY="<key_ID>" $Env:SECRET_KEY="<secret_key>"
-
Add provider and backend settings to the configuration file:
terraform { nebius = { source = "terraform-registry.storage.ai.nebius.cloud/nebius/nebius" version = ">= 0.6.0" # Optional } } backend "s3" { endpoint = "storage.ai.nebius.cloud" bucket = "<bucket_name>" region = "eu-north1" key = "<path_to_state_file_in_bucket>/<state_file_name>.tfstate" skip_region_validation = true skip_credentials_validation = true } } provider "nebius" { endpoint = "api.ai.nebius.cloud:443" storage_endpoint = "storage.ai.nebius.cloud" token = "<service_account_static_key>" cloud_id = "<cloud_ID>" folder_id = "<folder_ID>" zone = "<default_availability_zone>" }
To read more about the state storage backend, see the Terraform documentation
. -
Run the following command in the folder with the configuration file:
terraform init -backend-config="access_key=$ACCESS_KEY" -backend-config="secret_key=$SECRET_KEY"
-
Create or update your resources using Terraform.
Check the saved state
Make sure that the state file is uploaded to Object Storage:
- Open the management console
and select the folder with the bucket created. - Select Object Storage.
- In the bucket list, select the bucket you saved the Terraform state to.
- Make sure the state file is in the bucket.