【问题标题】:Why does Terraform want to destroy this imported aws_organizations_organizational_unit?为什么 Terraform 要销毁这个导入的 aws_organizations_organizational_unit?
【发布时间】:2022-01-14 13:04:36
【问题描述】:

我们正在尝试使用 Terraform v1.0.9 和 aws provider v3.64.2 为最近部署的 AWS 组织资源构建状态文件。

aws_organizations_organization 已更正为使用 terraform import aws_organizations_organization.my_organisation [id] 导入。 Terraform 不想在导入后破坏组织。

但是,当单元被导入 - AWS_DEFAULT_REGION=eu-west-2 terraform import -config=tf/units/infrastructure -var 'organisation_root=[id]' aws_organizations_organizational_unit.my-ou-infrastructure ou-abc0-ab0cdefg 时,它似乎导入成功,但在 terraform plan 上,它想要销毁 OU 并重新创建它。

# aws_organizations_organizational_unit.my-ou-infrastructure will be destroyed
- resource "aws_organizations_organizational_unit" "my-ou-infrastructure" {
    - accounts  = [] -> null
    - arn       = "arn:aws:organizations::000000000000:ou/o-xxxxx/ou-xxxx-xxxxxx" -> null
    - id        = "ou-xxxx-xxxxxx" -> null
    - name      = "name" -> null
    - parent_id = "id" -> null
    - tags      = {} -> null
  }

...

# module.my_organisation_units.module.my_organisation_unit_infrastructure.aws_organizations_organizational_unit.my-ou-infrastructure will be created
  + resource "aws_organizations_organizational_unit" "my-ou-infrastructure" {
      + accounts  = (known after apply)
      + arn       = (known after apply)
      + id        = (known after apply)
      + name      = "name"
      + parent_id = "id"
    }

...

Plan: 31 to add, 0 to change, 1 to destroy.

这应该发生吗?从文档来看,导入 OU 看起来非常简单。

【问题讨论】:

  • 看起来不同的资源...一个在根目录下另一个在模块下
  • 谢谢。这是我第一次使用import。看起来我需要对模块使用语法terraform import module.foo.aws_instance.bar i-abcd1234

标签: terraform terraform-provider-aws


【解决方案1】:

我们需要将资源作为模块导入terraform import module.my_organisation_units.module.my_organisation_unit_infrastructure.aws_organizations_organizational_unit.my-ou-infrastructure ou-abc0-ab0cdefg

【讨论】:

    猜你喜欢
    • 2019-10-25
    • 2016-08-09
    • 1970-01-01
    • 2020-07-12
    • 2022-06-13
    • 2018-07-06
    • 1970-01-01
    • 2014-04-13
    • 2016-08-04
    相关资源
    最近更新 更多