amazon-web-services - 尝试创建 aws_route53_record 以指向负载均衡器,但使用 terraform 不断出现错误
问题描述
由于域已经存在,我将区域导入到我的配置中:
resource "aws_route53_zone" "example_hosted_zone" {
name = "example.club"
}
53 号公路记录:
resource "aws_route53_record" "us-battasks" {
zone_id = aws_route53_zone.example_hosted_zone.zone_id
name = "us-battasks"
type = "CNAME"
ttl = "60"
records = [aws_lb.restricted_access_lb.id]
}
resource "aws_route53_record" "us-battasksapi" {
zone_id = aws_route53_zone.example_hosted_zone.zone_id
name = "us-battasksapi"
type = "CNAME"
ttl = "60"
records = [aws_lb.restricted_access_lb.id]
}
Terraform 计划显示它将创建资源,但是当我申请时,我收到以下错误:
Error: [ERR]: Error building changeset: InvalidChangeBatch: [Invalid Resource Record: FATAL problem: DomainLabelTooLong (Domain label is too long) encountered with 'arn:aws:elasticloadbalancing:us-east-1:221124075124:loadbalancer', Unparseable CNAME encountered]
status code: 400, request id: e43e5ced-957f-4bcd-83d2-1e7eaea7665b
Error: [ERR]: Error building changeset: InvalidChangeBatch: [Invalid Resource Record: FATAL problem: DomainLabelTooLong (Domain label is too long) encountered with 'arn:aws:elasticloadbalancing:us-east-1:221124075124:loadbalancer', Unparseable CNAME encountered]
status code: 400, request id: 33d3340e-f2f2-4c95-bc96-a9de1349afc4
如果有帮助,这里是负载均衡器的 Terraform 代码:
resource "aws_lb" "restricted_access_lb" {
name = "restricted-access-lb"
internal = false
load_balancer_type = "application"
security_groups = [aws_security_group.swarm_node_sg.id, aws_security_group.monolaunch_instance_sg.id, aws_security_group.restricted_access_sg.id]
subnets = [aws_subnet.public_subnet_b.id, aws_subnet.public_subnet_a.id]
enable_deletion_protection = true
}
解决方案
资源的ARNid
是您在尝试创建 Route53 记录时看到错误中显示的负载均衡器的 ARN 的原因。aws_lb
相反,您应该使用将映射到负载均衡器地址的dns_name
属性。
resource "aws_route53_record" "us-battasksapi" {
zone_id = aws_route53_zone.example_hosted_zone.zone_id
name = "us-battasksapi"
type = "CNAME"
ttl = "60"
records = [aws_lb.restricted_access_lb.dns_name]
}
相反,如果您想使用别名 A 记录来避免第二次 DNS 查找(加上zone 中顶点记录的问题),您将改为使用以下内容:
resource "aws_route53_record" "us-battasksapi" {
zone_id = aws_route53_zone.example_hosted_zone.zone_id
name = "us-battasksapi"
type = "A"
alias {
name = aws_lb.restricted_access_lb.dns_name
zone_id = aws_lb.restricted_access_lb.zone_id
evaluate_target_health = true
}
}
推荐阅读
- php - 如何用变量替换子字符串?
- swift - 更改状态模型后需要按两次恢复“自动预览更新已暂停”
- c++ - 有没有办法可以在 C++ 中编辑文件的中间
- r - 在 R 中导入的 data.frame 中将“\\”替换为“\”
- spring-mvc - 如果发布请求包含外部 ID,如何在 Spring 控制器中设置关联记录?
- javascript - 如何将等待功能链接在一起
- node.js - 使用 EJS 时是否需要在 Server.js 文件中使用 { hbs.registerPartials(__dirname + '/views/partials');} 之类的方法?
- asp.net-core - 为什么 Visual Studio 2019 16.9.5 中 .NET Core 3.1 和 .NET 5 的脚手架标识会失败?
- android - 删除小吃店时向下移动视图/按钮
- php - 准备好的语句总是在 if 上返回 0