Is there a way to reference existing resources, wi...
# general
s
Is there a way to reference existing resources, without knowing it's exact id? Mostly in context of resources being created automatically, outside of Pulumi control - e.g. anomaly detection in Azure. I'd like to search if there is one in the resource group, but I can't know it's id/name, just type and scope. Is that possible?
d
Not with resources, but some providers give functions that are a bit more flexible. For anomalies in Azure, the Azure Native provider has the
getanomalies
function, though this doesn't seem available in the Classic provider. https://www.pulumi.com/registry/packages/azure-native/api-docs/securityinsights/getanomalies/
s
we're using the native one, for .net
hm, but that seems to return the found anomalies
d
Usually if I need flexibility, I'll use other libraries along with Pulumi. Power of using a real language is you're not locked into just using the framework 😉
s
and not the detector itself, right?
d
unsure on azure specifics, sorry
s
yeah, but our problem is with pulumi directly, cause anomaly detector can be defined just once, but its being recreated on many occassions causing deployment to fail
being able to look up its reference and use that could prevent pulumi from triggering another creation
for operations later on, sure, we use other technologies too 🙂
d
best bet is looking for if the provider has those
get
functions that have filtering then. They generally don't require knowing a name
s
/// <summary>
/// Get an existing SmartDetectorAlertRule resource's state with the given name, ID, and optional extra
/// properties used to qualify the lookup.
/// </summary>
///
/// <param name="name">The unique name of the resulting resource.</param>
/// <param name="id">The unique provider ID of the resource to lookup.</param>
/// <param name="options">A bag of options that control this resource's behavior</param>
public static SmartDetectorAlertRule Get(string name, Input<string> id, CustomResourceOptions? options = null)
{
return new SmartDetectorAlertRule(name, id, options);
}
looks like this is the only one