Alibaba Cloud Cloud Shell is a free O&M product that comes pre-installed with Terraform and configured with authentication credentials. Therefore, you can run Terraform commands in Cloud Shell.

To use Terraform in Cloud Shell, perform the following operations:
  1. Open your browser and enter https://shell.aliyun.com in the address bar to access Cloud Shell.

    For more information about how to use Cloud Shell, see Use Cloud Shell.

  2. Log on to Cloud Shell.
  3. Compile a Terraform template.

    You can use the vim command to compile a Terraform template. If Object Storage Service (OSS) has been activated, you can upload the template that you compile to a bucket created for Cloud Shell.

    Example:
    provider "alicloud" {}
    
    resource "alicloud_vpc" "vpc" {
      name       = "tf_test_foo"
      cidr_block = "172.16.0.0/12"
    }
    
    resource "alicloud_vswitch" "vsw" {
      vpc_id            = alicloud_vpc.vpc.id
      cidr_block        = "172.16.0.0/21"
      availability_zone = "cn-hangzhou-b"
    }
    
    
    resource "alicloud_security_group" "default" {
      name = "default"
      vpc_id = alicloud_vpc.vpc.id
    }
    
    resource "alicloud_instance" "instance" {
      # Zone
      availability_zone = "cn-hangzhou-b"
      # Security group
      security_groups = alicloud_security_group.default. *.id
    
      # Instance type
      instance_type        = "ecs.n2.small"
      # System disk category
      system_disk_category = "cloud_efficiency"
      # System image
      image_id             = "ubuntu_140405_64_40G_cloudinit_20161115.vhd"
      # Instance name
      instance_name        = "test_foo"
      # VSwitch
      vswitch_id = alicloud_vswitch.vsw.id
      # Public bandwidth
      internet_max_bandwidth_out = 10
    }
    
    resource "alicloud_security_group_rule" "allow_all_tcp" {
      type              = "ingress"
      ip_protocol       = "tcp"
      nic_type          = "intranet"
      policy            = "accept"
      port_range        = "1/65535"
      priority          = 1
      security_group_id = alicloud_security_group.default.id
      cidr_ip           = "0.0.0.0/0"
    }
  4. Run the terraform init command to initialize the Terraform configuration files.
  5. Run the terraform plan command to preview configurations.terraform plan
  6. Run the terraform apply command to create one or more ECS instances.