Ben*_*min 3 terraform terraform-provider-aws
.tf我的根模块中有两个文件:
第一个被称为api-gateway.tf在 AWS 中提供 API 网关:
resource "aws_apigatewayv2_api" "apiGateway" {
name = "some_Name"
protocol_type = "HTTP"
}
output "api_gateway_endpoint" {
value = "${aws_apigatewayv2_api.apiGateway.api_endpoint}"
}
output "api_gateway_endpoint_id" {
value = "${aws_apigatewayv2_api.apiGateway.id}"
}
Run Code Online (Sandbox Code Playgroud)
我有另一个.tf名为route53.tf创建Route53记录的文件:
resource "aws_route53_record" "www" {
zone_id = "xxxxx"
name = "someurl.com"
type = "A"
alias {
name = "${output.api_gateway_endpoint}"
zone_id = "${output.api_gateway_endpoint_id}"
evaluate_target_health = false
}
}
Run Code Online (Sandbox Code Playgroud)
我需要将 apigateway的api_endpoint和id传递到 route53,但我不知道如何?
我尝试使用output和引用 route53 资源中的返回这两个值,但是它不起作用。它给了我一个undeclared resource error.
您如何将一种资源的输出值作为输入分配给另一种资源?
小智 5
假设您同时处理两个 TF 文件,则需要使用输出变量,这只是一个参考。
zone_id = "${aws_apigatewayv2_api.apiGateway.regional_zone_id}"
例如,我的 api 网关块(在我的 api_gateway.tf 中)是
resource "aws_api_gateway_domain_name" "devapi"
{
domain_name = "${var.appLower}.${local.domain}"
regional_certificate_arn = "${data.aws_acm_certificate.mts.arn}"
endpoint_configuration {
types = ["REGIONAL"]
}
}
Run Code Online (Sandbox Code Playgroud)
而我的 route53 块(在我的 route53.tf 中)看起来像这样
resource "aws_route53_record" "devapi"
{
name = "${aws_api_gateway_domain_name.devapi.domain_name}"
type = "A"
zone_id = "${data.aws_route53_zone.mts.id}"
alias {
evaluate_target_health = true
name = "${aws_api_gateway_domain_name.devapi.regional_domain_name}"
zone_id = "${aws_api_gateway_domain_name.devapi.regional_zone_id}"
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
112 次 |
| 最近记录: |