.tf files. Next, Terraform applies the changes and stores the current infrastructure state in a .tfstate file.
For shared environments or automated workflows, it is a good practice to store the .tf files under version control (for example, in a Git repository) and to store the .tfstate files in S3-compatible storage. As a result, several users or automation systems can access and update the same infrastructure state safely. Also, you can lock the state to prevent conflicting changes.
In Nebius AI Cloud, you can store the .tfstate file in an Object Storage bucket. The Terraform state is uploaded to the bucket and is updated automatically every time you make changes in your resources in configuration files.
Prerequisites
- Create a bucket to store the state.
- Create a service account that accesses the bucket.
- Create an access key for this service account and save the AWS-like ID and secret.
- Install and configure the Nebius AI Cloud provider for Terraform.
How to store the Terraform state file
- Create a working directory on your local machine. If you intend to use version control, store this directory in a repository.
-
In this directory, create the
terraform.tffile with the following contents:In this file, specify the following parameters:bucket: Bucket name.key: Path where the state should be stored, relative to the bucket root.access_keyandsecret_key: AWS-like ID and secret to access the bucket.
-
Prepare the authentication file
provider "nebius" {}. - Create configuration files for the infrastructure that you need to deploy. To get acquainted with an example of such infrastructure and files, see Getting started with the Terraform provider by Nebius AI Cloud.
-
Initialize Terraform in the working directory:
-
Check that the configuration is correct:
-
Apply the changes:
.tfstate file that is placed in the bucket you specified.
After that, when you want to update the infrastructure and change its configuration files, use the same terraform.tf file. When you run terraform apply, Terraform pulls the latest remote state from the bucket and shows the plan of the changes.