Terraform

Updated at:

Platform for AI (PAI) supports Terraform, which lets you manage PAI resources.

Background information

Basic features

Terraform is an infrastructure as code (IaC) tool. It lets you define and configure cloud infrastructure by writing simple code, which eliminates the need for manual operations. For more information, see the Terraform product introduction.

  • Terraform provides an easy-to-use CLI that allows you to deploy configuration files on the workloads of Alibaba Cloud services or third-party cloud services and manage the versions of the configuration files. Terraform allows you to define the infrastructure resources that are required to build cloud topologies in configuration files. The resources include virtual machines (VMs), storage accounts, and network interfaces.

  • Terraform supports new infrastructure through providers. This lets you use a simple template language to easily define, preview, and deploy cloud infrastructure on Alibaba Cloud.

  • Terraform allows you to create, modify, and delete the resources of multiple Alibaba Cloud services, such as Elastic Compute Services (ECS), Virtual Private Cloud (VPC), ApsaraDB RDS, and Server Load Balancer (SLB).

Scenarios

Terraform allows you to define infrastructure as code and use code to create, query, modify, and delete infrastructure resources. For information about the examples on how to use Terraform to manage the resources of Alibaba Cloud services, see Scenarios.

Install and configure Terraform

Only Terraform 1.241.0 and later versions support PAI resource management.

Manage PAI resources using Terraform

The following table lists the PAI resources that you can manage with Terraform.

Resource type

Description

alicloud_pai_service

Deploy as an EAS Service

alicloud_pai_workspace_code_source

Create a code build

alicloud_pai_workspace_dataset

Create a dataset

alicloud_pai_workspace_datasetversion

Create a dataset version

alicloud_pai_workspace_experiment

Create a flow task

alicloud_pai_workspace_run

Create an algorithm component task

alicloud_pai_workspace_workspace

Create a workspace

The following example shows how to use Terraform to create a workspace with alicloud_pai_workspace_workspace.

  1. Create a terraform.tf file, enter the following content, and save the file in the current execution directory.

    resource "alicloud_pai_workspace_workspace" "default" {
      description    = "example_terraform_workspace"
      workspace_name = "example_terraform_workspace"
      display_name   = "example_terraform_workspace"
      env_types      = ["prod"]
    }
  2. Run terraform init to initialize Terraform and download the required plugins.

  3. Run terraform apply to create the resources.

  4. Run terraform show to view the created workspace.

    Alternatively, you can log on to the PAI console to view the created workspace.