I know this is very esoteric, but does anyone have...
# azure
l
I know this is very esoteric, but does anyone have any experience importing a Diagnostic Setting on an App Insights component in an existing stack?
Or I guess a Diagnostic Setting anywhere
I’ve been fighting with it off and on for a little while now, the commands in the documentation don’t seem to work. Pulumi always says it can’t find the resource, but will also tell me it can’t create a resource with the same name either because it already exists
I’m sure I’m just doing something naive but I can’t find any other examples online anywhere
i
Can you share what you’re currently trying?
l
yep yep
Yeah I can share the command I’m using, lemme just change up some the names in there to be more generic
Copy code
pulumi import \
  azure-native:insights:DiagnosticSetting \
  prod-audit-diagnostic \
  /subscriptions/abc1234-d123-1f23-fecd-abcde123456/resourceGroups/production-resource-group/providers/Microsoft.KeyVault/vaults/prod-audit/providers/microsoft.insights/diagnosticSettings/prod-audit-diagnostic \
  -s productionuk-stack
i
you’re getting the error:
Copy code
cannot create already existing resource '/***/providers/Microsoft.Insights/diagnosticSettings/NAME'
i also get:
Copy code
error: autorest/azure: Service returned an error. Status=<nil> <nil>
I managed to get it to work just now by removing the
Metrics
section
image.png
okay, i think i understand now - I deleted all my diagnostic collectors that I had manually created and then was able to create through Pulumi. The reason why it worked for me when I removed ‘AllMetrics’ is because ‘AllMetrics’ is probably already being collected elsewhere. When I tried to create a new Diagnostic Setting pointing to the same sink - I got this error:
Copy code
<resource> is already used in diagnostic setting 'FrontDoor' for category 'FrontDoorAccessLog'. Data sinks can't be reused in different settings on the same category for the same resource."}.
after i created the initial resource, i was able to add the
AllMetrics
block to pulumi and then it magically worked with logs and metrics
image.png
was able to successfully reproduce this in another subscription