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

Cloud Firewall:VPCファイアウォールの特定のポリシーグループにアクセス制御ポリシーを作成する

最終更新日:Aug 14, 2024

このトピックでは、Terraformを使用して、仮想プライベートクラウド (VPC) ファイアウォールの特定のポリシーグループにアクセス制御ポリシーを作成する方法について説明します。

使用上の注意

前提条件

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

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

手順

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

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

    provider "alicloud" {
      version = "~> 1.203.0"
    }
    
    resource "alicloud_cloud_firewall_vpc_firewall_control_policy" "default" {
      order            = "1"
      destination      = "192.XX.XX.2/32"
      application_name = "ANY"
      description      = "Created_by_Terraform"
      source_type      = "net"
      dest_port        = "80/88"
      acl_action       = "accept"
      lang             = "zh"
      destination_type = "net"
      source           = "192.XX.XX.1/32"
      dest_port_type   = "port"
      proto            = "TCP"
      release          = true
      member_uid       = "141518928482****"
      vpc_firewall_id  = "vfw-d7b8ce273791475b****"
    }

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

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

    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_vpc_firewall_control_policy.default will be created
      + resource "alicloud_cloud_firewall_vpc_firewall_control_policy" "default" {
          + acl_action              = "accept"
          + acl_uuid                = (known after apply)
          + application_id          = (known after apply)
          + application_name        = "ANY"
          + description             = "Created_by_Terraform"
          + dest_port               = "80/88"
          + dest_port_group_ports   = (known after apply)
          + dest_port_type          = "port"
          + destination             = "192.XX.XX.2/32"
          + destination_group_cidrs = (known after apply)
          + destination_group_type  = (known after apply)
          + destination_type        = "net"
          + hit_times               = (known after apply)
          + id                      = (known after apply)
          + lang                    = "zh"
          + member_uid              = "141518928482****"
          + order                   = 1
          + proto                   = "TCP"
          + release                 = true
          + source                  = "192.XX.XX.1/32"
          + source_group_cidrs      = (known after apply)
          + source_group_type       = (known after apply)
          + source_type             = "net"
          + vpc_firewall_id         = "vfw-d7b8ce273791475b****"
        }
    
    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_vpc_firewall_control_policy.default: Creating...
    alicloud_cloud_firewall_vpc_firewall_control_policy.default: Creation complete after 2s [id=vfw-d7b8ce273791475b****:ba164e52-acd2-4899-bf72-6816b13a****]
    
    Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

    コードの実行後、IDがba164e52-acd2-4899-bf72-6816b13a **** であるVPCファイアウォールに対して、IDがvfw-d7b8ce273791475b **** であるアクセス制御ポリシーが作成されます。

  2. 結果を表示します。

    • terraform showコマンドを実行して、アクセス制御ポリシーの詳細を表示します。

      # alicloud_cloud_firewall_vpc_firewall_control_policy.default:
      resource "alicloud_cloud_firewall_vpc_firewall_control_policy" "default" {
          acl_action              = "accept"
          acl_uuid                = "ba164e52-acd2-4899-bf72-6816b13a****"
          application_id          = "0"
          application_name        = "ANY"
          description             = "Created_by_Terraform"
          dest_port               = "80/88"
          dest_port_group_ports   = []
          dest_port_type          = "port"
          destination             = "192.XX.XX.2/32"
          destination_group_cidrs = []
          destination_type        = "net"
          hit_times               = 0
          id                      = "vfw-d7b8ce273791475b****:ba164e52-acd2-4899-bf72-6816b13a****"
          lang                    = "zh"
          member_uid              = "1415189284827****"
          order                   = 1
          proto                   = "TCP"
          release                 = true
          source                  = "192.XX.XX..1/32"
          source_group_cidrs      = []
          source_type             = "net"
          vpc_firewall_id         = "vfw-d7b8ce273791475b****"
      }
    • Cloud Firewallコンソールにログインし、[アクセス制御] > [VPCボーダー] ページに移動します。 [VPC Border] ページで、アクセス制御ポリシーの詳細を表示します。