Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
  • Blog
  • Pricing
  • Documentation
Yandex project
© 2025 Yandex.Cloud LLC
Yandex Object Storage
    • All tutorials
    • Getting statistics on object queries with S3 Select
    • Getting website traffic statistics with S3 Select
    • Getting statistics on object queries using Yandex Query
    • Generating a resource-by-resource cost breakdown report using S3 Select
    • Server-side encryption
    • Integrating an L7 load balancer with CDN and Object Storage
    • Blue-green and canary deployment of service versions
    • Analyzing logs in DataLens
    • Mounting buckets to the file system of Yandex Data Processing hosts
    • Using Object Storage in Yandex Data Processing
    • Importing data from Object Storage, processing and exporting to Managed Service for ClickHouse®
    • Mounting a bucket as a disk in Windows
    • Migrating data from Yandex Data Streams using Yandex Data Transfer
    • Using hybrid storage in Yandex Managed Service for ClickHouse®
    • Loading data from Yandex Managed Service for OpenSearch to Yandex Object Storage using Yandex Data Transfer
    • Automatically copying objects from one bucket to another
    • Recognizing audio files in a bucket on a regular basis
    • Training a model in Yandex DataSphere on data from Object Storage
    • Connecting to Object Storage from VPC
    • Migrating data to Yandex Managed Service for PostgreSQL using Yandex Data Transfer
    • Uploading data to Yandex Managed Service for Greenplum® using Yandex Data Transfer
    • Uploading data to Yandex Managed Service for ClickHouse® using Yandex Data Transfer
    • Uploading data to Yandex Managed Service for YDB using Yandex Data Transfer
    • Exchanging data between Yandex Managed Service for ClickHouse® and Yandex Data Processing
    • Uploading data from Yandex Managed Service for YDB using Yandex Data Transfer
    • Hosting a static Gatsby website in Object Storage
    • Migrating a database from Managed Service for PostgreSQL to Object Storage
    • Exchanging data between Yandex Managed Service for ClickHouse® and Yandex Data Processing
    • Importing data from Yandex Managed Service for PostgreSQL to Yandex Data Processing using Sqoop
    • Importing data from Yandex Managed Service for MySQL® to Yandex Data Processing using Sqoop
    • Migrating data from Yandex Object Storage to Yandex Managed Service for MySQL® using Yandex Data Transfer
    • Migrating a database from Yandex Managed Service for MySQL® to Yandex Object Storage
    • Exporting Greenplum® data to a cold storage in Yandex Object Storage
    • Loading data from Yandex Direct to a Yandex Managed Service for ClickHouse® data mart using Yandex Cloud Functions, Yandex Object Storage, and Yandex Data Transfer
    • Migrating data from Elasticsearch to Yandex Managed Service for OpenSearch
    • Uploading Terraform states to Object Storage
    • Locking Terraform states using Managed Service for YDB
      • Overview
      • Management console
      • Terraform
    • Visualizing Yandex Query data
    • Publishing game updates
    • VM backups using Hystax Acura
    • Backing up to Object Storage with CloudBerry Desktop Backup
    • Backing up to Object Storage with Duplicati
    • Backing up to Object Storage with Bacula
    • Backing up to Yandex Object Storage with Veeam Backup
    • Backing up to Object Storage with Veritas Backup Exec
    • Managed Service for Kubernetes cluster backups in Object Storage
    • Developing a custom integration in API Gateway
    • URL shortener
    • Storing application runtime logs
    • Developing a skill for Alice and a website with authorization
    • Creating an interactive serverless application using WebSocket
    • Deploying a web application using the Java Servlet API
    • Developing a Telegram bot
    • Replicating logs to Object Storage using Fluent Bit
    • Replicating logs to Object Storage using Data Streams
    • Uploading audit logs to ArcSight SIEM
    • Exporting audit logs to SIEM Splunk systems
    • Creating an MLFlow server for logging experiments and artifacts
    • Operations with data using Yandex Query
    • Federated data queries using Query
    • Recognizing text in image archives using Vision OCR
    • Converting a video to a GIF in Python
    • Automating tasks using Managed Service for Apache Airflow™
    • Processing files with usage details in Yandex Cloud Billing
    • Deploying a web app with JWT authorization in API Gateway and authentication in Firebase
    • Searching for Yandex Cloud events in Yandex Query
    • Searching for Yandex Cloud events in Object Storage
    • Creating an external table from a bucket table using a configuration file
    • Migrating databases from Google BigQuery to Managed Service for ClickHouse®
  • Pricing policy
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Bucket logs
  • Release notes
  • FAQ

