【问题标题】:Terraform Custom Attribute Destroying User Pool AWSTerraform 自定义属性破坏用户池 AWS
【发布时间】:2018-10-18 11:02:32
【问题描述】:

我有一个不再使用的自定义属性,它每次都强制 terraform 销毁用户池。有没有办法避免用户池被破坏?

我的地形:

resource "aws_cognito_user_pool" "my_pool" {
   name                          = "${var.la} Pool"

   alias_attributes              = [
      "email"
   ]

   /* Auto-verify these fields */
   auto_verified_attributes      = [
      "email"
   ]

   ...

   schema {
      attribute_data_type         = "String"
      name                        = "my_custom_attribute1"
      required                    = "false"
      mutable                     = "true"
   }
 }

terraform plan 给出以下结果:

  schema.xxx.attribute_data_type:                          "String" => "" (forces new resource)
  schema.xxx.developer_only_attribute:                          "false" => "false"
  schema.xxx.mutable:                                           "true" => "false" (forces new resource)
  schema.xxx.name:                                              "my_custom_attribute1" => "" (forces new resource)
  schema.xxx.number_attribute_constraints.#:                    "0" => "0"
  schema.xxx.required:                                          "false" => "false"
  schema.xxx.string_attribute_constraints.#:                    "1" => "0" (forces new resource)
  schema.xxx.string_attribute_constraints.0.max_length:         "" => ""
  schema.xxx.string_attribute_constraints.0.min_length:         "" => ""

我没有对这些进行更改,但每次我尝试计划时它都会说有更改并且我需要销毁我的用户池(我不想这样做)。

我试过运行 terraform refresh,但似乎没有效果。

我找到了以下内容,但这些建议似乎无法解决我的问题:https://github.com/terraform-providers/terraform-provider-aws/issues/3891

我不认为这真的是一个错误。如何避免破坏我的 Cognito 用户池?

terraform 版本:0.11.5 aws 版本:0.17(也试过 0.15)

【问题讨论】:

  • 当你说你有一个不再使用的自定义属性时,你是说你已经在 Terraform 中删除了它,然后计划显示它需要替换用户池?如果是这样,那么这是可以预料的,因为 AWS 不允许您从用户池中删除属性,因此 Terraform 需要重新创建用户池才能删除该属性。
  • 不,我知道删除它会破坏池。我已经保留了该属性,但我想明确表示我目前没有使用它。当我将更改应用于其他服务(例如发电机)时,我只希望我的池不会被破坏。
  • 您可能需要分享更多配置和计划,以便让试图回答这个问题的人明白这一点。也许尝试创建一个具有简单用户池配置的 [mvce] 并计算出你需要做些什么来让它在你看到的时候强制一个新资源,这样你就可以展示完整的计划而不必审查/分享事物的一个子集。尽管 Terraform 认为您正在尝试删除该架构属性,但从那里的样子来看,它会在没有它的情况下重新创建用户池。
  • 我唯一真正遗漏的是电子邮件。这是一个很短的配置。让我困惑的是自定义属性是如何设置为可变的,但 terraform 似乎认为它需要将其更改为 false,从而破坏池。我的 terraform 说“真”,当前状态说“真”,但由于某种原因,它认为需要将其更改为“假”
  • 不,该计划是说由于某种原因正在删除该属性(因此所有参数都设置为默认值,例如空字符串/0/false)。

标签: amazon-web-services terraform


【解决方案1】:

我最近遇到了同样的问题,似乎 Terraform 已更新 their documentation 以突出显示此问题:

注意:当定义 String 或 Number 的 attribute_data_type 时,需要相应的属性约束配置块(例如 string_attribute_constraints 或 number_attribute_contraints)来防止重新创建 Terraform 资源。此要求适用于标准(例如姓名、电子邮件)和自定义架构属性。

简而言之,您可能需要向属性添加约束以阻止它每次重新创建,例如:

string_attribute_constraints = { # This is required to stop user pool being recreated
  max_length = 32
}

这可能会导致您的资源被更新(并因此被销毁)一次,但随后应按预期运行。不过,与往常一样,我建议您先进行测试!

【讨论】:

    猜你喜欢
    • 2019-05-28
    • 1970-01-01
    • 2018-03-25
    • 2022-01-21
    • 2021-07-02
    • 1970-01-01
    • 2020-06-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多