Creating a skill for Alice using Terraform
To create a skill for Alice using Terraform:
- Get your cloud ready.
- Create the infrastructure.
- Add the function link to the Alice's skill.
- Test the skill.
If you no longer need the resources you created, delete them.
Getting started
Sign up for Yandex Cloud and create a billing account:
- Navigate to the management console
and log in to Yandex Cloud or create a new account. - On the Yandex Cloud Billing
page, make sure you have a billing account linked and it has theACTIVEorTRIAL_ACTIVEstatus. 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 create or select a folder for your infrastructure on the cloud page
Learn more about clouds and folders here.
Create the infrastructure
With Terraform
Terraform is distributed under the Business Source License
For more information about the provider resources, see the guides on the Terraform
To create an infrastructure with Terraform:
-
Install Terraform, get the authentication credentials, and specify the Yandex Cloud provider source (see Configure your provider, Step 1).
-
Set up your infrastructure description file:
Ready-made configurationManually-
Clone the repository containing the configuration files and function code examples:
git clone https://github.com/yandex-cloud-examples/yc-serverless-alice-skill -
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.
-
Prepare the code for the Alice's skill. To create a new function version, you will upload its code to Yandex Cloud Functions as a ZIP archive.
PythonNode.jsAdd the
parrot.pyfile from the cloned repository to theparrot-py.ziparchive.Add the
index.jsfile from the cloned repository to theparrot-js.ziparchive.
-
Prepare the code for the Alice's skill. To create a new function version, you will upload its code to Yandex Cloud Functions as a ZIP archive.
-
Create a folder for the infrastructure description file.
-
Create a configuration file named
alice-skill.tfin the folder:alice-skill.tf
# 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) } -
In the folder, create a user data file named
alice-skill.auto.tfvars:alice-skill.auto.tfvars
folder_id = "<folder_ID>" file_path = "<local_path_to_function_code_archive>" language = "<programming_language>"
Learn more about the properties of resources used in Terraform in this provider guide.
-
-
In the
alice-skill.auto.tfvarsfile, set the following user-defined properties:-
folder_id: Folder ID. -
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:pythonif using thePythonexample.nodejsif using theNode.jsexample.
-
-
Create the resources:
-
In the terminal, navigate to the configuration file directory.
-
Make sure the configuration is correct using this command:
terraform validateIf the configuration is valid, you will get this message:
Success! The configuration is valid. -
Run this command:
terraform planYou 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.
-
Apply the configuration changes:
terraform apply -
Type
yesand press Enter to confirm the changes.
-
Add the function link to the Alice's skill
-
Go to the Alice skill page in your dashboard.
-
Click
Skill for Alice and do the following in the window that opens:-
In the Skill name field, specify a unique name for the skill you are creating.
-
In the Backend field, select Function in Yandex Cloud. Select the function you created earlier from the drop-down list.
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 role or higher.
-
Leave all the other parameter values unchanged and click Save at the top of the page.
-
The functions.functionInvoker role allows you to invoke functions. For more information on access management in Yandex Cloud, see this guide.
Test the skill
- In your Yandex Dialogs account
, select Testing in the left-hand menu on the page with the skill you created earlier. - 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.. - Send a message with any text and make sure the response contains the same text.
How to delete the resources you created
To stop paying for the resources you created:
-
Open the
alice-skill.tffile and delete your infrastructure description from it. -
Apply the changes:
-
In the terminal, navigate to the configuration file directory.
-
Make sure the configuration is correct using this command:
terraform validateIf the configuration is valid, you will get this message:
Success! The configuration is valid. -
Run this command:
terraform planYou 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.
-
Apply the configuration changes:
terraform apply -
Type
yesand press Enter to confirm the changes.
-
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.
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.