In this article:

  • Get your cloud ready
  • Required paid resources
  • Create an infrastructure
  • Test the website
  • How to delete the resources you created
  1. Tutorials
  2. Static website in Yandex Object Storage
  3. Terraform

Static website in Yandex Object Storage using Terraform

Written by
Yandex Cloud
Updated at May 7, 2025
  • Get your cloud ready
    • Required paid resources
  • Create an infrastructure
  • Test the website
  • How to delete the resources you created

To host a static website in Object Storage using Terraform:

  1. Get your cloud ready.
  2. Create an infrastructure.
  3. Test the website.

If you no longer need the resources you created, delete them.

Get your cloud readyGet your cloud ready

Sign up in Yandex Cloud and create a billing account:

  1. Navigate to the management console and log in to Yandex Cloud or register a new account.
  2. On the Yandex Cloud Billing page, make sure you have a billing account linked and it has the ACTIVE or TRIAL_ACTIVE status. If you do not have a billing account, create one and link a cloud to it.

If you have an active billing account, you can navigate to the cloud page to create or select a folder for your infrastructure to operate in.

Learn more about clouds and folders.

Required paid resourcesRequired paid resources

The cost of hosting a static website includes:

  • Fee for storing data for a static website (see Object Storage pricing).
  • Fee for data operations (see Object Storage pricing).
  • Fee for outgoing traffic from Yandex Cloud to the internet (see Object Storage pricing).
  • Fee for public DNS queries and zones (see Yandex Cloud DNS pricing).

Create an infrastructureCreate an infrastructure

With Terraform, you can quickly create a cloud infrastructure in Yandex Cloud and manage it using configuration files. These files store the infrastructure description written in HashiCorp Configuration Language (HCL). If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.

Terraform is distributed under the Business Source License. The Yandex Cloud provider for Terraform is distributed under the MPL-2.0 license.

For more information about the provider resources, see the documentation on the Terraform website or mirror website.

