【问题标题】:Dynamic reference to resouce id对资源 id 的动态引用
【发布时间】:2019-11-26 21:47:36
【问题描述】:

我有一个名为cognito_user_pool 的变量并定义了两个资源。 aws_cognito_identity_pool 在client_id 参数中需要aws_cognito_user_pool_client 的实例ID。 ID 由aws_cognito_user_pool_client.MY_CLIENT_NAME.id 访问,但问题是客户端名称保存在cognito_user_pool 变量中。

我的问题是如何在不硬编码客户端名称的情况下获取 ID。

以下设置不起作用:

resource "aws_cognito_user_pool_client" "example" {
  name         = var.cognito_user_pool
  user_pool_id = aws_cognito_user_pool.pool.id
}

resource "aws_cognito_identity_pool" "main" {
  identity_pool_name               = var.cognito_user_pool
  allow_unauthenticated_identities = false

  cognito_identity_providers {
    client_id               = aws_cognito_user_pool_client[var.cognito_user_pool].id
    provider_name           = aws_cognito_user_pool.pool.endpoint
    server_side_token_check = false
  }
}

生产:

Error: Invalid reference

  on setup.tf line 26, in resource "aws_cognito_identity_pool" "main":
  26:     client_id               = aws_cognito_user_pool_client[var.cognito_user_pool]

A reference to a resource type must be followed by at least one attribute
access, specifying the resource name.

【问题讨论】:

    标签: terraform terraform-provider-aws


    【解决方案1】:

    但客户端名称和客户端 ID 不一样。如果它是相同的,那么你可以只使用变量。

    我认为问题在于您错误地访问/引用了客户端 ID。

    resource "aws_cognito_identity_pool" "main" 中的 cognito_identity_providers 块应该是:

      cognito_identity_providers {
        client_id               = aws_cognito_user_pool_client.example.id
        provider_name           = aws_cognito_user_pool.pool.endpoint
        server_side_token_check = false
      }
    

    【讨论】:

    • 我想我有一个夜晚,最好还是去睡觉,然后第二天再试一次。当然,我现在明白你的意思了。谢谢大佬!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-10
    相关资源
    最近更新 更多