我对编码和地形非常陌生。
我试着把我需要的所有资源都写进.tf文件
在这样做的同时,我
Terraform plan
得到一个错误
│ Error: no matching Route53Zone found
│
│ with data.aws_route53_zone.<name>,
│ on <filename>.tf line 70, in data "aws_route53_zone" "<name>":
│ 70: data "aws_route53_zone" "<name>" {
这就是我写的
resource "aws_route53_zone" "example" {
name = "example.com"
comment = "eg-example"
tags= {
Name = "example.com"
}
}
resource "aws_acm_certificate" "eg-example-acm-domaincert" {
domain_name = "*.example.com"
validation_method = "DNS"
tags = {
name = "eg-example-acm-domaincert"
}
}
resource "aws_route53_record" "cname-example" {
zone_id = data.aws_route53_zone.example.zone_id
name = "cname.example.com"
type = "CNAME"
records = ["cname-example-alb-ext-1111111111.region.elb.amazonaws.com"]
ttl = "300"
}
data "aws_route53_zone" "example" {
name = "example.com."
private_zone = true
}
resource "aws_acm_certificate_validation" "eg-example-acm-domaincert" {
certificate_arn = "arn:aws:acm:**********************"
validation_record_fqdns = ["*****************************.example.com"]
}
代码与此没有太大区别。
除了在AWS控制台上创建一个区域之外,我真的没有任何想法。
还有别的办法吗?
我希望我的解释对你有意义。
取消对data
的调用,只使用资源:
aws_route53_zone.example.zone_id
当您检索以前创建的资源(例如,从另一个Terraform项目(时,请使用data
。
resource "aws_route53_record" "cname-example" {
zone_id = aws_route53_zone.example.zone_id // no need for data.
name = "cname.example.com"
type = "CNAME"
records = ["cname-example-alb-ext-1111111111.region.elb.amazonaws.com"]
ttl = "300"
}
Runterraform validate
andterraform plan
.
Good luck!
Since you are creating your HZ in your TF script, you can refer to it as well, without using data source:
resource "aws_route53_record" "cname-example" {
zone_id = aws_route53_zone.example.zone_id
name = "cname.example.com"
type = "CNAME"
records = ["cname-example-alb-ext-1111111111.region.elb.amazonaws.com"]
ttl = "300"
}