Building Block init script (to import existing resources into Terraform state)
Thomas Abbe
As a Building Block developer, I want to execute tofu import statements in order to import existing resources into the terraform/tofu state. This action is needed, if I want to modify an existing building block or if I want to migrate an existing OSB to a building block representation.
Since the tofu workspace name is not known in advance, it is currently impossible to write a proper migration script.
One solution could be to pass an initialization script (with the tofu import statements) before executing tofu apply inside the building block Terraform runner.
H
Henry Dettmer
Hi Thomas,
if you can derive the IDs of the resources you need to import at runtime this could be done with a static file input (e.g. imports.tf) using import blocks (https://developer.hashicorp.com/terraform/language/import).
Would that help in your case?
Thomas Abbe
Hi Henry Dettmer,
thank you, this might work for some cases. For some resources with derived names this might work, for other not since you have to do dynamic lookups. One example might be Azure RBAC Assignments where the name/id is not known in advance.