[Yandex Cloud documentation](../../../index.md) > [Tutorials](../../index.md) > [Application solutions](../index.md) > Alice > [Creating a skill for Alice](index.md) > Terraform

# Creating a skill for Alice using Terraform


To create a skill for Alice using Terraform:

1. [Get your cloud ready](#before-you-begin).
1. [Create the infrastructure](#deploy).
1. [Add the function link to the Alice's skill](#add-link).
1. [Test the skill](#test).

If you no longer need the resources you created, [delete](#clear-out) them.

## Getting started {#before-you-begin}

Sign up for Yandex Cloud and create a [billing account](../../../billing/concepts/billing-account.md):
1. Navigate to the [management console](https://console.yandex.cloud) and log in to Yandex Cloud or create a new account.
1. On the **[Yandex Cloud Billing](https://center.yandex.cloud/billing/accounts)** page, make sure you have a billing account linked and it has the `ACTIVE` or `TRIAL_ACTIVE` [status](../../../billing/concepts/billing-account-statuses.md). If you do not have a billing account, [create one](../../../billing/quickstart/index.md) and [link](../../../billing/operations/pin-cloud.md) a cloud to it.

If you have an active billing account, you can create or select a [folder](../../../resource-manager/concepts/resources-hierarchy.md#folder) for your infrastructure on the [cloud page](https://console.yandex.cloud/cloud).

[Learn more about clouds and folders here](../../../resource-manager/concepts/resources-hierarchy.md).

## Create the infrastructure {#deploy}

With [Terraform](https://www.terraform.io/), 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](https://github.com/hashicorp/terraform/blob/main/LICENSE). The [Yandex Cloud provider for Terraform](https://github.com/yandex-cloud/terraform-provider-yandex) is distributed under the [MPL-2.0](https://www.mozilla.org/en-US/MPL/2.0/) license.

For more information about the provider resources, see the guides on the [Terraform](https://www.terraform.io/docs/providers/yandex/index.html) website or [its mirror](../../../terraform/index.md).

To create an infrastructure with Terraform:

1. [Install Terraform](../../infrastructure-management/terraform-quickstart.md#install-terraform), [get the authentication credentials](../../infrastructure-management/terraform-quickstart.md#get-credentials), and specify the Yandex Cloud provider source (see [Configure your provider](../../infrastructure-management/terraform-quickstart.md#configure-provider), Step 1).
1. Set up your infrastructure description file:

    {% list tabs group=infrastructure_description %}

    - Ready-made configuration {#ready}

      1. Clone the repository containing the configuration files and function code examples:

          ```bash
          git clone https://github.com/yandex-cloud-examples/yc-serverless-alice-skill
          ```
      1. Navigate to the repository directory. It should now contain the following files:

          * `alice-skill.tf`: New infrastructure configuration.
          * `alice-skill.auto.tfvars`: User data.
          * `parrot.py`: File with the function code in Python.
          * `index.js`: File with the function code in Node.js.
      1. Prepare the code for the Alice's skill. To create a new function [version](*function_version), you will upload its code to Yandex Cloud Functions as a [ZIP archive](*upload_formats).

          {% list tabs group=programming_language %}

          - Python {#python}

              Add the `parrot.py` file from the cloned repository to the `parrot-py.zip` archive.

          - Node.js {#node}

              Add the `index.js` file from the cloned repository to the `parrot-js.zip` archive.

          {% endlist %}

    - Manually {#manual}

      1. Prepare the code for the Alice's skill. To create a new function [version](*function_version), you will upload its code to Yandex Cloud Functions as a [ZIP archive](*upload_formats).

          {% list tabs group=programming_language %}
          
          - Python {#python}
          
              1. Download the [parrot.py](https://github.com/yandex-cloud-examples/yc-serverless-alice-skill/blob/main/parrot.py) example file from the GitHub repo.
              1. Create a ZIP archive named `parrot-py.zip` with the `parrot.py` file.
          
          - Node.js {#node}
          
              1. Download the [index.js](https://github.com/yandex-cloud-examples/yc-serverless-alice-skill/blob/main/index.js) example file from the GitHub repo.
              1. Create a ZIP archive named `parrot-js.zip` with the `index.js` file.
          
          {% endlist %}

      1. Create a folder for the infrastructure description file.
      1. Create a configuration file named `alice-skill.tf` in the folder:

          {% cut "alice-skill.tf" %}

          ```hcl
          # Declaring variables
          
          variable "folder_id" {
            type = string
          }
          
          variable "file_path" {
            type = string
          }
          
          variable "language" {
            type = string
          }
          
          # Configuring the provider
          
          terraform {
            required_providers {
              yandex = {
                source = "yandex-cloud/yandex"
              }
            }
            required_version = ">= 0.13"
          }
          
          provider "yandex" {
            folder_id = var.folder_id
          }
          
          # Creating a function and a function version
          
          resource "yandex_function" "alice_parrot" {
            name               = "alice-parrot"
            description        = "Yandex Alice skill: Parrot (repeats user input)"
            runtime            = var.language == "python" ? "python312" : "nodejs18"
            entrypoint         = var.language == "python" ? "parrot.handler" : "index.handler"
            memory             = 128
            execution_timeout  = 2
          
            content {
              zip_filename = var.file_path
            }
          
            user_hash = filesha256(var.file_path)
          }
          ```

          {% endcut %}

      1. In the folder, create a user data file named `alice-skill.auto.tfvars`:

          {% cut "alice-skill.auto.tfvars" %}

          ```hcl
          folder_id         = "<folder_ID>"
          file_path         = "<local_path_to_function_code_archive>"
          language          = "<programming_language>"
          ```

          {% endcut %}

    {% endlist %}

    Learn more about the properties of resources used in Terraform in [this provider guide](../../../terraform/resources).

1. In the `alice-skill.auto.tfvars` file, set the following user-defined properties:

    * `folder_id`: [Folder ID](../../../resource-manager/operations/folder/get-id.md).
    * `file_path`: Local path to the archive file with the function code. Here is an example: `/Users/myuser/Temp/parrot-py.zip`.
    * `language`: Depending on the function language, specify:

        * `python` if using the `Python` example.
        * `nodejs` if using the `Node.js` example.

1. Create the resources:

    1. In the terminal, navigate to the configuration file directory.
    1. Make sure the configuration is correct using this command:
    
       ```bash
       terraform validate
       ```
    
       If the configuration is valid, you will get this message:
    
       ```bash
       Success! The configuration is valid.
       ```
    
    1. Run this command:
    
       ```bash
       terraform plan
       ```
    
       You will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
    1. Apply the configuration changes:
    
       ```bash
       terraform apply
       ```
    
    1. Type `yes` and press **Enter** to confirm the changes.

## Add the function link to the Alice's skill {#add-link}

{% list tabs %}

- Yandex Dialogs UI

  1. Go to the Alice skill page in your [dashboard.](https://dialogs.yandex.ru/developer/)
  1. Click ![circle-plus](../../../_assets/console-icons/circle-plus.svg) **Skill for Alice** and do the following in the window that opens:

      1. In the **Skill name** field, specify a unique name for the skill you are creating.
      1. In the **Backend** field, select **Function in Yandex Cloud**. Select the function you created earlier from the drop-down list.

          {% note warning %}

          The list shows the functions that you are allowed to view. To attach a function to a skill, you need permission to invoke the function. This permission comes with the [functions.functionInvoker](*functions_invoker) role or higher.

          {% endnote %}

      1. Leave all the other parameter values unchanged and click **Save** at the top of the page.

{% endlist %}

[*functions_invoker]: The `functions.functionInvoker` role allows you to invoke functions. For more information on access management in Yandex Cloud, see [this guide](../../../iam/concepts/access-control/index.md).

## Test the skill {#test}

{% list tabs %}

- Yandex Dialogs interface

  1. In your Yandex Dialogs [account](https://dialogs.yandex.ru/developer/), select **Testing** in the left-hand menu on the page with the skill you created earlier.
  1. If everything is set up correctly, the **Chat** section will display a message inviting you to start a conversation: `Hello! I'll repeat anything you say to me.`.
  1. Send a message with any text and make sure the response contains the same text.

{% endlist %}

## How to delete the resources you created {#clear-out}

To stop paying for the resources you created:

1. Open the `alice-skill.tf` file and delete your infrastructure description from it.
1. Apply the changes:

    1. In the terminal, navigate to the configuration file directory.
    1. Make sure the configuration is correct using this command:
    
       ```bash
       terraform validate
       ```
    
       If the configuration is valid, you will get this message:
    
       ```bash
       Success! The configuration is valid.
       ```
    
    1. Run this command:
    
       ```bash
       terraform plan
       ```
    
       You will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
    1. Apply the configuration changes:
    
       ```bash
       terraform apply
       ```
    
    1. Type `yes` and press **Enter** to confirm the changes.

[*function_version]: A version contain the function code, execution parameters, as well as all required dependencies. You can use different versions of the same function at different development stages. For more information, see [Function versions](../../../functions/concepts/function.md#version).

[*upload_formats]: There are several ways to upload a function version code: in the editor in the management console, from local files and directories, or as an archive. For more information, see [Code upload format](../../../functions/concepts/function.md#upload).

#### Useful links {#see-also}

* [Creating a skill for Alice using serverless technology via the management console, Yandex Cloud CLI, or API](console.md)