Написать в техподдержку Позвонить нам
Admin Panel Logout

In this article:

    Terraform for MCS

    At the moment, MCS supports 2 Terraform providers at once: OpenStack for managing IaaS services and its own MCS Terraform Provider for managing PaaS services. In order to manage Kubernetes clusters in the Mail.ru Cloud Solutions cloud, you will need to connect both the OpenStack terraform provider and the MCS terraform provider.

    Detailed instructions on the MCS provider for Terraform are available at this link https://mcs.mail.ru/terraform/docs

    To start using MCS Terrafom Provider, follow these steps:

    Installing terraform

    Download terraform on the official resource and follow the instructions for its installation.

    Provider setting

    To start using the terraform MCS provider, follow these steps:


    MCS Terraform Provider is published in the Terraform Registry. Documentation and usage example are available on Terraform website.

    1. Create a directory where config files will be stored, for example, `mcs_terraform`.
    2. Go to the `mcs_terraform` directory and create a` main.tf` file in it, and also create a `vars.tf` file to use variables when creating resources.
    3. Download the configuration file for OpenStack Terraform Provider and MCS Terraform Provider from the following link available in your personal account after authorization, save both files in the `mcs_terraform` folder
    4. In the files `mcs_provider.tf` and ʻopenstack_provider.tf` specify the password for the account in the field` password`


    For correct operation of both providers, you need to make sure that the ʻOS_USER_DOMAIN_ID` variable is not set in the environment variables. It can also be removed by running the command:

     unset OS_USER_DOMAIN_ID

             5. Add the following code to the main.tf file.

    terraform {
        required_providers {
            mcs = {
                source  = "MailRuCloudSolutions/mcs"
                version = "~> 0.3.0"
            openstack = {
                source = "terraform-provider-openstack/openstack"

    Resource creation

    The following steps are required to create and manage resources:

    In the file `main.tf`, describe the resources to create. For example, to create a cluster with a group of nodes, insert the following:

     data "mcs_kubernetes_clustertemplate" "ct1" {
    # version of the Kubernetes cluster
    version = 16
    data "openstack_compute_flavor_v2" "k8s" {
    # virtual machine type
    name = "Standard-2-4-40"
    # describes the cluster itself
    resource "mcs_kubernetes_cluster" "mycluster" {
    cluster_template_id = data.mcs_kubernetes_clustertemplate.ct1.id
    subnet_id = "your_subnet_id"
    network_id = "your_network_id"
    master_flavor = data.openstack_compute_flavor_v2.k8s.id
    keypair = "your_keypair_name"
    # describes the Node Group of the cluster. One cluster may have many Node Groups, but as a last resort it may not have a single Node Group.
    resource "mcs_kubernetes_node_group" "myng" {
    cluster_id = mcs_kubernetes_cluster.mycluster.id
    node_count = 1


    For the convenience of filling in some of the ʻid`, you can use the `data sources`. They start with a data label and read existing resources.

    Creating or using a keypair (key pair):

     # Read an existing key pair. Use `data.openstack_compute_keypair_v2.kp` to access the attributes
    data "openstack_compute_keypair_v2" "kp" {
    name = "my-keypair"
    # Generate key pair
    resource "openstack_compute_keypair_v2" "test-keypair" {
    name = "my-keypair"
    # Create with an existing key pair
    resource "openstack_compute_keypair_v2" "test-keypair" {
    name = "my-keypair"
    public_key = "ssh-rsa your_public_key"

    Creating new network entities or reading existing ones:

     # Read existing resources
    data "openstack_networking_network_v2" "k8s_network" {
    name = "your_network_name"
    data "openstack_networking_subnet_v2" "k8s_subnet" {
    name = "your_subnet_name"
    # Create new resources
    resource "openstack_networking_network_v2" "k8s" {
    name = "k8s-net"
    admin_state_up = true
    resource "openstack_networking_subnet_v2" "k8s-subnetwork" {
    name = "k8s-subnet"
    network_id = openstack_networking_network_v2.k8s.id
    cidr = ""
    ip_version = 4
    dns_nameservers = ["", ""]
    data "openstack_networking_network_v2" "extnet" {
    name = "ext-net"
    resource "openstack_networking_router_v2" "k8s" {
    name = "k8s-router"
    admin_state_up = true
    external_network_id = data.openstack_networking_network_v2.extnet.id
    resource "openstack_networking_router_interface_v2" "k8s" {
    router_id = openstack_networking_router_v2.k8s.id
    subnet_id = openstack_networking_subnet_v2.k8s-subnetwork.id

    Application configuration

    1. Run command:
       terraform init
    2. To see what resources will be created, run
       terraform plan
    3. To apply the selected configuration, execute
       terraform apply

      and enter `yes`.

    Deleting Resources

    Run command:

     terraform destroy

    and enter `yes`.

    Was this article helpful?