Skip to main content
When you create Nebius AI Cloud infrastructure by using a Terraform provider, you declare the desired infrastructure state in .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

  1. Create a bucket to store the state.
    Terraform recommends that you enable versioning for the bucket. However, storing multiple versions of objects in a bucket increases your costs.
  2. Create a service account that accesses the bucket.
  3. Create an access key for this service account and save the AWS-like ID and secret.
  4. Install and configure the Nebius AI Cloud provider for Terraform.

How to store the Terraform state file

  1. Create a working directory on your local machine. If you intend to use version control, store this directory in a repository.
  2. In this directory, create the terraform.tf file with the following contents:
    terraform {
      required_providers {
        nebius = {
          source  = "terraform-provider.storage.eu-north1.nebius.cloud/nebius/nebius"
          version = ">= terraform-provider-nebius.storage.ai.nebius.cloud/nebius/nebius"
        }
      }
    
      backend "s3" {
        bucket  = "<your_bucket_name>"
        key     = "<path_to_store_tfstate>"
        region  = "eu-north1"
    
        access_key = "<AWS-like_key_ID>"
        secret_key = "<AWS-like_key_secret>"
    
        endpoints = {
          s3 = "https://storage.eu-north1.nebius.cloud"
        }
    
        # Lock the state from concurrent modifications
        use_lockfile = true
    
        # These settings stop Terraform from AWS-specific checks
        # that are not relevant for Nebius AI Cloud
        skip_credentials_validation = true
        skip_region_validation      = true
        skip_requesting_account_id  = true
        skip_metadata_api_check     = true
      }
    }
    
    In this file, specify the following parameters:
    • bucket: Bucket name.
    • key: Path where the state should be stored, relative to the bucket root.
    • access_key and secret_key: AWS-like ID and secret to access the bucket.
  3. Prepare the authentication file provider "nebius" {}.
  4. 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.
  5. Initialize Terraform in the working directory:
    terraform init
    
  6. Check that the configuration is correct:
    terraform validate
    
  7. Apply the changes:
    terraform apply
    
Terraform creates the required infrastructure and stores its state in a .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.