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.
Tutorials
    • All tutorials
      • Transferring a WordPress website from a different hosting provider to Yandex Cloud
        • Overview
        • Management console
        • Terraform
      • Setting up virtual hosting
      • Creating a Python web application with Flask
      • Hosting a static Gatsby website
      • Migrating to Cloud CDN from a third-party CDN provider
      • Getting website traffic statistics with S3 Select

In this article:

  • Get your cloud ready
  • Required paid resources
  • Create an infrastructure
  • Configure OpenCart
  • Delete the resources you created
  1. Application solutions
  2. Creating a website
  3. OpenCart online store
  4. Terraform

Creating an OpenCart online store using Terraform

Written by
Yandex Cloud
Updated at May 7, 2025
  • Get your cloud ready
    • Required paid resources
  • Create an infrastructure
  • Configure OpenCart
  • Delete the resources you created

To create an OpenCart online store using Terraform:

  1. Get your cloud ready.
  2. Create an infrastructure.
  3. Configure OpenCart.

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

Get 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 resources

The cost of supporting an OpenCart online store infrastructure includes:

  • Fee for a continuously running VM (see Yandex Compute Cloud pricing).
  • Fee for using a dynamic or static public IP address (see Yandex Virtual Private Cloud pricing).
  • Fee for a DB cluster if using MySQL® (see Managed Service for MySQL® pricing).

