Terraformを使用して、Anti-DDoS Proxyインスタンスを購入および管理できます。 このトピックでは、Anti-DDoS Proxyインスタンスを取得する手順について説明します。
セットアップ
侵害されたAlibaba Cloudアカウントに関連するリスクを軽減するために、RAMユーザーを使用し、そのユーザーのAccessKeyペアを作成することをお勧めします。 詳細については、「RAMユーザーの作成」および「AccessKeyペアの作成」をご参照ください。
次のポリシーをRAMユーザーに割り当てて、この例ではリソースを管理するための最小限の権限を付与します。 詳細については、「RAM ユーザーへの権限の付与」をご参照ください。
このポリシーでは、RAMロールの作成、表示、削除、およびRAMロールのアクセス許可の管理が可能です。
{ "Statement": [ { "Action": [ "ddosprotection:CreateInstance", "ddosprotection:DeleteInstance" ], "Effect": "Allow", "Resource": "*" } ], "Version": "1" }
次のいずれかの方法を使用して、Terraformのランタイム環境を設定します。
Terraform ExplorerでTerraformを使用する: Alibaba Cloudが提供するTerraform Explorerを使用すると、開発者はインストールなしでTerraformをオンラインで実行できます。 この方法は、Terraformを無料で効率的かつ便利に使用およびデバッグするのに理想的です。
TerraformをCloud Shellで使用する: Alibaba Cloud Cloud Shellには、Terraformと設定されたID資格情報がプリインストールされており、Terraformコマンドを直接実行できます。 この方法は、Terraformを効率的に、便利に、低コストで使用およびデバッグするのに理想的です。
Terraformのインストールと設定: この方法は、ネットワーク接続が不十分なシナリオやカスタム開発環境が必要な場合に最適です。
必要なリソース
alicloud_ddosco_instance: このリソースは、Anti-DDoSインスタンスの作成に使用されます。
手順
作業ディレクトリを作成し、
main.tf
という名前の構成ファイルを追加して、デプロイするリソースを定義します。main.tf: デプロイ用のリソースを指定するプライマリTerraformファイル。 次のガイドでは、Anti-DDoS Proxy (Outside Chinese Mainland) インスタンスの取得に焦点を当てています。
重要Terraformを使用してAnti-DDoS Proxy (Outside Chinese Mainland) インスタンスをデプロイする場合、Terraformを使用してインスタンスを破棄できないことに注意してください。 したがって、不必要な費用を防ぐために、インスタンスのライフサイクルを慎重に管理する必要があります。
# Region variable "region_id" { type = string default = "ap-southeast-1" # Change to Singapore } # DDoS CoO instance name variable "ddoscoo_instance_name" { description = "The name of the DDoS CoO instance" type = string default = "Ddoscoo-spm-fofo" # Default value } # Number of ports (Required): The number of port forwarding rules for the instance. At least 50. Increase by 5 each time, such as 55, 60, 65. Only upgrades are supported. variable "port_count" { description = "Number of ports for the DDoS CoO instance" type = string default = "50" # Default value } # 0: Insurance Plan #1: Unlimited Plan #2: CMA Plan #3: Secure Chinese mainland acceleration (Sec-CMA) Plan. variable "product_plan" { description = "Product plan of the DDoS CoO instance" type = string default = "0" } # Number of domains (Required): The number of domain forwarding rules for the instance. At least 50. Increase by 5 each time, such as 55, 60, 65. Only upgrades are supported. variable "domain_count" { description = "Number of domains for the DDoS CoO instance" type = string default = "50" # Default value } # Purchase period variable "period" { description = "Purchase period of the DDoS CoO instance" type = string default = "1" # Default value } # Product type variable "product_type" { description = "Product type of the DDoS CoO instance" type = string default = "ddosDip" # International version ddoscoo_intl } # Billing method variable "pricing_mode" { description = "Pricing mode of the DDoS CoO instance (Prepaid or Postpaid)" type = string default = "Postpaid" # Default value } # Clean bandwidth Clean bandwidth provided by the instance variable "normal_bandwidth" { description = "Clean bandwidth provided by the instance, valid only when product_type is ddosDip" type = number default = 100 } # Queries per second: Clean QPS provided by the instance variable "normal_qps" { description = "Normal QPS provided by the instance, valid only for security_acceleration" type = number default = 500 } # Function version: Standard function plan variable "function_version" { description = "Function version of the instance, valid only for security_acceleration" type = number default = 0 } provider "alicloud" { region = var.region_id } resource "alicloud_ddoscoo_instance" "newInstance" { name = var.ddoscoo_instance_name port_count = var.port_count domain_count = var.domain_count period = var.pricing_mode == "Prepaid" ? var.period : null product_type = var.product_type product_plan = var.product_plan function_version = var.function_version normal_bandwidth = var.normal_bandwidth } output "instance_id" { description = "The ID of the DDoS CoO instance" value = alicloud_ddoscoo_instance.newInstance.id } output "instance_name" { description = "The name of the DDoS CoO instance" value = var.ddoscoo_instance_name }
Terraform init
コマンドを実行してterraformを初期化します。期待される出力:
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.
terraform plan
コマンドを実行して、リソースプランを生成します。
期待される結果
alicloud_ddoscoo_instance.newInstance: Refreshing state... [id=ddoscoo-cn-20s3zrc4k001]
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
~ update in-place
Terraform will perform the following actions:
# alicloud_ddoscoo_instance.newInstance will be updated in-place
~ resource "alicloud_ddoscoo_instance" "newInstance" {
id = "ddoscoo-cn-20**********""
~ name = "yourDdoscooInstanceName" -> "Ddoscoo"
# (7 unchanged attributes hidden)
}
Plan: 0 to add, 1 to change, 0 to destroy.
Changes to Outputs:
+ instance_id = "ddoscoo-cn-**********"
+ instance_name = "Ddoscoo"
terraform apply
コマンドを実行し、プロンプトが表示されたらyes
と入力し、Enterをクリックします。 コマンドが実行されるのを待ちます。 次のメッセージが表示された場合、承認は完了です。
期待される結果
alicloud_ddoscoo_instance.newInstance: Modifying... [id=ddoscoo-cn-*********]
alicloud_ddoscoo_instance.newInstance: Modifications complete after 1s [id=ddoscoo-cn-*********]
Apply complete! Resources: 0 added, 1 changed, 0 destroyed.
Outputs:
instance_id = "ddoscoo-cn-*********"
instance_name = "Ddoscoo"
操作を確認します。
terraform showコマンドを実行します。
Terraformによって作成されたリソースの詳細を表示するには、次のコマンドを実行します。
terraform show
Anti-DDoSプロキシ (中国本土外) コンソール
Anti-DDoS Proxy (Outside Chinese Mainland) コンソールにアクセスして、作成したインスタンスを表示します。
完全なコード例
# Region
variable "region_id" {
type = string
default = "ap-southeast-1" # Change to Singapore
}
# DDoS CoO instance name
variable "ddoscoo_instance_name" {
description = "The name of the DDoS CoO instance"
type = string
default = "Ddoscoo-spm-fofo" # Default value
}
# Number of ports (required): The number of port forwarding rules for the instance. At least 50. Increase by 5 each time, such as 55, 60, 65. Only upgrades are supported.
variable "port_count" {
description = "Number of ports for the DDoS CoO instance"
type = string
default = "50" # Default value
}
# 0: Insurance plan #1: Unlimited plan #2: CMA plan #3: Secure Chinese mainland acceleration (Sec-CMA) plan.
variable "product_plan" {
description = "Product plan of the DDoS CoO instance"
type = string
default = "0"
}
# Number of domains (required): The number of domain forwarding rules for the instance. At least 50. Increase by 5 each time, such as 55, 60, 65. Only upgrades are supported.
variable "domain_count" {
description = "Number of domains for the DDoS CoO instance"
type = string
default = "50" # Default value
}
# Purchase period
variable "period" {
description = "Purchase period of the DDoS CoO instance"
type = string
default = "1" # Default value
}
# Product type
variable "product_type" {
description = "Product type of the DDoS CoO instance"
type = string
default = "ddosDip" # International version ddoscoo_intl
}
# Billing method
variable "pricing_mode" {
description = "Pricing mode of the DDoS CoO instance (Prepaid or Postpaid)"
type = string
default = "Postpaid" # Default value
}
# Clean bandwidth: Clean bandwidth provided by the instance
variable "normal_bandwidth" {
description = "Clean bandwidth provided by the instance, valid only when product_type is ddosDip"
type = number
default = 100
}
# Queries per second: Clean QPS provided by the instance
variable "normal_qps" {
description = "Normal QPS provided by the instance, valid only for security_acceleration"
type = number
default = 500
}
# Function version: Standard function plan
variable "function_version" {
description = "Function version of the instance, valid only for security_acceleration"
type = number
default = 0
}
provider "alicloud" {
region = var.region_id
}
resource "alicloud_ddoscoo_instance" "newInstance" {
name = var.ddoscoo_instance_name
port_count = var.port_count
domain_count = var.domain_count
period = var.pricing_mode == "Prepaid" ? var.period : null
product_type = var.product_type
product_plan = var.product_plan
function_version = var.function_version
normal_bandwidth = var.normal_bandwidth
}
output "instance_id" {
description = "The ID of the DDoS CoO instance"
value = alicloud_ddoscoo_instance.newInstance.id
}
output "instance_name" {
description = "The name of the DDoS CoO instance"
value = var.ddoscoo_instance_name
}
関連ドキュメント
Terraformの詳細については、Terraformとは何ですか?