【问题标题】:Terraform regenerating resources when a new object is added to map将新对象添加到地图时 Terraform 重新生成资源
【发布时间】:2019-10-08 20:22:41
【问题描述】:

我有一个 Terraform(0.12 之前的版本)模块,可以生成一个 Amazon Cognito 用户池 + 一个客户端和域。

resource "aws_cognito_user_pool" "pool" {
  count = "${var.user_pool_count}"
  name  = "${lookup(var.user_pools[count.index], "name")}"

  username_attributes      = ["email"]
  auto_verified_attributes = ["email"]

  password_policy {
    minimum_length    = "${lookup(var.user_pools[count.index], "password_minimum_length")}"
    require_lowercase = "${lookup(var.user_pools[count.index], "password_require_lowercase")}"
    require_numbers   = "${lookup(var.user_pools[count.index], "password_require_numbers")}"
    require_symbols   = "${lookup(var.user_pools[count.index], "password_require_symbols")}"
    require_uppercase = "${lookup(var.user_pools[count.index], "password_require_uppercase")}"
  }

  verification_message_template = {
    default_email_option = "CONFIRM_WITH_LINK"
  }

  lambda_config = {
    pre_token_generation = "${var.lambda_pre_token_generation}"
    custom_message       = "${var.lambda_custom_message}"
  }

  email_configuration = {
    reply_to_email_address = "${lookup(var.user_pools[count.index], "reply_to_email_address")}"
    source_arn             = "${lookup(var.user_pools[count.index], "source_arn")}"
    email_sending_account  = "${lookup(var.user_pools[count.index], "email_sending_account")}"
  }

  schema = [
    < REDACTED >
  ]
}

resource "aws_cognito_user_pool_client" "client" {
  count               = "${var.user_pool_count}"
  name                = "${lookup(var.user_pools[count.index], "name")}"
  user_pool_id        = "${element(aws_cognito_user_pool.pool.*.id,count.index)}"
  explicit_auth_flows = ["ADMIN_NO_SRP_AUTH", "USER_PASSWORD_AUTH"]
}

resource "aws_cognito_user_pool_domain" "main" {
  count        = "${var.user_pool_count}"
  domain       = "${lookup(var.user_pools[count.index], "domain")}"
  user_pool_id = "${element(aws_cognito_user_pool.pool.*.id,count.index)}"
}

这接受名为 user_pools 的映射列表来定义所需的 Cognito 用户池。 不幸的是,当我添加一个包含新池定义的新地图时,Terraform 会强制为所有池重新创建 aws_cognito_user_pool_client 和 aws_cognito_user_pool_domain。这似乎是因为它看到了以下方面的变化:

user_pool_id: "eu-west-1_R8SDX8Yqj" =&gt; "${element(aws_cognito_user_pool.pool.*.id,count.index)}" (forces new resource)

我假设这是因为 Terraform 看到 aws_cognito_user_pool.pool.*.id 发生了变化并迫使重新进行游戏。谁能解释如何解决这个问题?重新生成所有域和客户端对我来说不是最理想的。

【问题讨论】:

    标签: amazon-web-services terraform amazon-cognito terraform-provider-aws


    【解决方案1】:

    对于任何阅读本文的人。我在 Github 上发现了以下问题 - https://github.com/hashicorp/terraform/issues/14357

    将我的语法更改为以下似乎可以解决它。

    user_pool_id = "${aws_cognito_user_pool.pool.*.id[count.index]}"

    【讨论】:

      猜你喜欢
      • 2021-09-21
      • 1970-01-01
      • 2013-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-23
      • 1970-01-01
      相关资源
      最近更新 更多