Experimental Import Block Feedback - import with multiple states in mind


today the import {} blocks are a great way to import into the tfstate. The gap i see however is that imports are assumed to be used in a single workspace. There are 2 scenarios where this causes problems:

  1. using terraform workspace

if i am not using the default workspace today there is no way to specify to import {} which workspace.

  1. using .tfvars files for environment separation

if im using a single workspace but calling terraform with -var-files=dev.tfvars then the import blocks are not helpful after a single deployment

I can think of a few options to resolve but I will propose that the import blocks be definable in a new file type *.tfimports and then referencable via the command line like -var-files, ie. -imports=dev.tfimports

come to think of it, this also effects moved blocks

To a much more limited extent, perhaps. moved blocks typically relate to evolving the structure of the .tf code, so it generally makes sense to couple them to the .tf code even when it is re-used across multiple environments.

Whereas import blocks are intrinsically environment specific, which creates much more of a conflict with “One set of .tf code, multiple environments” setups.

off topic: yes i agree regarding your moved comments. i just happen to be in the middle of inheriting some really badly organized terraform code so using moved at the env specific level would be helpful atm.

generally i think moved is for module developers to refactor their modules