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

Cloud Firewall:アドレス帳の作成

最終更新日:Aug 14, 2024

このトピックでは、Terraformを使用してアドレス帳を作成する方法について説明します。

使用上の注意

  • Terraformランタイム環境: Alibaba Cloud Shell

  • Terraformバージョン: 0.12

  • alicloudバージョン: 1.203.0

  • リソース定義: cloud_firewall_address_book

前提条件

  • Alibaba CloudアカウントとAccessKeyペアが作成されます。 詳細については、「AccessKey の作成」をご参照ください。

  • Terraformがインストールされ、設定されます。

手順

  1. Terraformの実行ディレクトリで、terraform.tfファイルを設定します。

    以下にコードの例を示します。

    provider "alicloud" {
      version = "~> 1.203.0"
    }
    
    resource "alicloud_cloud_firewall_address_book" "example" {
      description      = "Created_by_terraform"
      group_name       = "IPListExample"
      group_type       = "ip"
      address_list     = ["192.0.2.1/32", "192.0.2.2/32"]
    }

  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コマンドを実行します。 次の情報が表示されたら、情報を確認し、はいと入力してアドレス帳を作成します。

    次のコードは例を提供します。 コードを実行すると、IDが1d89edf3-5711-41e6-b8dd-0c1ac080 **** のアドレス帳が作成されます。

    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_address_book.example will be created
      + resource "alicloud_cloud_firewall_address_book" "example" {
          + address_list = [
              + "192.0.2.1/32",
              + "192.0.2.2/32",
            ]
          + description  = "Created_by_terraform"
          + group_name   = "IPListExample"
          + group_type   = "ip"
          + id           = (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_address_book.example: Creating...
    alicloud_cloud_firewall_address_book.example: Creation complete after 2s [id=1d89edf3-5711-41e6-b8dd-0c1ac080****]

  2. 結果を表示します。

    • terraform showコマンドを実行して、アドレス帳の詳細を表示します。

      # 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               = "1d89edf3-5711-41e6-b8dd-0c1ac080****"
      }
    • Cloud Firewallコンソールにログインします。 [予防設定] > [アドレス帳] ページに移動します。 [アドレス帳] ページで、アドレス帳の名前を使用してアドレス帳を検索し、アドレス帳の詳細を表示します。