为了理解,这是我问题的简化示例。
我的团队曾经通过module1
来管理一个 S3 存储桶,该调用了包含存储桶代码的module2
。
production_account/ --(invokes)--> module1/ --(invokes)--> module2/s3.tf
但后来他们决定重构代码,并直接调用module2
。
production_account/ --(invokes)--> module2/s3.tf
因此,当我现在进行地形规划时,我得到:
module.module1.module.module2.aws_s3_bucket.bucket will be destroyed {
...
}
module.module2.aws_s3_bucket.bucket will be created {
...
}
简而言之,terraform 希望重新创建 s3 存储桶。这样做的问题是所有数据都将丢失。
有没有办法将现有存储桶导入状态并通过模块 2 对其进行管理?
terraform import module.module1.module.module2.aws_s3_bucket.bucket
解决了我问题的前半部分。
是的。使用地形状态 mv 不import
。
terraform state mv module.module1.module2.aws_s3_bucket.bucket module.module2.aws_s3_bucket.bucket