全部產品
Search
文件中心

Cloud Firewall:建立Cloud Firewall執行個體

更新時間:Jun 30, 2024

本文介紹如何使用Terraform建立互連網防火牆執行個體。

注意事項

  • Terraform運行環境:阿里雲Cloud Shell

  • Terraform版本:0.12

  • alicloud版本:1.203.0

  • resource定義:cloud_firewall_instance

前提條件

  • 已建立阿里雲帳號和存取金鑰(AccessKey)。具體操作,請參見建立AccessKey

  • 已經安裝並配置了Terraform。

建立防火牆執行個體

  1. 在Terraform執行目錄下的terraform.tf檔案中,配置如下內容。

    程式碼範例如下:

    provider "alicloud" {
      version = "~> 1.203.0"
    }
    
    resource "alicloud_cloud_firewall_instance" "example" {
      payment_type    = "Subscription"
      spec            = "premium_version"
      ip_number       = 20
      band_width      = 10
      cfw_log         = false
      cfw_log_storage = 1000
      cfw_service     = false
      period          = 6
    }

  1. 運行terraform init,對環境進行初始化。

    程式碼範例如下:

    Initializing the backend...
    
    Initializing provider plugins...
    - Checking for available provider plugins...
    - Downloading plugin for provider "alicloud" (hashicorp/alicloud) 1.203.0...
    
    
    Warning: registry.terraform.io: For users on Terraform 0.13 or greater, this provider has moved to aliyun/alicloud. Please update your source in required_providers.
    
    
    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.

  1. 運行terraform apply出現如下配置資訊後,確認配置資訊並輸入yes,開始建立。

    程式碼範例如下:

    An execution plan has been generated and is shown below.
    Resource actions are indicated with the following symbols:
      + create
    
    Terraform will perform the following actions:
    
      # alicloud_cloud_firewall_instance.example will be created
      + resource "alicloud_cloud_firewall_instance" "example" {
          + band_width            = 10
          + cfw_log               = false
          + cfw_log_storage       = 1000
          + cfw_service           = false
          + create_time           = (known after apply)
          + end_time              = (known after apply)
          + id                    = (known after apply)
          + ip_number             = 20
          + payment_type          = "Subscription"
          + period                = 6
          + release_time          = (known after apply)
          + renewal_duration_unit = (known after apply)
          + renewal_status        = (known after apply)
          + spec                  = "premium_version"
          + status                = (known after apply)
        }
    
    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_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.

    建立成功後,可以返回Cloud FirewallID為vipcloudfw-cn-x0r36mo****。

  2. 查看結果。

    • 運行terraform show查看Cloud Firewall執行個體的詳細資料。

      # alicloud_cloud_firewall_instance.example:
      resource "alicloud_cloud_firewall_instance" "example" {
          band_width            = 10
          cfw_log               = false
          cfw_log_storage       = 1000
          cfw_service           = false
          create_time           = "2023-04-21T01:38:58Z"
          end_time              = "2023-10-21T16:00:00Z"
          id                    = "vipcloudfw-cn-x0r36mo****"
          ip_number             = 20
          payment_type          = "Subscription"
          period                = 6
          renewal_duration_unit = "Month"
          renewal_status        = "ManualRenewal"
          spec                  = "premium_version"
          status                = "Normal"
      }
    • 登入Cloud Firewall控制台,在總覽頁面,單擊升級查看Cloud Firewall執行個體的當前配置。