すべてのプロダクト
Search
ドキュメントセンター

CloudOps Orchestration Service:Terraform を使用した OOS のオーケストレーション

最終更新日:Jun 21, 2026

Terraform は、クラウド リソースを安全かつ効率的に設定、管理するためのオープンソースツールです。Terraform を使用して CloudOps Orchestration Service を管理できます。このトピックでは、Terraform を使用して CloudOps Orchestration Service にアプリケーションを作成する方法について説明します。

前提条件

  • このトピックの操作を実行するには、最小限の権限を持つ RAM ユーザーを使用することを推奨します。これにより、Alibaba Cloud アカウントのアクセスキーペアが漏洩するリスクを低減できます。詳細については、「RAM ユーザーの作成」および「RAM ユーザーへの権限付与」をご参照ください。サンプルポリシー:

    {
      "Version": "1",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": [
            "oos:GetApplication",
            "oos:DeleteApplication",
            "oos:CreateApplication",
            "oos:ListApplications"
          ],
          "Resource": "*"
        }
      ]
    }
  • Terraform のランタイム環境は、次のいずれかの方法で準備します。

    • Terraform Explorer で Terraform を使用する:Alibaba Cloud は Terraform のオンラインランタイム環境を提供します。Terraform をインストールすることなく、Terraform Explorer 環境にログインして Terraform を使用できます。この方法は、コストゼロで効率的かつ便利に Terraform を使用およびデバッグしたいシナリオに適しています。

    • Cloud Shell で Terraform を使用する:Terraform は Cloud Shell にプリインストールされており、認証情報も設定済みです。Cloud Shell で直接 Terraform コマンドを実行できます。この方法は、低コストで迅速かつ便利に Terraform を使用およびデバッグしたいシナリオに適しています。

    • オンプレミスマシンに Terraform をインストールして設定する:この方法は、ネットワーク接続が不安定な場合や、カスタム開発環境が必要な場合に適しています。

必要なリソース

アプリケーションの作成

  1. 作業ディレクトリと、そのディレクトリに main.tf という名前のファイルを作成します。次に、以下の内容を main.tf ファイルにコピーします。

    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. 次のコマンドを実行して、Terraform ランタイム環境を初期化します:

    terraform init

    以下の情報が表示されたら、Terraform の初期化は完了です。

    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. 次のコマンドでコードを実行します。

    terraform apply

    プロンプトが表示されたら、yes と入力して [Enter] キーを押します。以下の情報が表示されたら、OOS アプリケーションの作成は完了です。

    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. 結果を確認します。

    terraform show コマンドの実行

    作業ディレクトリで次のコマンドを実行し、Terraform で作成したリソースの詳細を確認します。

    terraform show
    shell@Alicloud:~/oos$ terraform show
    # alicloud_oos_application.default:
    resource "alicloud_oos_application" "default" {
        application_name  = "terraform-example-xxx"
        description       = "terraform-example"
        id                = "terraform-example-xxx"
        resource_group_id = "rg-xxx"
        tags              = {
            "Created" = "TF"
        }
    }
    
    # data.alicloud_resource_manager_resource_groups.default:
    data "alicloud_resource_manager_resource_groups" "default" {
        enable_details = false
        groups         = [
            {
                account_id   = "xxx"
                display_name = "default resource group"
                id           = "rg-xxx"
                name         = "default"
                # ...

    コンソールへのログイン

    OOS コンソールにログインします。[Application Management] ページで、作成したアプリケーションを表示します。

リソースのリリース

Terraform で作成したリソースが不要になった場合は、次のコマンドを実行してリリースします。terraform destroy コマンドの詳細については、「一般的なコマンド」をご参照ください。

terraform destroy

完全なサンプルコード

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"
  }
}

その他のサンプルコードは、GitHub をご参照ください。