Hello everyone,
I’m encountering a problem I’d appreciate some help with. I’m trying to create import blocks for resources within an imported module. However, the dots in the resource “to” ID are always removed. Additionally, the module path needs to precede the resource type. I haven’t found a way to set this part of the ID via another argument.
Ultimately, the only solution I found was using a Stack Escape Hatch, which does work. Have I fundamentally misunderstood something, or is this simply not yet possible? It also seems that Escape Hatches on the ImportableResource
object don’t work at all.
I’d be grateful for any insights. Does anyone have an idea?
# This Module contains a Vault policy resource
from imports.test_module import TestModule
class MyStack(TerraformStack):
def __init__(self, scope: Construct, id: str):
super().__init__(scope, id)
VaultProvider(self, "vault", address="", )
test_module = TestModule(self, "dev",
module_arg = "a"
)
#myscope = Construct(self, "scope")
# using this as scope generates:
#"import": [
# {
# "id": "mypolicy",
# "to": "vault_policy.scope_moduledevvault_policymypolicy_80ABDBAC"
# }
# ],
p = Policy.generate_config_for_import(self, "module.dev.vault_policy.mypolicy", "mypolicy")
# generates:
#"import": [
# {
# "id": "mypolicy",
# "to": "vault_policy.moduletest-customervault_policymypolicy"
# }
# ],
#p.add_override("to", "module.dev.vault_policy.mypolicy")
# does not change anything
# p.override_logical_id("module.dev.vault_policy.mypolicy")
# best so far, but module path must preceed resource type, generates:
# "import": [
# {
# "id": "mypolicy",
# "to": "vault_policy.module.dev.vault_policy.mypolicy"
# }
# ],
self.add_override("import.0.to", "module.dev.vault_policy.mypolicy")
# works but is probably not most elegant way to do it, generates:
#"import": [
# {
# "id": "mypolicy",
# "to": "module.dev.vault_policy.mypolicy"
# }
# ],