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
alicloud_oos_application: an application in OOS.
Create an application
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" } }Run the following command to initialize the Terraform runtime environment:
terraform initIf 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.Run the following command to run the code.
terraform applyWhen prompted, enter
yesand 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.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
Log on to the console
Log on to the OOS console. On the page, view the created application.

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 destroyComplete sample code
Examples
To view other sample code, visit GitHub.