All Products
Search
Document Center

Anti-DDoS:Purchase and manage Anti-DDoS Proxy with Terraform

Last Updated:Aug 31, 2026

You can use Terraform to purchase and manage Anti-DDoS Proxy instances. This topic provides an example of how to purchase an Anti-DDoS Proxy instance.

Note

You can run the sample code in this topic in one click. Run with one click

Prerequisites

  • An Alibaba Cloud account has full permissions on all resources. If the account is compromised, it poses significant security risks. We recommend that you use a RAM user and create an AccessKey for the RAM user. For more information, see Create a RAM user and Create an AccessKey.

  • Attach the following minimum required policy to the RAM user that runs Terraform commands to obtain the permissions required to manage the resources in this example. For more information, see Manage RAM user permissions.

    This policy allows the RAM user to create and delete Anti-DDoS Proxy instances.

    {
      "Statement": [
        {
          "Action": [
            "ddosprotection:CreateInstance",
            "ddosprotection:DeleteInstance"
          ],
          "Effect": "Allow",
          "Resource": "*"
        }
      ],
      "Version": "1"
    }
  • Prepare a Terraform runtime environment. You can use one of the following methods:

Resources

Procedure

  1. Create a working directory and a configuration file named main.tf inside it.

    main.tf: The main Terraform file that defines the resources to deploy. The example shows how to purchase an Anti-DDoS Proxy (Outside Chinese Mainland) instance.

    Important

    Note that Anti-DDoS Proxy (Outside Chinese Mainland) instances created with Terraform cannot be destroyed by Terraform. To avoid unnecessary costs, carefully manage the instance lifecycle.

    # The region where the instance is deployed. The default value "ap-southeast-1" corresponds to Singapore.
    variable "region_id" {
      type    = string
      default = "ap-southeast-1"
    }
    # The name of the Anti-DDoS Proxy instance.
    variable "ddoscoo_instance_name" {
      description = "The name of the Anti-DDoS Proxy instance"
      type        = string
      default     = "Ddoscoo-spm-fofo"  # The default value.
    }
    # (Required) The number of port forwarding rules for the instance. The value must be at least 50. You can increase the value in increments of 5, such as 55, 60, and 65. Only upgrades are supported.
    variable "port_count" {
      description = "Number of ports for the Anti-DDoS Proxy instance"
      type        = string
      default     = "50"  # The default value.
    }
    # 0: Insurance Plan, 1: Unlimited Plan, 2: Chinese Mainland Acceleration Plan, 3: Secure Chinese Mainland Acceleration (Sec-CMA) Plan.
    variable "product_plan" {
      description = "Product plan of the Anti-DDoS Proxy instance"
      type        = string
      default     = "0"
    }
    # (Required) The number of domain forwarding rules for the instance. The value must be at least 50. You can increase the value in increments of 5, such as 55, 60, and 65. Only upgrades are supported.
    variable "domain_count" {
      description = "Number of domains for the Anti-DDoS Proxy instance"
      type        = string
      default     = "50"  # The default value.
    }
    # The subscription duration.
    variable "period" {
      description = "Purchase period of the Anti-DDoS Proxy instance"
      type        = string
      default     = "1"  # The default value.
    }
    # The product type.
    variable "product_type" {
      description = "Product type of the Anti-DDoS Proxy instance"
      type        = string
      default     = "ddoscoo_intl"  # Use "ddoscoo_intl" for instances outside Chinese mainland.
    }
    # The billing method.
    variable "pricing_mode" {
      description = "Pricing mode of the Anti-DDoS Proxy instance (Prepaid or Postpaid)"
      type        = string
      default     = "Postpaid"  # The default value.
    }
    # The clean bandwidth provided by the instance.
    variable "bandwidth" {
      description = "Clean bandwidth provided by the instance"
      type        = number
      default     = 100
    }
    # The number of queries per second (QPS) provided by the instance.
    variable "normal_qps" {
      description = "Normal QPS provided by the instance, valid only for security_acceleration"
      type        = number
      default     = 500
    }
    # The function version. Valid value: 0. Indicates the Standard Function Plan.
    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. Run the terraform init command to initialize Terraform.

  3. Expected output:

    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. Run the terraform plan command to generate an execution plan.

Expected output:

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. Run the terraform apply command. When prompted, enter yes and press Enter. The operation is successful if the following output is displayed.

Expected output:

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. Verify the results.

CLI

You can run the following command to query the details of the resources created by 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 (Outside Chinese Mainland) Console

Log on to the Anti-DDoS Proxy console, and select the Outside Chinese Mainland region at the top of the console. In the left-side navigation pane, click Assets > Instances to view the specifications and status of the created instance (including the protection plan version, normal business bandwidth, burstable bandwidth, QPS, and maximum connections).

Complete code example

Note

You can run the sample code in this topic in one click. Run with one click

# The region where the instance is deployed. The default value "ap-southeast-1" corresponds to Singapore.
variable "region_id" {
  type    = string
  default = "ap-southeast-1"
}
# The name of the Anti-DDoS Proxy instance.
variable "ddoscoo_instance_name" {
  description = "The name of the Anti-DDoS Proxy instance"
  type        = string
  default     = "Ddoscoo-spm-fofo"  # The default value.
}
# (Required) The number of port forwarding rules for the instance. The value must be at least 50. You can increase the value in increments of 5, such as 55, 60, and 65. Only upgrades are supported.
variable "port_count" {
  description = "Number of ports for the Anti-DDoS Proxy instance"
  type        = string
  default     = "50"  # The default value.
}
# 0: Insurance Plan, 1: Unlimited Plan, 2: Chinese Mainland Acceleration Plan, 3: Secure Chinese Mainland Acceleration (Sec-CMA) Plan.
variable "product_plan" {
  description = "Product plan of the Anti-DDoS Proxy instance"
  type        = string
  default     = "0"
}
# (Required) The number of domain forwarding rules for the instance. The value must be at least 50. You can increase the value in increments of 5, such as 55, 60, and 65. Only upgrades are supported.
variable "domain_count" {
  description = "Number of domains for the Anti-DDoS Proxy instance"
  type        = string
  default     = "50"  # The default value.
}
# The subscription duration.
variable "period" {
  description = "Purchase period of the Anti-DDoS Proxy instance"
  type        = string
  default     = "1"  # The default value.
}
# The product type.
variable "product_type" {
  description = "Product type of the Anti-DDoS Proxy instance"
  type        = string
  default     = "ddoscoo_intl"  # Use "ddoscoo_intl" for instances outside Chinese mainland.
}
# The billing method.
variable "pricing_mode" {
  description = "Pricing mode of the Anti-DDoS Proxy instance (Prepaid or Postpaid)"
  type        = string
  default     = "Postpaid"  # The default value.
}
# The clean bandwidth provided by the instance.
variable "bandwidth" {
  description = "Clean bandwidth provided by the instance"
  type        = number
  default     = 100
}
# The number of queries per second (QPS) provided by the instance.
variable "normal_qps" {
  description = "Normal QPS provided by the instance, valid only for security_acceleration"
  type        = number
  default     = 500
}
# The function version. Valid value: 0. Indicates the Standard Function Plan.
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
}

Related documentation