All Products
Search
Document Center

Cloud Firewall:Create an address book

Last Updated:Mar 31, 2026

Use the alicloud_cloud_firewall_address_book Terraform resource to create and manage address books in Cloud Firewall as infrastructure as code.

Run the sample code in this topic with a few clicks in Terraform Explorer.

Prerequisites

Before you begin, make sure 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 exposed. See Create a RAM user and Create an AccessKey pair.

  • The following RAM policy attached to the RAM user. See Grant permissions to RAM users.

    {
        "Version": "1",
        "Statement": [
            {
                "Effect": "Allow",
                "Action": [
                    "yundun-cloudfirewall:*",
                    "yundun-ndr:*"
                ],
                "Resource": "*"
            }
        ]
    }
  • Terraform version 0.12.28 or later. Run terraform --version to check. Choose a setup option:

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

Resource

alicloud_cloud_firewall_address_book creates an address book in Cloud Firewall.

Parameters

ParameterRequiredTypeDescription
group_nameYesStringName of the address book
group_typeYesStringType of the address book. Valid values: ip, ipv6, domain, port, tag.
descriptionNoStringDescription of the address book
address_listNoListIP addresses or CIDRs to include in the address book
auto_add_tag_ecsNoIntWhether to automatically add ECS instances with matching tags. Set to 1 to enable. Default: 0.

Create an address book

  1. Create a working directory and a main.tf configuration file. This file defines the resources Terraform deploys.

    resource "alicloud_cloud_firewall_address_book" "example" {
      # Description of the address book
      description  = "Created_by_terraform"
      # Name of the address book
      group_name   = "IPListExample"
      # Type of the address book: ip, ipv6, domain, port, or tag
      group_type   = "ip"
      # IP addresses to include
      address_list = ["192.0.2.1/32", "192.0.2.2/32"]
    }
  2. Initialize Terraform. This downloads the Alibaba Cloud provider plugin defined in your configuration.

    terraform init

    The output confirms initialization is complete:

    Initializing provider plugins...
    - Finding latest version of hashicorp/alicloud...
    - Installing hashicorp/alicloud v1.231.0...
    - Installed hashicorp/alicloud v1.231.0 (signed by HashiCorp)
    
    Terraform has created a lock file .terraform.lock.hcl to record the provider
    selections it made above. Include this file in your version control repository
    so that Terraform can guarantee to make the same selections by default when
    you run "terraform init" in the future.
    
    Terraform has been successfully initialized!
  3. Preview the changes Terraform will make before applying them.

    terraform plan
  4. Create the address book.

    terraform apply

    When prompted, enter yes and press Enter. The output confirms the address book is created:

    Plan: 1 to add, 0 to change, 0 to destroy.
    
    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
    
    alicloud_cloud_firewall_address_book.example: Creating...
    alicloud_cloud_firewall_address_book.example: Creation complete after 1s [id=d41518ef-0437-44e9-9dd6-86d62f3d0***]
    
    Apply complete!  Resources: 1 added, 0 changed, 0 destroyed.

Verify the address book

Option 1: Use terraform show

terraform show

The output displays the full state of the created resource, including its assigned ID:

# alicloud_cloud_firewall_address_book.example:
resource "alicloud_cloud_firewall_address_book" "example" {
    address_list     = [
        "192.0.2.1/32",
        "192.0.2.2/32",
    ]
    auto_add_tag_ecs = 0
    description      = "Created_by_terraform"
    group_name       = "IPListExample"
    group_type       = "ip"
    id               = "d41518ef-0437-44e9-9dd6-86d62f3d****"
}

Option 2: Use the Cloud Firewall console

Log on to the Cloud Firewall console. Go to Cloud Firewall consolePrevention Configuration > Address Books and search by the address book name.

Exported attributes

After creation, Terraform exports the following attribute:

AttributeDescription
idThe unique ID of the address book (UUID format)

Clean up

To delete the address book created by Terraform, run:

terraform destroy

For details on this command, see Common Terraform commands.

Complete sample code

Run this sample with a few clicks in Terraform Explorer.
resource "alicloud_cloud_firewall_address_book" "example" {
  # Description of the address book
  description  = "Created_by_terraform"
  # Name of the address book
  group_name   = "IPListExample"
  # Type of the address book: ip, ipv6, domain, port, or tag
  group_type   = "ip"
  # IP addresses to include
  address_list = ["192.0.2.1/32", "192.0.2.2/32"]
}