All Products
Search
Document Center

ENS:Integrasi resource menggunakan Terraform

Last Updated:Jun 21, 2026

Terraform adalah alat open source yang memungkinkan Anda menyediakan dan mengelola infrastruktur cloud secara aman dan efisien. Anda dapat menggunakan Terraform untuk mengelola resource ENS. Topik ini menjelaskan cara menggunakan Terraform untuk membuat instans ENS.

Prosedur

Berikan izin yang diperlukan kepada pengguna RAM

Anda harus memberikan izin yang diperlukan kepada pengguna Resource Access Management (RAM) untuk mengeksekusi templat Terraform. Untuk itu, buat pengguna RAM, peroleh pasangan Kunci Akses (AccessKey pair), lalu sambungkan kebijakan izin ke pengguna tersebut. Pasangan Kunci Akses dikonfigurasi sebagai variabel lingkungan Terraform. Sambungkan kebijakan berikut ke pengguna RAM:

  • AliyunENSFullAccess: izin untuk mengelola resource ENS.

Akun Alibaba Cloud memiliki izin penuh atas semua operasi API. Namun, penggunaannya untuk memanggil operasi API berpotensi menimbulkan risiko keamanan. Kami menyarankan agar Anda menggunakan pengguna RAM untuk memanggil operasi API atau menjalankan tugas O&M rutin. Sebelum memanggil operasi API sebagai pengguna RAM, pastikan Anda telah memberikan izin yang sesuai dengan kebutuhan bisnis. Pengguna RAM tersebut harus memiliki izin untuk mengelola resource Edge Node Service. Untuk informasi selengkapnya, lihat Kebijakan sistem untuk ENS.

Instal Terraform

  • Untuk informasi lebih lanjut tentang cara menginstal dan mengonfigurasi Terraform di PC Anda, lihat Instal dan konfigurasi Terraform di PC lokal.

    Setelah Terraform terinstal, buka command-line interface (CLI) dan jalankan perintah terraform version. Jika informasi versi ditampilkan, berarti Terraform telah berhasil terinstal.

  • Jika Anda tidak ingin menginstal Terraform, gunakan Cloud Shell yang disediakan oleh Alibaba Cloud. Cloud Shell menyediakan lingkungan runtime bawaan untuk Terraform.

Buat templat

Buat file bernama eip.tf dan masukkan konten berikut ke dalam file tersebut untuk membuat instans.

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"
}

Jalankan templat

Pada contoh ini, langkah-langkah berikut dilakukan di Windows. Metode spesifik untuk menjalankan perintah mungkin berbeda pada sistem operasi lain.

  1. Inisialisasi dan muat modul yang diperlukan, seperti modul 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. Periksa apakah sintaks templat valid.

    terraform validate
    D:\Terraform>terraform validate
    Success! The configuration is valid.
  3. Buat rencana eksekusi.

    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. Terapkan templat.

    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. Masukkan yes untuk mengubah resource. Anda dapat menjalankan perintah terraform destroy untuk melepas resource yang dibuat dari templat.

    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. Setelah instans dibuat, panggil operasi API, gunakan SDK, atau login ke konsol ENS untuk melihat instans tersebut.

    Pada panel navigasi sebelah kiri konsol ENS, pilih Compute & Images > Instances. Di halaman Instances, pastikan status instans adalah running.