All Products
Search
Document Center

Cloud Firewall:Activate Cloud Firewall

Last Updated:Mar 31, 2026

Activate Cloud Firewall programmatically using the alicloud_cloud_firewall_instance Terraform resource.

Run this example directly in Terraform Explorer without any local setup.

Prerequisites

Before you begin, ensure that you have:

  • A Resource Access Management (RAM) user with an AccessKey pair. Using a RAM user instead of your Alibaba Cloud root account limits the blast radius if credentials are compromised. See Create a RAM user and Create an AccessKey pair.

  • The following permissions attached to the RAM user — the Cloud Firewall permissions to manage firewall instances, and AliyunBSSFullAccess to handle subscription billing through BSS OpenAPI:

    {
        "Version": "1",
        "Statement": [
            {
                "Effect": "Allow",
                "Action": [
                    "yundun-cloudfirewall:CreateFirewall",
                    "yundun-cloudfirewall:DescribeFirewalls",
                    "yundun-cloudfirewall:DeleteFirewall"
                ],
                "Resource": "*"
            },
            {
                "Effect": "Allow",
                "Action": [
                    "bssapi:*",
                    "bss:*"
                ],
                "Resource": "*"
            }
        ]
    }
  • Terraform 0.12.28 or later. Verify with terraform --version.

  • A Terraform environment set up using one of these options:

    OptionBest for
    Terraform ExplorerQuick testing with no local installation
    Cloud ShellFast setup with credentials pre-configured
    Local installationCustom environments or restricted network access
Important

Activating Cloud Firewall incurs charges. Unsubscribe from the service when you no longer need it. For subscription billing, terraform destroy does not unsubscribe — see Release resources.

Terraform resource

alicloud_cloud_firewall_instance: activates Cloud Firewall.

Arguments

ArgumentDescription
payment_typeBilling method. Valid values: Subscription, PayAsYouGo.
specEdition. Valid values: premium_version, enterprise_version, ultimate_version.
ip_numberNumber of public IP addresses to protect. Valid values: 20–4000.
band_widthPeak Internet traffic to protect, in Mbit/s. Valid values: 10–15000.
cfw_logWhether to enable the audit log feature. Valid values: true, false.
cfw_log_storageLog storage capacity. Ignored if cfw_log is false.
periodSubscription period in months. Valid values: 1, 3, 6, 12, 24, 36.
The cfw_service argument was removed in provider version 1.209.1 and is no longer supported.

Attributes exported after apply

After terraform apply, the following attributes are available for use in other resources:

AttributeDescription
idThe instance ID, in the format vipcloudfw-cn-xxxxxxxx.
create_timeThe time the instance was created.
end_timeThe subscription end time.
release_timeThe release time of the instance.
renewal_duration_unitThe unit for the renewal duration.
renewal_statusThe renewal status of the instance.
statusThe current status of the instance.

Activate Cloud Firewall

  1. Create a working directory and a main.tf file with the following configuration:

    resource "alicloud_cloud_firewall_instance" "example" {
      # Billing method. Valid values: Subscription, PayAsYouGo.
      payment_type    = "Subscription"
      # Edition. Valid values: premium_version, enterprise_version, ultimate_version.
      spec            = "premium_version"
      # Number of public IP addresses to protect. Valid values: 20-4000.
      ip_number       = 20
      # Peak Internet traffic to protect in Mbit/s. Valid values: 10-15000.
      band_width      = 10
      # Enable audit log. Valid values: true, false.
      cfw_log         = false
      # Log storage capacity. Ignored when cfw_log is false.
      cfw_log_storage = 1000
      # Subscription period in months. Valid values: 1, 3, 6, 12, 24, 36.
      period          = 1
    }
  2. Initialize Terraform:

    terraform init

    A successful initialization ends with:

    Terraform has been successfully initialized!
  3. Preview the changes:

    terraform plan
  4. Apply the configuration:

    terraform apply

    Enter yes when prompted. A successful run ends with:

    alicloud_cloud_firewall_instance.example: Creating...
    alicloud_cloud_firewall_instance.example: Creation complete after 4s [id=vipcloudfw-cn-x0r36mo****]
    
    Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Verify the result

Run Terraform show

Query the resources managed by Terraform:

terraform show
image

Check the Cloud Firewall console

Log on to the Cloud Firewall console. On the Cloud Firewall consoleOverview page, click Upgrade

Release resources

Important

For subscription billing, terraform destroy removes the instance from the Terraform state file but does not unsubscribe from Cloud Firewall. After running terraform destroy, log on to the Cloud Firewall console and manually unsubscribe.

Complete sample code

Run this example with a few clicks in Terraform Explorer.
resource "alicloud_cloud_firewall_instance" "example" {
  # Billing method. Valid values: Subscription, PayAsYouGo.
  payment_type    = "Subscription"
  # Edition. Valid values: premium_version, enterprise_version, ultimate_version.
  spec            = "premium_version"
  # Number of public IP addresses to protect. Valid values: 20-4000.
  ip_number       = 20
  # Peak Internet traffic to protect in Mbit/s. Valid values: 10-15000.
  band_width      = 10
  # Enable audit log. Valid values: true, false.
  cfw_log         = false
  # Log storage capacity. Ignored when cfw_log is false.
  cfw_log_storage = 1000
  # Subscription period in months. Valid values: 1, 3, 6, 12, 24, 36.
  period          = 1
}