您如何将一种资源的输出值分配为另一种资源的输入?
How do you assign the output value of one resource as input to another?
我的根模块中有两个 .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}"
}
我有另一个名为 route53.tf
的 .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
}
}
我需要把apigateway的api_endpoint
和id
传给route53,不知道怎么传?
我尝试使用 output
返回这两个值并在 route53 资源中引用它,但是它不起作用。它给了我一个 undeclared resource error
.
如何将一种资源的输出值分配给另一种资源的输入?
假设你同时处理两个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"]
}
}
而我的 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}"
}
}
我的根模块中有两个 .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}"
}
我有另一个名为 route53.tf
的 .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
}
}
我需要把apigateway的api_endpoint
和id
传给route53,不知道怎么传?
我尝试使用 output
返回这两个值并在 route53 资源中引用它,但是它不起作用。它给了我一个 undeclared resource error
.
如何将一种资源的输出值分配给另一种资源的输入?
假设你同时处理两个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"]
}
}
而我的 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}"
}
}