【问题标题】: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?如果在 Terraform 模块中创建了 aws_api_gateway_integration,如何在 aws_api_gateway_deployment 资源上填充depends_on?
【发布时间】:2019-08-12 08:20:54
【问题描述】:

aws_api_gateway_deployment 的 Terraform 文档中说:

注意:取决于您的休息中是否有 aws_api_gateway_integration api(这又取决于 aws_api_gateway_method)。为了避免比赛 您可能需要添加显式depends_on =的条件 [“aws_api_gateway_integration.name”]。

我的 aws_api_gateway_deployment 资源位于根模块中,但大部分 aws_api_gateway_integrations 是在子模块中创建的(这是我创建的本地模块)。

我的理解是不能从模块中导出资源。

文件夹结构为:

 - 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

【问题讨论】:

    标签: aws-api-gateway terraform terraform-provider-aws


    【解决方案1】:

    您不能依赖另一个模块中的资源。您可以通过引用该模块的输出来创建对整个模块的隐式依赖。

    我认为您可以为此使用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}"
      }
    }
    

    【讨论】:

    • 好酷。虽然感觉有点像hack,但我想这达到了最终目标。谢谢!
    • 进一步检查我不确定我是否遵循。我是在模块内部还是外部声明null_resourcedepends_on 属性在 aws_api_gateway_deployment 资源中是什么样的?
    【解决方案2】:

    所以最后我让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"
    }
    

    【讨论】:

    • 你可以依赖整个模块吗?你知道的越多。
    猜你喜欢
    • 2020-06-02
    • 1970-01-01
    • 2019-03-19
    • 1970-01-01
    • 2022-09-22
    • 2021-02-23
    • 2020-04-16
    • 2019-10-31
    相关资源
    最近更新 更多