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
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
    • Yandex Cloud Partner program
  • Blog
  • Pricing
  • Documentation
© 2025 Direct Cursus Technology L.L.C.
Yandex Compute Cloud
  • Yandex Container Solution
    • All tutorials
    • Configuring time synchronization using NTP
    • Autoscaling an instance group to process messages from a queue
    • Updating an instance group under load
    • Deploying Remote Desktop Gateway
    • Getting started with Packer
    • Transferring logs from a VM to Yandex Cloud Logging
    • Building a VM image with infrastructure tools using Packer
    • Migrating data to Yandex Cloud using Hystax Acura
    • Fault protection with Hystax Acura
    • VM backups using Hystax Acura
    • Deploying a fault-tolerant architecture with preemptible VMs
      • Overview
      • Management console, CLI, and API
      • Terraform
    • Configuring a fault-tolerant architecture in Yandex Cloud
    • Creating a budget trigger that invokes a function to stop a VM
    • Creating triggers that invoke a function to stop a VM and send a Telegram notification
    • Creating a Python web application with Flask
    • Creating an SAP program in Yandex Cloud
    • Deploying a Minecraft server in Yandex Cloud
    • Automating image builds using Jenkins and Packer
    • Creating test VMs via GitLab CI
    • High-performance computing on preemptible VMs
    • Configuring an SFTP server based on CentOS 7
    • Deploying GlusterFS in high availability mode
    • Deploying GlusterFS in high performance mode
    • Backing up to Object Storage with Bacula
    • Building a CI/CD pipeline in GitLab using serverless products
    • Implementing a secure high-availability network infrastructure with a dedicated DMZ based on the Check Point NGFW
    • Cloud infrastructure segmentation with the Check Point next-generation firewall
    • Configuring a secure GRE tunnel over IPsec
    • Creating a bastion host
    • Implementing fault-tolerant scenarios for NAT VMs
    • Creating a tunnel between two subnets using OpenVPN Access Server
    • Creating an external table from a Object Storage bucket table using a configuration file
    • Setting up network connectivity between BareMetal and Virtual Private Cloud subnets
    • Working with snapshots in Managed Service for Kubernetes
    • Launching the DeepSeek-R1 language model in a GPU cluster
    • Running a vLLM library with the Gemma 3 language model on a VM with GPU
  • Access management
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Release notes

In this article:

  • Get your cloud ready
  • Required paid resources
  • Delegate your domain to Cloud DNS
  • Create an infrastructure
  • Test the website
  • Delete the resources you created
  1. Tutorials
  2. Assigning a domain name to a web server VM
  3. Terraform

Assigning a domain name to a web server VM with Terraform

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

To create an infrastructure for assigning a domain name to a web server VM using Terraform:

  1. Get your cloud ready.
  2. Delegate your domain to Cloud DNS.
  3. Create an infrastructure.
  4. 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 support cost includes:

  • Fee for using a public IP address (see Yandex Virtual Private Cloud pricing).
  • Fee for VM computing resources and disks (see Yandex Compute Cloud pricing).
  • Fee for using a public DNS zone and public DNS requests (see Yandex Cloud DNS pricing).

Delegate your domain to Cloud DNSDelegate your domain to Cloud DNS

To delegate a domain to Cloud DNS, in your account on your domain registrar's website, specify the DNS server addresses in the domain settings:

  • ns1.yandexcloud.net
  • ns2.yandexcloud.net

Delegation does not take effect immediately. It usually takes up to 24 hours (86,400 seconds) for internet service providers to update records. This depends on the TTL value which specifies how long domain records are cached.

You can check the domain delegation using Whois or the dig utility:

dig +short NS example.com

Result:

