Hi guys! I have some challenges working with dyna...
# python
s
Hi guys! I have some challenges working with dynamicly generated resources in Pulumi. Specifically, I am trying to figure out how to reference the resources I create in this code block:
Copy code
# Define the list of catalogs and schemas
catalog_schema_list = {
    db_catalogs.db_catalog_source: [
        {"schema_name": "general"}
    ],
    db_catalogs.db_catalog_archive: [
        {"schema_name": "general"}
    ], 
    db_catalogs.db_catalog_model: [
        {"schema_name": "general"}
    ]
}

# Loop through the list and create the schemas dynamically
for catalog, schemas in catalog_schema_list.items():
    for schema_name in schemas:

    # Construct a unique resource name to resolve Output values
        resource_name = pulumi.Output.concat("db_schema_", catalog.name, "_", schema_name["schema_name"],"_")\
            .apply(lambda name: name.replace("_dev", "").replace("_", "-") + constants.config_env_name)

        resource_name.apply(lambda rn: databricks.Schema(
            rn,
            name=schema_name["schema_name"],
            owner=db_usermanagement.service_principal.application_id,
            metastore_id=db_metastore.metastore.id,
            catalog_name=catalog.name,
            opts=pulumi.ResourceOptions(
                provider=db_workspaces.provider_db_workspace_env
                ,parent=catalog
            )
        ))
"Normally" (eg. creating resources without a loop), I can reference the resource using the name like "db_schema_source_general" in the below code:
Copy code
db_schema_source_general = databricks.Schema("db-catalog-source-general-"+ constants.config_env_name
    ,name="general"
    ,owner= db_usermanagement.service_principal.application_id
    ,metastore_id=db_metastore.metastore.id
    ,catalog_name=db_catalogs.db_catalog_source.name
    #,opts=pulumi.ResourceOptions(parent=db_catalog_source)
    ,opts=pulumi.ResourceOptions(provider=db_workspaces.provider_db_workspace_env,parent=db_catalogs.db_catalog_source)
)