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

Anti-DDoS:Terraform を使用した Anti-DDoS Proxy の購入と管理

最終更新日:Jun 23, 2026

Terraform を使用して Anti-DDoS Proxy インスタンスを購入および管理できます。このトピックでは、Anti-DDoS Proxy インスタンスを購入する方法の例を説明します。

説明

このトピックのサンプルコードはワンクリックで実行できます。ワンクリックで実行

前提条件

  • Alibaba Cloud アカウント (root ユーザー) は、すべてのリソースに対する完全な権限を持っています。アカウントが侵害されると、重大なセキュリティリスクが生じます。RAM ユーザーを使用し、その RAM ユーザーの AccessKey を作成することを推奨します。詳細については、「RAM ユーザーの作成」および「AccessKey の作成」をご参照ください。

  • Terraform コマンドを実行する RAM ユーザーに、この例のリソースを管理するために必要な権限を付与するために、以下の最小限必要なポリシーをアタッチします。詳細については、「RAM ユーザー権限の管理」をご参照ください。

    このポリシーにより、RAM ユーザーは Anti-DDoS Proxy インスタンスを作成および削除できます。

    {
      "Statement": [
        {
          "Action": [
            "ddosprotection:CreateInstance",
            "ddosprotection:DeleteInstance"
          ],
          "Effect": "Allow",
          "Resource": "*"
        }
      ],
      "Version": "1"
    }
  • Terraform の実行環境を準備します。以下のいずれかの方法を使用できます。

リソース

操作手順

  1. 作業ディレクトリを作成し、その中に main.tf という名前の設定ファイルを作成します。

    main.tf:デプロイするリソースを定義する Terraform のメインファイルです。この例では、Anti-DDoS Proxy (中国本土以外) インスタンスを購入する方法を示します。

    重要

    Terraform で作成された Anti-DDoS Proxy (中国本土以外) インスタンスは、Terraform では削除できないことにご注意ください。不要なコストを避けるため、インスタンスのライフサイクルを慎重に管理してください。

    # インスタンスがデプロイされるリージョン。デフォルト値 "ap-southeast-1" はシンガポールに対応します。
    variable "region_id" {
      type    = string
      default = "ap-southeast-1"
    }
    # Anti-DDoS Proxy インスタンスの名前。
    variable "ddoscoo_instance_name" {
      description = "The name of the Anti-DDoS Proxy instance"
      type        = string
      default     = "Ddoscoo-spm-fofo"  # デフォルト値。
    }
    # (必須) インスタンスのポート転送ルールの数。値は 50 以上である必要があります。55、60、65 のように 5 刻みで値を増やすことができます。スペックアップのみサポートされています。
    variable "port_count" {
      description = "Number of ports for the Anti-DDoS Proxy instance"
      type        = string
      default     = "50"  # デフォルト値。
    }
    # 0: 保険版、1: 無制限版、2: 中国本土アクセラレーションプラン、3: セキュア中国本土アクセラレーション (Sec-CMA) プラン。
    variable "product_plan" {
      description = "Product plan of the Anti-DDoS Proxy instance"
      type        = string
      default     = "0"
    }
    # (必須) インスタンスのドメイン転送ルールの数。値は 50 以上である必要があります。55、60、65 のように 5 刻みで値を増やすことができます。スペックアップのみサポートされています。
    variable "domain_count" {
      description = "Number of domains for the Anti-DDoS Proxy instance"
      type        = string
      default     = "50"  # デフォルト値。
    }
    # サブスクリプション期間。
    variable "period" {
      description = "Purchase period of the Anti-DDoS Proxy instance"
      type        = string
      default     = "1"  # デフォルト値。
    }
    # プロダクトタイプ。
    variable "product_type" {
      description = "Product type of the Anti-DDoS Proxy instance"
      type        = string
      default     = "ddoscoo_intl"  # 中国本土以外のインスタンスには "ddoscoo_intl" を使用します。
    }
    # 課金方法。
    variable "pricing_mode" {
      description = "Pricing mode of the Anti-DDoS Proxy instance (Prepaid or Postpaid)"
      type        = string
      default     = "Postpaid"  # デフォルト値。
    }
    # インスタンスが提供するクリーン帯域幅。
    variable "bandwidth" {
      description = "Clean bandwidth provided by the instance"
      type        = number
      default     = 100
    }
    # インスタンスが提供する秒間クエリ数 (QPS)。
    variable "normal_qps" {
      description = "Normal QPS provided by the instance, valid only for security_acceleration"
      type        = number
      default     = 500
    }
    # 関数バージョン。有効な値: 0。標準機能プランを示します。
    variable "function_version" {
      description = "Function version of the instance, valid only for security_acceleration"
      type        = number
      default     = 0
    }
    provider "alicloud" {
      region = var.region_id
    }
    resource "alicloud_ddoscoo_instance" "newInstance" {
      name             = var.ddoscoo_instance_name
      port_count       = var.port_count
      domain_count     = var.domain_count
      period           = var.pricing_mode == "Prepaid" ? var.period : null
      product_type     = var.product_type
      product_plan     = var.product_plan
      function_version = var.function_version
      bandwidth        = var.bandwidth
    }
    output "instance_id" {
      description = "The ID of the Anti-DDoS Proxy instance"
      value       = alicloud_ddoscoo_instance.newInstance.id
    }
    output "instance_name" {
      description = "The name of the Anti-DDoS Proxy instance"
      value       = var.ddoscoo_instance_name
    }
  2. terraform init コマンドを実行して Terraform を初期化します。

  3. 期待される出力:

    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.
  4. terraform plan コマンドを実行して実行計画を生成します。

