All Products
Search
Document Center

CloudOps Orchestration Service:Use Terraform to orchestrate CloudOps Orchestration Service

Last Updated:Nov 20, 2025

Terraform is an open source tool that is used to securely and efficiently configure and manage cloud resources. You can use Terraform to manage CloudOps Orchestration Service. This topic describes how to use Terraform to create an application in CloudOps Orchestration Service.

Prerequisites

  • We recommend that you use a RAM user that has the minimum required permissions to perform the operations in this topic. This reduces the risk of leaking the AccessKey pair of your Alibaba Cloud account. For more information, see Create a RAM user and Grant permissions to a RAM user. Sample policy:

    {
      "Version": "1",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": [
            "oos:GetApplication",
            "oos:DeleteApplication",
            "oos:CreateApplication",
            "oos:ListApplications"
          ],
          "Resource": "*"
        }
      ]
    }
  • The runtime environment for Terraform is prepared using one of the following methods:

    • Use Terraform in Terraform Explorer: Alibaba Cloud provides an online runtime environment for Terraform. You can log on to the Terraform Explorer environment to use Terraform without the need to install Terraform. This method is suitable for scenarios where you need to use and debug Terraform in a zero-cost, efficient, and convenient manner.

    • Use Terraform in Cloud Shell: Terraform is preinstalled in Cloud Shell and identity credentials are configured. You can directly run Terraform commands in Cloud Shell. This method is suitable for scenarios in which you want to use and debug Terraform in a fast and convenient manner at low costs.

    • Install and configure Terraform on your on-premises machine: This method is suitable for scenarios in which network connections are unstable or a custom development environment is required.

Required resources

Create an application

  1. Create a working directory and a file named main.tf under the directory. Then, copy the following content to the main.tf file.

    variable "region" {
      default = "cn-hangzhou"
    }
    
    provider "alicloud" {
      region = var.region
    }
    
    variable "name" {
      default = "terraform-example"
    }
    
    resource "random_integer" "default" {
      min = 10000
      max = 99999
    }
    
    data "alicloud_resource_manager_resource_groups" "default" {}
    
    resource "alicloud_oos_application" "default" {
      resource_group_id = data.alicloud_resource_manager_resource_groups.default.groups.0.id
      application_name  = "${var.name}-${random_integer.default.result}"
      description       = var.name
      tags = {
        Created = "TF"
      }
    }
  2. Run the following command to initialize the Terraform runtime environment:

    terraform init

    If the following information is returned, Terraform is initialized.

    Terraform has been successfully initialized!
    
    You may now begin working with Terraform. Try running "terraform plan" to see
    any changes that are required for your infrastructure. All Terraform commands
    should now work.
    
    If you ever set or change modules or backend configuration for Terraform,
    rerun this command to reinitialize your working directory. If you forget, other
    commands will detect it and remind you to do so if necessary.
  3. Run the following command to run the code.

    terraform apply

    When prompted, enter yes and press the Enter key. If the following information is returned, the OOS application is created.

    You can apply this plan to save these new output values to the Terraform state, without changing any real infrastructure.
    
    Do you want to perform these actions?
      Terraform will perform the actions described above.
      Only 'yes' will be accepted to approve.
    
      Enter a value: yes
    
    
    Apply complete!  Resources: 2 added, 0 changed, 0 destroyed.
  4. Verify the result.

    Run the terraform show command

    Run the following command in the working directory to query the details of the resource that is created using Terraform:

    terraform show

    image

    Log on to the console

    Log on to the OOS console. On the Application Management page, view the created application.

    image

Release resources

When you no longer need the resources created by Terraform, run the following command to release them. For more information about the terraform destroy command, see Common commands.

terraform destroy

Complete sample code

Examples

variable "region" {
  default = "cn-hangzhou"
}

provider "alicloud" {
  region = var.region
}

variable "name" {
  default = "terraform-example"
}

resource "random_integer" "default" {
  min = 10000
  max = 99999
}

data "alicloud_resource_manager_resource_groups" "default" {}

resource "alicloud_oos_application" "default" {
  resource_group_id = data.alicloud_resource_manager_resource_groups.default.groups.0.id
  application_name  = "${var.name}-${random_integer.default.result}"
  description       = var.name
  tags = {
    Created = "TF"
  }
}

To view other sample code, visit GitHub.