ns2.yandexcloud.net.
ns1.yandexcloud.net.

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 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 the infrastructure description file:

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

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

      • bind-domain-to-vm.tf: Your infrastructure configuration.
      • bind-domain-to-vm.auto.tfvars: User data file.
    1. Create a folder for the infrastructure description file.
    2. In the folder, create:
      1. bind-domain-to-vm.tf configuration file:

        bind-domain-to-vm.tf
        # Declaring variables for custom parameters
        
        variable "folder_id" {
          type = string
        }
        
        variable "domain_name" {
          type = string
        }
        
        variable "ssh_key_path" {
          type = string
        }
        
        # Adding other variables
        
        locals {
          zone             = "ru-central1-a"
          network_name     = "webserver-network"
          subnet_name      = "webserver-subnet-ru-central1-a"
          sg_name          = "webserver-sg"
          vm_name          = "mywebserver"
          domain_zone_name = "my-domain-zone"
        }
        
        # Configuring a provider 
        
        terraform {
          required_providers {
            yandex = {
              source  = "yandex-cloud/yandex"
              version = ">= 0.47.0"
            }
          }
        }
        
        provider "yandex" {
          zone      = local.zone
          folder_id = var.folder_id
        }
        
        # Creating a cloud network
        
        resource "yandex_vpc_network" "webserver-network" {
          name = local.network_name
        }
        
        # Create subnet
        
        resource "yandex_vpc_subnet" "webserver-subnet-b" {
          name           = local.subnet_name
          zone           = local.zone
          network_id     = "${yandex_vpc_network.webserver-network.id}"
          v4_cidr_blocks = ["192.168.1.0/24"]
        }
        
        # Creating a security group
        
        resource "yandex_vpc_security_group" "webserver-sg" {
          name        = local.sg_name
          network_id  = "${yandex_vpc_network.webserver-network.id}"
          ingress {
            protocol       = "TCP"
            description    = "http"
            v4_cidr_blocks = ["0.0.0.0/0"]
            port           = 80
          }
        
          ingress {
            protocol       = "TCP"
            description    = "https"
            v4_cidr_blocks = ["0.0.0.0/0"]
            port           = 443
          }
        
          ingress {
            protocol       = "TCP"
            description    = "ssh"
            v4_cidr_blocks = ["0.0.0.0/0"]
            port           = 22
          }
        
          egress {
            protocol       = "ANY"
            description    = "any"
            v4_cidr_blocks = ["0.0.0.0/0"]
            from_port      = 0
            to_port        = 65535
          }
        }
        
        # Creating an image
        
        resource "yandex_compute_image" "osimage" {
          source_family = "lamp"
        }
        
        # Creating a disk
        
        resource "yandex_compute_disk" "boot-disk" {
          name     = "web-server-boot"
          type     = "network-hdd"
          image_id = yandex_compute_image.osimage.id
        }
        
        # Creating a VM instance
        
        resource "yandex_compute_instance" "mywebserver" {
          name        = local.vm_name
          platform_id = "standard-v2"
          zone        = local.zone
        
          resources {
            cores  = "2"
            memory = "2"
          }
        
          boot_disk {
            disk_id = yandex_compute_disk.boot-disk.id
          }
        
          network_interface {
            subnet_id          = "${yandex_vpc_subnet.webserver-subnet-b.id}"
            nat                = true
            security_group_ids = ["${yandex_vpc_security_group.webserver-sg.id}"]
          }
        
          metadata = {
            user-data = "#cloud-config\nusers:\n  - name: yc-user\n    groups: sudo\n    shell: /bin/bash\n    sudo: 'ALL=(ALL) NOPASSWD:ALL'\n    ssh_authorized_keys:\n      - ${file("${var.ssh_key_path}")}"
          }
        }
        
        # Creating a DNS zone
        
        resource "yandex_dns_zone" "my-domain-zone" {
          name    = local.domain_zone_name
          zone    = "${var.domain_name}."
          public  = true
        }
        
        # Creating a type A resource record
        
        resource "yandex_dns_recordset" "rsA1" {
          zone_id = yandex_dns_zone.my-domain-zone.id
          name    = "${yandex_dns_zone.my-domain-zone.zone}"
          type    = "A"
          ttl     = 600
          data    = ["${yandex_compute_instance.mywebserver.network_interface.0.nat_ip_address}"]
        }
        
      2. bind-domain-to-vm.auto.tfvars user data file:

        bind-domain-to-vm.auto.tfvars
        folder_id    = "<folder_ID>"
        ssh_key_path = "<path_to_SSH_key>"
        domain_name  = "<domain_name>"
        

    For more information about the properties of Terraform resources, see the provider documentation:

    • Network: yandex_vpc_network
    • Subnets: yandex_vpc_subnet
    • Security groups: yandex_vpc_security_group
    • Image: yandex_compute_image
    • Disk: yandex_compute_disk
    • VM: yandex_compute_instance
    • DNS zone: yandex_dns_zone
    • DNS resource record: yandex_dns_recordset
  3. In the bind-domain-to-vm.auto.tfvars file, set the following user-defined properties:

    • folder_id: Folder ID.
    • ssh_key_path: Path to the public SSH key file to authenticate the user on the VM, e.g., ~/.ssh/id_ed25519.pub. For more information, see Creating an SSH key pair.
    • domain_name: Your domain name, e.g., example.com.
  4. Create the 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.

  5. Get the VM public IP address: you will use it later to test the hosting.

After creating the infrastructure, test the website.

Test the websiteTest the website

The website on your web server is now accessible by its domain name. To test the site, enter its IP address or domain name in your browser:

  • http://<VM_public_IP_address>
  • http://example.com

Delete the resources you createdDelete the resources you created

To shut down the hosting and stop paying for the resources you created:

  1. Open the bind-domain-to-vm.tf configuration file and delete your infrastructure description.

  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

  • Assigning a domain name to a web server VM using the management console, CLI, or API

Was the article helpful?

Previous
Management console, CLI, and API
Next
Configuring a fault-tolerant architecture in Yandex Cloud
© 2025 Direct Cursus Technology L.L.C.