Hey, need some help. I want to import a handful of...
# general
Hey, need some help. I want to import a handful of existing resources. The resources to import need to be gathered at runtime. I need to search the cloud provider (aws for me) by tag, then import all resources with that tag. I feel like this is a dumb question, but I can't figure out how to query the cloud provider in this way using Pulumi, can anyone point me in the right direction on how to do this? Or, if such a mechanism doesn't exist in Pulumi, what's an alternative? Is it common to import the aws sdk to query what I need, then use Pulumi's "import_" to bring them under the Pulumi umbrella?
You can query for specific resource types by tag, there's a get static function in each class. Also, there's the AWS SDK that you can use.
In general, "dynamic" importing like this isn't done. If you need to import something, then you know its ID. You need code to describe each resource, so to do what you're describing, you'd need to dynamically generate the correct code.
pulumi import
will create snippets but it's up to you to put those in your pulumi program. And what you're describing won't do that.
I appreciate the input. I know it sounds a little odd to be dynamically importing like this. I agree, static imports of already known resources have been just fine for a couple small projects of mine. Let me explain a little more, if just for your reaction to make sure I'm not way off-base on my approach. A development team is going to have a web app, that web app will be creating dynamodb tables. I need to setup event sourcing on all these tables. To automate, as part of the apps' cicd, i was going to run Pulumi to gather the list of tables, and hook them up to kenisis/kafka. Does that seem reasonable?
Copy code
    "I don't know all of these tables.",
    "But if I just query my infrastructure and put them into a list.",
    "I'll be fine, the below already works.",

for table in TABLES:
    tbl = aws.dynamodb.Table.get(id=table, resource_name=table, )
    stream_destination = aws.dynamodb.KinesisStreamingDestination(f"{table}-stream", stream_arn=stream.arn, table_name=tbl.name)
I think you're going to run into issues here because you're going to have multiple sources of truth, but if you really want to go down this path you can use the AWS SDK to do the query from within your program. However, if you have the ability to change the app, I would highly recommend having the application changed to use Pulumi's automation API to create the tables correctly in the first place
Thanks! Totally agree, I would normally do what you have recommended, but I'm having to compromise on this ownership detail.