英文:
How to manage Terraform import IDs separately per workspace?
问题
Terraform 1.5 introduced import blocks for "config-driven import". This allows plan
/apply
operations to seamlessly manage the state of your preexisting infrastructure if you simply provide the import ID values as part of your configuration.
Example import block:
import {
to = aws_instance.example
id = "i-abcd1234"
}
This appears to be a huge step forward for tasks and workflows in which the state is not already under management by a Terraform state backend1. However, when using Workspaces to differentiate between deployment instances, each config resource will have a unique ID per workspace. It isn't clear that there's a clean way to specify these unique ID values.
How can we specify unique ID values per workspace?
英文:
Terraform 1.5 introduced import blocks for "config-driven import". This allows plan
/apply
operations to seamlessly manage the state of your preexisting infrastructure if you simply provide the import ID values as part of your configuration.
Example import block:
import {
to = aws_instance.example
id = "i-abcd1234"
}
This appears to be a huge step forward for tasks and workflows in which the state is not already under management by a Terraform state backend<sup>1</sup>. However, when using Workspaces to differentiate between deployment instances, each config resource will have a unique ID per workspace. It isn't clear that there's a clean way to specify these unique ID values.
How can we specify unique ID values per workspace?
答案1
得分: 2
> 如何为每个工作区指定唯一的 ID 值?
据我所知,目前似乎不可能做到这一点,因为您无法在 import
块中使用变量。我已为此问题在 GitHub 上提出了一个问题 https://github.com/hashicorp/terraform/issues/33383。
还有另一个开放的问题 https://github.com/hashicorp/terraform/issues/33380,该问题提出了一个用于该块的工作区参数,如果实施的话,将有效地成为我的提案的替代方案。
英文:
> How can we specify unique ID values per workspace?
This is currently not possible as far as I can tell, because you cannot use variables in the import
block. I've opened a GitHub issue for this https://github.com/hashicorp/terraform/issues/33383.
There's also another open issue https://github.com/hashicorp/terraform/issues/33380 which proposes a workspace parameter for the block, which if implemented would effectively be an alternative to my proposal.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论