【问题标题】:Terraform always updating iam_policy_document's condition blockTerraform 总是更新 iam_policy_document 的条件块
【发布时间】:2021-12-05 22:01:43
【问题描述】:

我有一个带有条件块的 iam_policy_document 资源。在 terraform 条件块中有一个名为 values 的必需参数。这是条件的一组可能值。但是,就我而言,该变量是一个布尔值。所以这个集合只是一个值,["false"]。

当我运行 terraform apply 然后运行 ​​terraform plan 或 terraform apply 时,terraform 总是说它会将此值从“false”更新为 [“false”]。有没有办法让它在实际上没有任何变化时停止更新此政策?

参考:https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document#values

我在 AWS 上使用 v0.15.1。

这是当 terraform 代码未更改且 AWS 上未发生手动操作策略时的 terraform plan 输出。请注意,它正在更新政策。

Terraform will perform the following actions:

  # module.s3_test_bucket.aws_s3_bucket.main will be updated in-place
  ~ resource "aws_s3_bucket" "main" {
        id                          = "test-for-stackoverflow"
      ~ policy                      = jsonencode(
          ~ {
              ~ Statement = [
                  ~ {
                      ~ Condition = {
                          ~ Bool = {
                              ~ aws:SecureTransport = "false" -> [
                                  + "false",
                                ]
                            }
                        }
                        [...]

【问题讨论】:

  • 导致问题的实际 TF 代码是什么?
  • 如果没有更完整的细节很难具体说明,但从表面上看,这看起来像是 S3 API 以 AWS 提供商未预料到的方式对策略 JSON 进行了规范化的情况,因此提供者认为它需要“修复”规范化。由于您使用aws_iam_policy_document 生成此策略,您将无法直接影响它生成的 JSON,因此我认为如果升级到最新的 AWS 提供商没有帮助,我认为目前唯一的解决方法是是使用jsonencode函数直接自己编写JSON策略内容。
  • 然后您可以完全按照 S3 API 对其进行规范化的方式来构建它,并避免这种无法收敛的情况。对于真正的修复,我认为您需要向 AWS 提供商提出问题,看看是否可以教它有关此规范化规则的知识,以便它不会尝试撤消它。

标签: amazon-web-services amazon-s3 terraform


【解决方案1】:

您键入 aws:SecureTransport = array of 1,AWS 将其更新为字符串,因此您在部署的配置和 terrafrom 配置文件之间存在差异。 将值更改为字符串 aws:SecureTransport = [“假”] 到
aws:SecureTransport = "假"

它应该可以解决它。

【讨论】:

    猜你喜欢
    • 2019-03-16
    • 1970-01-01
    • 2021-05-15
    • 2021-06-24
    • 2021-08-11
    • 2020-01-31
    • 1970-01-01
    • 2021-09-06
    • 2023-01-30
    相关资源
    最近更新 更多