Create 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 set up your OpenCart online store with 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
    Creating files manually
    1. Clone the repository with configuration files:

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

      • opencart.tf: New infrastructure configuration.
      • opencart.auto.tfvars: User data file.
    1. Create a configuration file folder.

    2. In the folder, create:

      1. opencart.tf: New infrastructure configuration file:

        opencart.tf
        # Declaring variables for confidential parameters
        
        variable "folder_id" {
          type = string
        }
        
        variable "vm_user" {
          type = string
        }
        
        variable "ssh_key_path" {
          type = string
        }
        
        variable "db_user" {
          type = string
        }
        
        variable "db_password" {
          type      = string
          sensitive = true
        }
        
        # Adding other variables
        
        locals {
          network_name = "network-1"
          subnet_name1 = "subnet-1"
          subnet_name2 = "subnet-2"
          sg_db_name   = "opencart-sg"
          sg_vm_name   = "opencart-sg-vm"
          vm_name      = "opencart"
          cluster_name = "opencart"
          db_name      = "db1"
        }
        
        # Configuring a provider
        
        terraform {
          required_providers {
            yandex = {
              source  = "yandex-cloud/yandex"
              version = ">= 0.47.0"
            }
          }
        }
        
        provider "yandex" {
          folder_id = var.folder_id
        }
        
        # Creating a cloud network
        
        resource "yandex_vpc_network" "network-1" {
          name = local.network_name
        }
        
        # Creating subnets
        
        resource "yandex_vpc_subnet" "subnet-1" {
          name           = local.subnet_name1
          zone           = "ru-central1-a"
          network_id     = yandex_vpc_network.network-1.id
          v4_cidr_blocks = ["192.168.1.0/24"]
        }
        
        resource "yandex_vpc_subnet" "subnet-2" {
          name           = local.subnet_name2
          zone           = "ru-central1-b"
          network_id     = yandex_vpc_network.network-1.id
          v4_cidr_blocks = ["192.168.2.0/24"]
        }
        
        # Creating security groups
        
        resource "yandex_vpc_security_group" "opencart-sg" {
          name       = local.sg_db_name
          network_id = yandex_vpc_network.network-1.id
        
          egress {
            protocol       = "ANY"
            description    = "any"
            v4_cidr_blocks = ["0.0.0.0/0"]
          }
        
          ingress {
            protocol       = "TCP"
            description    = "ext-https"
            v4_cidr_blocks = ["0.0.0.0/0"]
            port           = 3306
          }
        }
        
        resource "yandex_vpc_security_group" "opencart-sg-vm" {
          name       = local.sg_vm_name
          network_id = yandex_vpc_network.network-1.id
        
          egress {
            protocol       = "ANY"
            description    = "any"
            v4_cidr_blocks = ["0.0.0.0/0"]
            from_port      = 0
            to_port        = 65535
          }
        
          ingress {
            description    = "HTTP"
            protocol       = "TCP"
            v4_cidr_blocks = ["0.0.0.0/0"]
            port           = 80
          }
        
          ingress {
            protocol       = "TCP"
            description    = "ssh"
            v4_cidr_blocks = ["0.0.0.0/0"]
            port           = 22
          }
        
          ingress {
            protocol       = "TCP"
            description    = "ext-https"
            v4_cidr_blocks = ["0.0.0.0/0"]
            port           = 443
          }
        }
        
        # Specifying a prebuilt VM image
        
        resource "yandex_compute_image" "opencart-image" {
          source_family = "opencart"
        }
        
        # Creating a VM instance
        
        resource "yandex_compute_instance" "opencart" {
          name        = "opencart"
          platform_id = "standard-v3"
          zone        = "ru-central1-a"
        
          resources {
            core_fraction = 20
            cores         = 2
            memory        = 4
          }
        
          boot_disk {
            initialize_params {
              image_id = yandex_compute_image.opencart-image.id
              type     = "network-ssd"
              size     = "13"
            }
          }
        
          network_interface {
            subnet_id          = yandex_vpc_subnet.subnet-1.id
            security_group_ids = [yandex_vpc_security_group.opencart-sg-vm.id]
            nat                = true
          }
        
          metadata = {
            user-data = "#cloud-config\nusers:\n  - name: ${var.vm_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 cluster MySQL®
        # If you do not need a cluster, delete the code block creating the MySQL® cluster, database, and user
        
        resource "yandex_mdb_mysql_cluster" "opencart-mysql" {
          name               = local.cluster_name
          environment        = "PRODUCTION"
          network_id         = yandex_vpc_network.network-1.id
          version            = "8.0"
          security_group_ids = [yandex_vpc_security_group.opencart-sg.id]
        
          resources {
            resource_preset_id = "s2.micro"
            disk_type_id       = "network-ssd"
            disk_size          = "10"
          }
        
          host {
            zone             = "ru-central1-a"
            subnet_id        = yandex_vpc_subnet.subnet-1.id
            assign_public_ip = false
          }
        
          host {
            zone             = "ru-central1-b"
            subnet_id        = yandex_vpc_subnet.subnet-2.id
            assign_public_ip = false
          }
        }
        
        # Creating a database for MySQL®
        
        
        resource "yandex_mdb_mysql_database" "db1" {
          cluster_id = yandex_mdb_mysql_cluster.opencart-mysql.id
          name       = local.db_name
        }
        
        # Creating a user for MySQL®
        
        resource "yandex_mdb_mysql_user" "user1" {
          cluster_id = yandex_mdb_mysql_cluster.opencart-mysql.id
          name       = var.db_user
          password   = var.db_password
          permission {
            database_name = yandex_mdb_mysql_database.db1.name
            roles         = ["ALL"]
          }
        }
        
      2. opencart.auto.tfvars: User data file:

        opencart.auto.tfvars
        folder_id    = "<folder_ID>"
        vm_user      = "<VM_user_name>"
        ssh_key_path = "<path_to_public_SSH_key>"
        db_user      = "<DB_user_name>"
        db_password  = "<DB_password>"
        

    For more information about the properties of Terraform resources, see these Terraform guides:

    • Network: yandex_vpc_network
    • Subnets: yandex_vpc_subnet
    • Security groups: yandex_vpc_security_group
    • VM image: yandex_compute_image
    • VM instance: yandex_compute_instance
    • MySQL® cluster: yandex_mdb_mysql_cluster
    • DB MySQL®: yandex_mdb_mysql_database
    • User MySQL®: yandex_mdb_mysql_user
  3. In the opencart.auto.tfvars file, set the following user-defined properties:

    • folder_id: Folder ID.
    • vm_user: VM username.
    • ssh_key_path: Path to the public SSH key that is required to authenticate the user on the VM. For more information, see Creating an SSH key pair.
    • db_user: DB username, e.g., user1.
    • db_password: DB password (8 to 128 characters).
  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 public IP address of the VM: you will need it later to configure OpenCart.

Once you created the infrastructure, configure OpenCart.

Configure OpenCart

  1. Open the web interface of the OpenCart online store. In the browser, open http://<VM_public_IP_address>/. The OpenCart settings page opens.

  2. Read the license and click Continue.

    Step 1

  3. Make sure that all lines with system requirements are marked with green ticks and click Continue.

    Step 2

  4. Set up access to the DB:

    Local server MySQL®
    Cluster Managed Service for MySQL®

    DB connection attributes are generated in a special file when a VM is created:

    1. Log in to the created VM via SSH.

    2. Switch to sudo -i administration mode.

    3. Open default_passwords.txt in the admin's home directory:

      root@opencart:~# cat default_passwords.txt
      MYSQL_USER=opencart
      MYSQL_PASS=qDbvN1R6tA6ET
      MYSQL_ROOT_PASS=5DiVb80l1kXVz
      MYSQL_DB=opencart
      
    4. On the OpenCart setup page, in the DB section, enter the relevant data:

      • Username: MYSQL_USER variable value.
      • Database: MYSQL_DB variable value.
      • Password: MYSQL_PASS variable value.

      Leave the other fields unchanged.

    If you are using a Managed Service for MySQL® cluster, enter the required cluster attributes:

    • Hostname: Enter the fully qualified domain name (FQDN) of the created DB. To find out this name:
      1. Open the folder page in the management console in a new browser tab.
      2. Go to the Managed Service for MySQL® section.
      3. Select the cluster you created in the table.
      4. Select the Hosts tab in the left menu.
      5. Hover over the Hostname field (for example, rc1c-vok617m35g3dj23i) and copy the database's FQDN by clicking .
    • Username: Username (user1 in the example).
    • Database: DB name (db1 in the example).
    • Password: User password you specified.

    Leave the other fields unchanged.

  5. Enter the administrator's name, password, and current email address. Then click Continue.

    Step 3

  6. A page will open to notify you that system configuration is complete. To configure the online store, click Login to your administration and enter your admin username and password.

    Step 4

  7. When the installation is complete, log in to the VM via SSH and delete the installation files you no longer need:

    user@opencart:~$ sudo -i
    root@opencart:~# rm -rf /var/www/opencart/install/
    
  8. To test the home page, go to http://<VM_public_IP_address>/. You will see your website home page the way your online store visitors will see it.

    Step 5

Delete the resources you created

How to delete the resources you created:

  1. Open the opencart.tf configuration file and delete your infrastructure description 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 also

  • Creating an OpenCart online store using the management console.

Was the article helpful?

Previous
Management console
Next
Setting up virtual hosting
© 2025 Direct Cursus Technology L.L.C.