All Products
Search
Document Center

Edge Security Acceleration:Use Terraform to add DNS records for an ESA site

Last Updated:Jul 29, 2025

After you add a site to ESA, you must add DNS records for the site to manage its domain name within ESA. This process ensures that the accelerated domain name can be resolved and accessed. This topic describes how to use Terraform to add DNS records.

Resources involved

Note

You cannot use Terraform to create an Enterprise Edition plan. If you want to purchase an Enterprise Edition plan, please contact us.

Write configuration files

Create a working directory and the configuration files as described in the following sections. Then, modify the configurations in the code as needed.

Define the provider and Terraform version

First, create a configuration file named providers.tf and copy the following code to the file. This file is used to centrally manage all provider configurations and version constraints.

terraform {
  required_providers {
    alicloud = {
      source  = "aliyun/alicloud"
      version = "1.245.0"
    }
  }
}

Define resource variables

To improve code reusability, declare input variables and local variables. To do this, create a configuration file named variables.tf and copy the following code to the file.

# The connection type of the site. Valid values: CNAME and NS.
variable "site_type" {
  default = "NS"
}
# The billing method. The value must be Subscription. Other values are not supported.
variable "payment_type" {
  default = "Subscription"
}
# The area where the endpoint is deployed. Valid values:
# domestic (the Chinese mainland), overseas (global, excluding the Chinese mainland), and global (global).
variable "coverage_name" {
  default = "overseas"
}
# Specifies whether to enable auto-renewal.
variable "auto_pay" {
  default = "true"
}
# The valid values of the plan name are as follows:
# entranceplan_intl (Entrance Edition), basicplan_intl (Pro Edition), and vipplan_intl (Premium Edition).
variable "plan_name" {
  default = "entranceplan_intl"
}
# The site name. You must replace the value with your domain name.
variable "site_name" {
  default = "aliyundoc.com"
}
# The value of the origin server, which is your origin domain name.
variable "record_value" {
  default = "www.example.com"
}
# The port for origin fetch, which is the port number of your source port.
variable "record_port" {
  default = "80"
}
# The DNS record value, which is the accelerated domain name.
variable "record_name" {
  default = "_udp._sip.aliyundoc.com"
}
# The DNS record type.
variable "record_type" {
  default = "SRV"
}

Define resources

Finally, create a configuration file named main.tf and copy the following code to the file. This file serves as the main entry point for all resource declarations.

# Create a plan.
resource "alicloud_esa_rate_plan_instance" "my_plan" {
  type         = var.site_type
  auto_renew   = "false"
  period       = "1"
  payment_type = var.payment_type
  coverage     = var.coverage_name
  auto_pay     = var.auto_pay
  plan_name    = var.plan_name
}

# Create a site.
resource "alicloud_esa_site" "my_site" {
  site_name   = var.site_name
  instance_id = alicloud_esa_rate_plan_instance.my_plan.id
  coverage    = var.coverage_name
  access_type = var.site_type
}

# Add a DNS record.
resource "alicloud_esa_record" "my_record" {
  data {
    value    = var.record_value
    weight   = "1"
    priority = "1"
    port     = var.record_port
  }

  ttl         = "100"
  record_name = var.record_name
  comment     = "This is a remark"
  site_id     = alicloud_esa_site.my_site.id
  record_type = var.record_type
}

Create resources

  1. Run the following command to initialize the Terraform environment.

    terraform init
  2. Run the following command to validate the Terraform syntax and configuration.

    terraform validate

    If the output is the same as that shown in the following figure, the validation is successful.

    image

  3. Run the following command to preview the execution plan.

    terraform plan

    image

  4. Run the following command to apply the configuration.

    terraform apply

    image

Verify the results

View the plan

  1. Log on to the ESA console. In the navigation pane on the left, choose Billing Management > Plans.

  2. On the Plan Management page, you can view the new plan, as shown in the following figure.

    image

View the site

In the ESA console, choose Websites. You can view the new site, as shown in the following figure.

image

View DNS records

  1. In the ESA console, choose Websites, and click the name of the target site in the Website column.

  2. In the navigation pane on the left, choose DNS > Records. You can view the new DNS record, as shown in the following figure.

    image

(Optional) Clean up resources

If you no longer need the resources that are created or managed by Terraform, run the terraform destroy command to release the resources.

terraform destroy