Delivering data from Yandex Forms to Yandex DataLens using Yandex Cloud Functions and Yandex Query via Terraform
To set up Forms and DataLens integration via Terraform:
- Set up your infrastructure.
- Create and configure a function in Yandex Cloud Functions.
- Create and set up a form in Forms.
- Configure a connection and binding to data in Yandex Query.
- Set up fetching data in DataLens.
- Test the new resource integration.
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:
- Navigate to the management console
and log in to Yandex Cloud or register a new account. - On the Yandex Cloud Billing
page, make sure you have a billing account linked and it has theACTIVE
orTRIAL_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
Learn more about clouds and folders.
Required paid resources
The infrastructure support cost includes:
- Fee for using the Yandex Object Storage bucket (see Object Storage pricing).
- Fee for storing and requesting Yandex Lockbox secrets (see Yandex Lockbox pricing).
- Fee for function calls and computing resources allocated for executing the functions (see Cloud Functions pricing).
- Fee for the amount of data read from sources when executing Query queries (see Query pricing).
- Fee for using DataLens under the service plan (see DataLens pricing).
Set up your infrastructure
With Terraform
Terraform is distributed under the Business Source License
For more information about the provider resources, see the documentation on the Terraform
To set up your infrastructure via Terraform:
-
If you do not have Terraform yet, install it.
-
Get the authentication credentials. You can add them to environment variables or specify them later in the provider configuration file.
-
Configure and initialize a provider. There is no need to create a provider configuration file manually, you can download it
. -
Place the configuration file in a separate working directory and specify the parameter values. If you did not add the authentication credentials to environment variables, specify them in the configuration file.
-
Download the forms-and-datalens-integration.tf
configuration file to the same working directory.This file describes:
- Network and subnet for deploying the infrastructure for your function in Cloud Functions.
- Service account with the following roles:
lockbox.payloadViewer
: For reading Yandex Lockbox secrets.functions.functionInvoker
: For calling the function in Cloud Functions.storage.admin
: For reading data from and writing data to an Object Storage bucket, as well as managing the bucket’s ACL.yq.viewer
andyq.invoker
: For integrating DataLens and Query.
- Static key for the service account used for creating the Object Storage bucket.
- Static key for the service account used for creating the function in Cloud Functions.
- Yandex Lockbox secret for storing data on the service account static key for the function from Cloud Functions.
data
resource for the Yandex Lockbox secret the function in Cloud Functions uses to retrieve the secret version ID.- Object Storage bucket to store function results.
- Publicly accessible function in Cloud Functions.
-
In the local variables section of the
forms-and-datalens-integration.tf
file, specify the following:- Your folder ID in the
sa_folder_id
variable. - Name of the Object Storage bucket in the
bucket-name
variable.
- Your folder ID in the
-
Make sure the Terraform configuration files are correct using this command:
terraform validate
If there are any errors in the configuration files, Terraform will point them out.
-
Create the required infrastructure:
-
Run this command to view the planned changes:
terraform plan
If you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
-
If everything looks correct, apply the changes:
-
Run this command:
terraform apply
-
Confirm updating the resources.
-
Wait for the operation to complete.
-
All the required resources will be created in the specified folder. You can check resource availability and their settings in the management console
. -
Create and configure a function in Cloud Functions
-
Download the function code archive
to the directory with theforms-and-datalens-integration.tf
file. -
Under the local variables section of the
forms-and-datalens-integration.tf
file, specify the following values:content_path
=function.zip
.create-function
=1
.
-
Make sure the Terraform configuration files are correct using this command:
terraform validate
If there are any errors in the configuration files, Terraform will point them out.
-
Create the required infrastructure:
-
Run this command to view the planned changes:
terraform plan
If you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
-
If everything looks correct, apply the changes:
-
Run this command:
terraform apply
-
Confirm updating the resources.
-
Wait for the operation to complete.
-
All the required resources will be created in the specified folder. You can check resource availability and their settings in the management console
. -
Create and set up a Forms form
Create an API key
You need an API key to set up integration with Forms.
- In the management console
, select the appropriate folder. - From the list of services, select Identity and Access Management.
- Select the
forms-integration
service account. - Go to Overview.
- Click Create new key and select Create API key.
- Click Create.
- In the window that opens, New key, you will see Key ID and Your secret key. Save them, as you will need them later.
Create a form
-
Go to Forms
. -
Click Create form.
-
Add at least two fields to the form and set up any questions in them.
-
Click Publish.
-
Save the link to the published form: you will need it later.
Set up integration with a Cloud Functions function
-
Go to Forms
. -
Open the form you created earlier.
-
Go to the Settings tab.
-
Open the Additional section.
-
Under Cloud function key, enter the data of the previously created API key and click Save.
-
Open the Integrations tab.
-
Click Cloud Functions to add a condition for the integration.
-
In the Function code field, enter the Cloud Functions function ID. You can copy the ID in the Overview section of the Cloud Functions function in the management console.
-
In the Show outcome notification field, select Show.
-
Click Save.
Test the integration you created
-
Follow the public link to the previously created form.
-
Complete the form and click Submit.
-
Go to Forms
. -
Open the form you created earlier.
-
Open the Integrations tab.
-
Go to the Completed integrations page.
-
Open the completed action record and make sure that the Response section contains the
200 — OK
response. -
Navigate to the management console
and open the bucket created earlier. Make sure the bucket now contains a JSON file with the data from the form you completed.The name of the directory the file will reside in matches the form's internal ID. Save this ID for the next steps.
All the future form completion outcomes will be saved in this directory.
-
Complete the form several times more, and make sure you fill one of the fields in the same way in at least two forms. This will improve data visualization when testing the integration.
Configure a connection and binding to data in Query
- Navigate to the management console
and select Query. - In the Connections tab, click
Create new. - Create a connection with the following parameters:
- Name:
forms-connection
. - Type:
Object Storage
. - Bucket: Name of the bucket you created earlier.
- Service account:
forms-integration-sa
.
- Name:
- In the window that opens, set the data binding parameters:
- Type:
Object Storage
. - Connection:
forms-connection
. - Path:
/<form_ID>/
.
You can copy the ID:- Under Objects in the Object Storage bucket. The name of the folder containing the file with results of the completed form matches the form ID.
- In the address bar of the Forms interface
, on the form viewing or editing page.
- Format:
json_each-row
. - Columns: Create columns for the fields you specified in the form.
If you want Query to define columns automatically, click Detect columns.
- Type:
Set up fetching data in DataLens
- Go to DataLens
. - In the left-hand panel, select
Connections and click Create connection. - Select Query. In the window that opens, set the below parameters as follows:
- Cloud and folder: Select the cloud and folder where you created the rest of the resources.
- Service account:
forms-integration-sa
- Click Save changes. In the window that opens, specify
forms-datalens-connection
as the connection name, then click Create. - Go back to the DataLens
main page and click Create dataset. - In the connection panel, click
Add and select theforms-datalens-connection
connection. - Under Tables, select the table and drag it to your DataLens workspace.
After loading, the data from the table will appear in the Preview panel. - Click Save and enter
forms-integration-dataset
as the dataset name, then click Create.
Test the new resource integration
To check how the created resources work together, open the forms-integration-dataset
dataset and click Create chart. In the window that opens, create a chart using the data from the form. For better visualization, create a chart based on a field with repeating values.
Delete the resources you created
Some resources are not free of charge. Delete the resources you no longer need to avoid paying for them.
-
In the terminal window, go to the directory containing the infrastructure plan.
Warning
Make sure the directory has no Terraform manifests with the resources you want to keep. Terraform deletes all resources that were created using the manifests in the current directory.
-
Delete resources:
-
Run this command:
terraform destroy
-
Confirm deleting the resources and wait for the operation to complete.
All the resources described in the Terraform manifests will be deleted.
-