To create an infrastructure for a static website in Object Storage using Terraform:

  1. Install Terraform, get the authentication credentials, and specify the source for installing the Yandex Cloud provider (see Configure a provider, Step 1).

  2. Prepare your infrastructure description files:

    Ready-made configuration
    Manually
    1. Clone the repository with configuration files.

      git clone https://github.com/yandex-cloud-examples/yc-s3-static-website.git
      
    2. Navigate to the repository directory. Make sure it contains the following files:

      • static.tf: New infrastructure configuration.
      • index.html and error.html: Website's main page and error page.
    1. Create a folder for configuration files.
    2. In the folder, create:
      1. static.tf configuration file:

        static.tf
        locals {
          folder_id = "<folder_ID>"
          domain    = "<domain>"
        }
        
        terraform {
          required_providers {
            yandex = {
              source  = "yandex-cloud/yandex"
              version = ">= 0.47.0"
            }
          }
        }
        
        provider "yandex" {
          folder_id = local.folder_id
        }
        
        resource "yandex_iam_service_account" "sa" {
          name      = "my-sa"
        }
        
        resource "yandex_resourcemanager_folder_iam_member" "sa-editor" {
          folder_id = local.folder_id
          role      = "storage.editor"
          member    = "serviceAccount:${yandex_iam_service_account.sa.id}"
        }
        
        resource "yandex_iam_service_account_static_access_key" "sa-static-key" {
          service_account_id = yandex_iam_service_account.sa.id
          description        = "static access key for object storage"
        }
        
        resource "yandex_storage_bucket" "test" {
          access_key = yandex_iam_service_account_static_access_key.sa-static-key.access_key
          secret_key = yandex_iam_service_account_static_access_key.sa-static-key.secret_key
          bucket     = local.domain
          max_size   = 1073741824  
          acl        = "public-read"
          
          website {
            index_document = "index.html"
            error_document = "error.html"
          }
        
          # Certificate Manager certificate
          https {
            certificate_id = data.yandex_cm_certificate.example.id
          }
        }
        
        resource "yandex_cm_certificate" "le-certificate" {
          name    = "my-le-cert"
          domains = ["${local.domain}"]
        
          managed {
          challenge_type = "DNS_CNAME"
          }
        }
        
        resource "yandex_dns_recordset" "validation-record" {
          zone_id = yandex_dns_zone.zone1.id
          name    = yandex_cm_certificate.le-certificate.challenges[0].dns_name
          type    = yandex_cm_certificate.le-certificate.challenges[0].dns_type
          data    = [yandex_cm_certificate.le-certificate.challenges[0].dns_value]
          ttl     = 600
        }
        
        data "yandex_cm_certificate" "example" {
          depends_on      = [yandex_dns_recordset.validation-record]
          certificate_id  = yandex_cm_certificate.le-certificate.id
          #wait_validation = true
        }
        
        resource "yandex_storage_object" "index-html" {
          access_key = yandex_iam_service_account_static_access_key.sa-static-key.access_key
          secret_key = yandex_iam_service_account_static_access_key.sa-static-key.secret_key
          bucket     = yandex_storage_bucket.test.id
          key        = "index.html"
          source     = "index.html"
        }
        
        resource "yandex_storage_object" "error-html" {
          access_key = yandex_iam_service_account_static_access_key.sa-static-key.access_key
          secret_key = yandex_iam_service_account_static_access_key.sa-static-key.secret_key
          bucket     = yandex_storage_bucket.test.id
          key        = "error.html"
          source     = "error.html"
        }
        
        resource "yandex_dns_zone" "zone1" {
          name        = "example-zone-1"
          description = "Public zone"
          zone        = "${local.domain}."
          public      = true
        }
        
        resource "yandex_dns_recordset" "rs2" {
          zone_id = yandex_dns_zone.zone1.id
          name    = "${local.domain}."
          type    = "ANAME"
          ttl     = 600
          data    = ["${local.domain}.website.yandexcloud.net"]
        }
        
      2. index.html file containing the text Hello world!:

        index.html
        <!doctype html>
        <html>
          <head>
            <title>Hello, world!</title>
          </head>
          <body>
            <p>Hello, world!</p>
          </body>
        </html>
        
      3. error.html file containing the text Error!:

        error.html
        <!doctype html>
        <html>
          <head>
            <title>Error!</title>
          </head>
          <body>
            <p>Error!</p>
          </body>
        </html>
        

    Learn more about the properties of Terraform resources in the provider documentation:

    • Service account: yandex_iam_service_account.
    • Role: yandex_resourcemanager_folder_iam_member.
    • Static access key: yandex_iam_service_account_static_access_key.
    • Bucket: yandex_storage_bucket.
    • DNS zone: yandex_dns_zone.
    • DNS resource record: yandex_dns_recordset.
  3. Under locals in the static.tf file, set the following user-defined properties:

    • folder_id: ID of the folder to create the resources in.
    • domain: Domain name in example.com format, without a trailing dot.
  4. Create resources:

    1. In the terminal, change to the folder where you edited the configuration file.

    2. Make sure the configuration file is correct using the command:

      terraform validate
      

      If the configuration is correct, the following message is returned:

      Success! The configuration is valid.
      
    3. Run the command:

      terraform plan
      

      The terminal will display a list of resources with parameters. No changes are made at this step. If the configuration contains errors, Terraform will point them out.

    4. Apply the configuration changes:

      terraform apply
      
    5. Confirm the changes: type yes in the terminal and press Enter.

After creating the infrastructure, test the website.

Test the websiteTest the website

To check that the website is running, use one of the standard Object Storage addresses:

  • http://<bucket_name>.website.yandexcloud.net
  • http://website.yandexcloud.net/<bucket_name>

If you have configured your own domain for a website, use its address, e.g., example.com.

How to delete the resources you createdHow to delete the resources you created

To stop paying for the resources you created:

  1. Open the static.tf configuration file and delete the description of the new infrastructure from it.

  2. Apply the changes:

    1. In the terminal, change to the folder where you edited the configuration file.

    2. Make sure the configuration file is correct using the command:

      terraform validate
      

      If the configuration is correct, the following message is returned:

      Success! The configuration is valid.
      
    3. Run the command:

      terraform plan
      

      The terminal will display a list of resources with parameters. No changes are made at this step. If the configuration contains errors, Terraform will point them out.

    4. Apply the configuration changes:

      terraform apply
      
    5. Confirm the changes: type yes in the terminal and press Enter.

See alsoSee also

  • Static website in Yandex Object Storage using the management console

Was the article helpful?

Previous
Management console
Next
Visualizing Yandex Query data
Yandex project
© 2025 Yandex.Cloud LLC