1

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?

Brent Bradburn
  • 51,587
  • 17
  • 154
  • 173

1 Answers1

2

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.

Paolo
  • 21,270
  • 6
  • 38
  • 69
  • Enabling the `workspace` intrinsic does seem like the path of least resistance even though this seems like one of the blocks where enabling variable resolution may prove problematic. – Matthew Schuchard Jun 16 '23 at 12:47
  • @MattSchuchard uhm yeah perhaps, but that would first of all lead to quite the code duplication, and then introduce yet another special case where the general constructs of the language cannot be applied.. – Paolo Jun 16 '23 at 13:00
  • I was referring to your answer that is probably the best possible information at this time (ergo the upvote), and specifically the second cited issue with a proposed resolution, and adding details. I am unsure to what you are referring in your comment. – Matthew Schuchard Jun 16 '23 at 13:38
  • @MattSchuchard all I am saying is that if I had to choose between what I proposed in 33383 vs what is proposed 33380, I'd choose what I proposed – Paolo Jun 16 '23 at 13:40