Reputation: 3262
In the Terraform docs for aws_api_gateway_deployment
it says:
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"].
My aws_api_gateway_deployment
resource lives in the root module but most of the aws_api_gateway_integration
s are created in a child module (this is a local module created by me).
My understanding is that you can't export a resource from a module.
The folder structure is:
- 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
How can I reference the aws_api_gateway_integration
that is created inside the module from the calling, root module?
Upvotes: 3
Views: 2546
Reputation: 3262
So in the end I made the aws_api_gateway_deployment
depend on the whole module. This seemed to work nicely:
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"
}
Upvotes: 2
Reputation: 7347
You cannot depend on a resource inside another module. You can create an implicit dependency on an entire module by referencing an output of that module.
I think you can use null_resource
for this (though there may be a better way). Create a null resource like this, then have your aws_api_gateway_deployment
depend on it:
resource "null_resource" "depend_on_module" {
triggers {
service_func_lambda_module_output = "${module.service_func_for_lambda.some_output}"
}
}
Upvotes: 2