期待される出力:

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # alicloud_ddoscoo_instance.newInstance will be created
  + resource "alicloud_ddoscoo_instance" "newInstance" {
      + id           = (known after apply)
      + name         = "Ddoscoo-spm-fofo"
      + product_type = "ddoscoo_intl"
      # ...
    }

Plan: 1 to add, 0 to change, 0 to destroy.
  1. terraform apply コマンドを実行します。プロンプトが表示されたら、yes と入力し、Enter キーを押します。以下の出力が表示されれば、操作は成功です。

期待される出力:

alicloud_ddoscoo_instance.newInstance: Creating...
alicloud_ddoscoo_instance.newInstance: Creation complete after 1s [id=ddoscoo-ap-southeast-1-xxxxxxxxx]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Outputs:

instance_id = "ddoscoo-ap-southeast-1-xxxxxxxxx"
instance_name = "Ddoscoo-spm-fofo"
  1. 結果の確認

CLI

次のコマンドを実行して、Terraform で作成されたリソースの詳細を照会できます。

terraform show
# alicloud_ddoscoo_instance.newInstance:
resource "alicloud_ddoscoo_instance" "newInstance" {
    bandwidth        = "100"
    base_bandwidth   = "100"
    domain_count     = "50"
    id               = "ddoscoo-ap-southeast-1-xxxxxxxxx"
    name             = "Ddoscoo-spm-fofo"
    period           = 1
    port_count       = "50"
    product_type     = "ddoscoo_intl"
    service_bandwidth = "100"
}
Outputs:
instance_id = "ddoscoo-ap-southeast-1-xxxxxxxxx"
instance_name = "Ddoscoo-spm-fofo"

コンソール

Anti-DDoS Proxy コンソールにログインして、作成されたインスタンスを表示します。

上部のナビゲーションバーで、[中国本土以外] リージョンを選択します。左側のナビゲーションウィンドウで、[資産管理] > [インスタンス管理] を選択します。表示されたページで、作成されたインスタンスの仕様とステータスを確認できます。仕様には、保護プラン、基本帯域幅、拡張帯域幅、秒間クエリ数 (QPS)、接続制限が含まれます。

完全なコード例

説明

このトピックのサンプルコードはワンクリックで実行できます。ワンクリックで実行

# インスタンスがデプロイされるリージョン。デフォルト値 "ap-southeast-1" はシンガポールに対応します。
variable "region_id" {
  type    = string
  default = "ap-southeast-1"
}
# Anti-DDoS Proxy インスタンスの名前。
variable "ddoscoo_instance_name" {
  description = "The name of the Anti-DDoS Proxy instance"
  type        = string
  default     = "Ddoscoo-spm-fofo"  # デフォルト値。
}
# (必須) インスタンスのポート転送ルールの数。値は 50 以上である必要があります。55、60、65 のように 5 刻みで値を増やすことができます。スペックアップのみサポートされています。
variable "port_count" {
  description = "Number of ports for the Anti-DDoS Proxy instance"
  type        = string
  default     = "50"  # デフォルト値。
}
# 0: 保険版、1: 無制限版、2: 中国本土アクセラレーションプラン、3: セキュア中国本土アクセラレーション (Sec-CMA) プラン。
variable "product_plan" {
  description = "Product plan of the Anti-DDoS Proxy instance"
  type        = string
  default     = "0"
}
# (必須) インスタンスのドメイン転送ルールの数。値は 50 以上である必要があります。55、60、65 のように 5 刻みで値を増やすことができます。スペックアップのみサポートされています。
variable "domain_count" {
  description = "Number of domains for the Anti-DDoS Proxy instance"
  type        = string
  default     = "50"  # デフォルト値。
}
# サブスクリプション期間。
variable "period" {
  description = "Purchase period of the Anti-DDoS Proxy instance"
  type        = string
  default     = "1"  # デフォルト値。
}
# プロダクトタイプ。
variable "product_type" {
  description = "Product type of the Anti-DDoS Proxy instance"
  type        = string
  default     = "ddoscoo_intl"  # 中国本土以外のインスタンスには "ddoscoo_intl" を使用します。
}
# 課金方法。
variable "pricing_mode" {
  description = "Pricing mode of the Anti-DDoS Proxy instance (Prepaid or Postpaid)"
  type        = string
  default     = "Postpaid"  # デフォルト値。
}
# インスタンスが提供するクリーン帯域幅。
variable "bandwidth" {
  description = "Clean bandwidth provided by the instance"
  type        = number
  default     = 100
}
# インスタンスが提供する秒間クエリ数 (QPS)。
variable "normal_qps" {
  description = "Normal QPS provided by the instance, valid only for security_acceleration"
  type        = number
  default     = 500
}
# 関数バージョン。有効な値: 0。標準機能プランを示します。
variable "function_version" {
  description = "Function version of the instance, valid only for security_acceleration"
  type        = number
  default     = 0
}
provider "alicloud" {
  region = var.region_id
}
resource "alicloud_ddoscoo_instance" "newInstance" {
  name             = var.ddoscoo_instance_name
  port_count       = var.port_count
  domain_count     = var.domain_count
  period           = var.pricing_mode == "Prepaid" ? var.period : null
  product_type     = var.product_type
  product_plan     = var.product_plan
  function_version = var.function_version
  bandwidth        = var.bandwidth
}
output "instance_id" {
  description = "The ID of the Anti-DDoS Proxy instance"
  value       = alicloud_ddoscoo_instance.newInstance.id
}
output "instance_name" {
  description = "The name of the Anti-DDoS Proxy instance"
  value       = var.ddoscoo_instance_name
}

関連ドキュメント