Terraform配置常见问题

使用Terraform配置CDN时,如果遇到疑问请参考以下常见问题及处理建议。

如何在创建CDN加速域名时配置证书?

在使用alicloud_cdn_domain_new资源创建CDN加速域名时,可以通过设置 certificate_config 参数来配置证书。示例如下:

使用数字证书管理服务的证书
resource "alicloud_cdn_domain_new" "domain" {
  scope       = "overseas"
  domain_name = "mycdndomain-${random_integer.default.result}.alicloud-provider.cn"
  cdn_type    = "download"
  sources {
    type     = "ipaddr"
    content  = "1.1.x.x"
    priority = 20
    port     = 80
    weight   = 15
  }
  certificate_config {
    server_certificate_status = "on"
    cert_type  = "cas"
    cert_id    = "1111111"
    cert_region = "cn-hangzhou"
  }
}
手动上传证书
resource "alicloud_cdn_domain_new" "domain" {
  scope       = "overseas"
  domain_name = "mycdndomain-${random_integer.default.result}.alicloud-provider.cn"
  cdn_type    = "download"
  sources {
    type     = "ipaddr"
    content  = "1.1.x.x"
    priority = 20
    port     = 80
    weight   = 15
  }
  certificate_config {
    server_certificate_status = "on"
    cert_type          = "upload"
    cert_name          = "cert-xxxxxxxxx"
    server_certificate = "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----"
    private_key        = "-----BEGIN RSA PRIVATE KEY-----\n...\n-----END RSA PRIVATE KEY-----"
  }
}

配置证书后,证书状态是否需要手动开启?

不需要。只要填写了 certificate_config 参数块,默认会自动开启证书状态server_certificate_status = "on")。无需额外配置。

cert_type支持的证书类型有哪些?分别代表什么?

证书类型通过 cert_type 参数指定,支持两种类型:

  • upload:手动上传证书(需提供公钥和私钥,分别填写server_certificateprivate_key)。

  • cas:使用阿里云数字证书管理服务的SSL证书(需填写cert_id证书IDcert_region证书地域)。

说明

free 类型的免费证书已不再支持。

选择 upload 类型时需要哪些必填参数?

当 cert_type = "upload" 时,必须提供以下参数:

  • server_certificate:证书公钥(PEM格式)。

  • private_key:证书私钥(PEM格式)。

certificate_config {
    cert_type          = "upload"
    cert_name          = "cert-xxxxxxxxx"
    server_certificate = "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----"
    private_key        = "-----BEGIN RSA PRIVATE KEY-----\n...\n-----END RSA PRIVATE KEY-----"
  }

选择 cas 类型时需要哪些必填参数?

当 cert_type = "cas" 时,必须提供以下参数:

  • cert_id:阿里云证书中心的证书ID(可在证书详情页获取)。

  • cert_region:阿里云数字证书管理服务所在地域,根据账号类型选择(默认为cn-hangzhou):

    • 中国站账号:cn-hangzhou

    • 国际站账号:ap-southeast-1

certificate_config {
    server_certificate_status = "on"
    cert_type  = "cas"
    cert_id    = "1111111"
    cert_region = "cn-hangzhou"
  }

cert_region参数有什么用?如何设置cert_region参数

cert_region参数用于设置阿里云数字证书管理服务所在地域,cert_type = "cas"(使用阿里云云盾证书)时,该参数为必填。填写规则如下:

  • 云盾证书所在的阿里云账号为中国站账号时,配置为cn-hangzhou

  • 云盾证书所在的阿里云账号为国际站账号时,配置为ap-southeast-1