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

ENS:Terraform によるリソース統合

最終更新日:Jun 21, 2026

Terraform は、クラウドインフラストラクチャを安全かつ効率的にプロビジョニングおよび管理できるオープンソースツールで、ENS リソースの管理に使用できます。 このトピックでは、Terraform を使用して ENS インスタンスを作成する方法について説明します。

手順

RAM ユーザーへの必要な権限の付与

Terraform テンプレートを実行するために必要な権限を RAM ユーザーに付与する必要があります。RAM ユーザーを作成し、アクセスキーペアを取得してから、許可ポリシーを RAM ユーザーにアタッチする必要があります。アクセスキーペアは、Terraform の環境変数として設定されます。RAM ユーザーには、次のポリシーをアタッチする必要があります。

  • AliyunENSFullAccessENS リソースを管理するための権限。

Alibaba Cloud アカウントは、すべての API 操作に対する権限を持っています。 Alibaba Cloud アカウントを使用して API 操作を呼び出すと、セキュリティリスクが生じる可能性があります。 RAM ユーザーを使用して API 操作を呼び出すか、日常の O&M を実行することをお勧めします。 RAM ユーザーとして API 操作を呼び出す前に、ビジネス要件に基づいて、RAM ユーザーに必要な権限を付与してください。 RAM ユーザーには、Edge Node Serviceリソースを管理する権限が必要です。 詳細については、「ENS のシステムポリシー」をご参照ください。

Terraform のインストール

  • 詳細については、「ローカル PC に Terraform をインストールして設定する」をご参照ください。

    Terraform のインストール後、コマンドラインインターフェイス (CLI) を開いて terraform version と入力します。バージョン情報が返されれば、Terraform はインストールされています。

  • Terraform をインストールしたくない場合は、Alibaba Cloud が提供する Cloud Shell を使用してください。Cloud Shell は、Terraform 用の組み込みランタイム環境を提供します。

テンプレートの作成

eip.tf という名前のファイルを作成し、EIP を作成するために、ファイルに次の内容を入力します。

variable "name" {
  default = "terraform-example"
}
resource "alicloud_ens_eip" "default" {
  description   = "EipDescription_autotest"
  bandwidth     = "5"
  isp           = "cmcc"
  payment_type  = "PayAsYouGo"
  ens_region_id = "cn-chenzhou-telecom_unicom_cmcc"
  eip_name      = var.name
  internet_charge_type = "95BandwidthByMonth"
}

テンプレートの実行

この例では、次の手順を Windows で実行します。他のオペレーティングシステムでは、コマンドを実行する具体的な方法が異なる場合があります。

  1. Provider モジュールなどの必要なモジュールを初期化してロードします。

    terraform init
    D:\Terraform>terraform init
    Initializing the backend...
    Initializing provider plugins...
    - Reusing previous version of hashicorp/alicloud from the dependency lock file
    - Using previously-installed hashicorp/alicloud v1.226.0
    ╷
    │ Warning: Additional provider information from registry
    │
    │ The remote registry returned warnings for registry.terraform.io/hashicorp/alicloud:
    │ - 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.
    D:\Terraform>
  2. テンプレートの構文が有効かどうかを確認します。

    terraform validate
    D:\Terraform>terraform validate
    Success! The configuration is valid.
  3. 実行計画を作成します。

    terraform plan
    D:\Terraform>terraform plan
    Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
      + create
    Terraform will perform the following actions:
      # alicloud_ens_eip.default will be created
      + resource "alicloud_ens_eip" "default" {
          + bandwidth            = 5
          + create_time          = (known after apply)
          + description          = "EipDescription_autotest"
          + eip_name             = "terraform-example"
          + ens_region_id        = "cn-chenzhou-telecom_unicom_cmcc"
          + id                   = (known after apply)
          + internet_charge_type = "95BandwidthByMonth"
          + isp                  = "cmcc"
          + payment_type         = "PayAsYouGo"
          + status               = (known after apply)
        }
    Plan: 1 to add, 0 to change, 0 to destroy.
    Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run "terraform apply" now.
  4. テンプレートをデプロイします。

    terraform apply
    D:\Terraform>terraform apply
    Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
      + create
    Terraform will perform the following actions:
      # alicloud_ens_eip.default will be created
      + resource "alicloud_ens_eip" "default" {
          + bandwidth           = 5
          + create_time         = (known after apply)
          + description         = "EipDescription_autotest"
          + eip_name            = "terraform-example"
          + ens_region_id       = "cn-chenzhou-telecom_unicom_cmcc"
          + id                  = (known after apply)
          + internet_charge_type = "95BandwidthByMonth"
          + isp                 = "cmcc"
          + payment_type        = "PayAsYouGo"
          + 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.
  5. 「yes」と入力してリソースを変更します。terraform destroy コマンドを実行して、テンプレートから作成されたリソースを解放できます。

    alicloud_ens_eip.default: Creating...
    alicloud_ens_eip.default: Creation complete after 7s [id=eip-5xxxxxxxxxxxx]
    Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
  6. EIP の作成後、API オペレーションを呼び出すか、SDK を使用するか、または ENS コンソールにログインして EIP を表示します。

    ENS コンソールの左側のナビゲーションペインで、[Networking] > [EIP Address] を選択します。[EIP Address] ページで、新しく作成された EIP が表示されていることを確認します。