# Terraform 管理阿里云域名解析记录 使用 Terraform 自动管理域名解析记录,很方便,速度也不慢。 相比之下: - 阿里云,如果用 `aliyun-cli`,速度也不慢,但是需要为自动化编写脚本 - aliyun-cli 还可以使用 docker 方式使用 - 但是因为加载镜像过程,从本地执行会比较慢 `main.tf`: ```tf terraform { required_providers { alicloud = { source = "aliyun/alicloud" } } } provider "alicloud" { access_key = var.aliyun_access_key secret_key = var.aliyun_secret_key region = var.region } variable "aliyun_access_key" { type = string } variable "aliyun_secret_key" { type = string } variable "region" { type = string } resource "alicloud_alidns_record" "record" { domain_name = "your-domain.com" rr = "test" type = "A" value = "1.2.3.4" status = "ENABLE" } ``` `terraform.tfvars`: ```tf aliyun_access_key = "" aliyun_secret_key = "" region = "cn-beijing" ``` 执行: ```bash # 初始化,安装 aliyun provider terraform init # 查看配置是否有问题 terraform plan # 执行 terraform apply # 销毁 terraform destroy ```