如果 aws_api_gateway_integration 是在 Terraform 模块中创建的,我如何在 aws_api_gateway_deployment 资源上填充 depends_on?
How do I populate the depends_on on an aws_api_gateway_deployment resource if the aws_api_gateway_integration was created in a Terraform module?
在 aws_api_gateway_deployment
的 Terraform 文档中说:
Note: Depends on having aws_api_gateway_integration inside your rest
api (which in turn depends on aws_api_gateway_method). To avoid race
conditions you might need to add an explicit depends_on =
["aws_api_gateway_integration.name"].
我的 aws_api_gateway_deployment
资源位于根模块中,但大部分 aws_api_gateway_integration
是在子模块中创建的(这是我创建的本地模块)。
我的理解是您不能从模块中导出资源。
文件夹结构为:
- main.tf <-- contains the aws_api_gateway_rest_api and aws_api_gateway_deployment and uses the service_func_lambda module multiple times
- modules/
- service_func_lambda/
- main.tf <-- contains the aws_api_gateway_integration and other bits such as aws_api_gateway_method and aws_api_gateway_resource
如何从调用根模块引用在模块内部创建的 aws_api_gateway_integration
?
您不能依赖另一个模块中的资源。您可以通过引用该模块的输出来创建对整个模块的隐式依赖。
我认为您可以使用 null_resource
(尽管可能有更好的方法)。像这样创建一个空资源,然后让你的 aws_api_gateway_deployment
依赖于它:
resource "null_resource" "depend_on_module" {
triggers {
service_func_lambda_module_output = "${module.service_func_for_lambda.some_output}"
}
}
所以最后我让 aws_api_gateway_deployment
依赖于整个模块。这似乎工作得很好:
resource "aws_api_gateway_deployment" "api_gw_deploy" {
depends_on = [
"module.user_func_list",
"module.user_func_create",
"module.resource_func_list",
]
rest_api_id = "${aws_api_gateway_rest_api.main_api_gw.id}"
stage_name = "live"
}
在 aws_api_gateway_deployment
的 Terraform 文档中说:
Note: Depends on having aws_api_gateway_integration inside your rest api (which in turn depends on aws_api_gateway_method). To avoid race conditions you might need to add an explicit depends_on = ["aws_api_gateway_integration.name"].
我的 aws_api_gateway_deployment
资源位于根模块中,但大部分 aws_api_gateway_integration
是在子模块中创建的(这是我创建的本地模块)。
我的理解是您不能从模块中导出资源。
文件夹结构为:
- main.tf <-- contains the aws_api_gateway_rest_api and aws_api_gateway_deployment and uses the service_func_lambda module multiple times
- modules/
- service_func_lambda/
- main.tf <-- contains the aws_api_gateway_integration and other bits such as aws_api_gateway_method and aws_api_gateway_resource
如何从调用根模块引用在模块内部创建的 aws_api_gateway_integration
?
您不能依赖另一个模块中的资源。您可以通过引用该模块的输出来创建对整个模块的隐式依赖。
我认为您可以使用 null_resource
(尽管可能有更好的方法)。像这样创建一个空资源,然后让你的 aws_api_gateway_deployment
依赖于它:
resource "null_resource" "depend_on_module" {
triggers {
service_func_lambda_module_output = "${module.service_func_for_lambda.some_output}"
}
}
所以最后我让 aws_api_gateway_deployment
依赖于整个模块。这似乎工作得很好:
resource "aws_api_gateway_deployment" "api_gw_deploy" {
depends_on = [
"module.user_func_list",
"module.user_func_create",
"module.resource_func_list",
]
rest_api_id = "${aws_api_gateway_rest_api.main_api_gw.id}"
stage_name = "live"
}