如何分别管理每个工作区的Terraform导入ID?

huangapple go评论46阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年6月16日 07:28:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76486088.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定