pulumi-azure-native icon indicating copy to clipboard operation
pulumi-azure-native copied to clipboard

ExportConfiguration resource requires a POST for creation

Open pierskarsenbarg opened this issue 3 years ago • 8 comments

Hello!

  • Vote on this issue by adding a 👍 reaction
  • To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already)

Issue details

When creating an ExportConfiguration resource we need to pass in the storage account SAS URL which we get from listStorageAccountSAS. However, it looks like when we're passing the URL to Azure in the ExportConfiguration resource we're encoding it incorrectly.

Steps to reproduce

  1. Clone repo here: https://github.com/pierskarsenbarg/export-config
  2. Run pulumi up
  3. Uncomment these lines
  4. Run pulumi up again

Error message:

    error: autorest/azure: Service returned an error. Status=404 Code="NotFound" Message="Not Found" InnerError={"diagnosticcontext":"0a95e454-db5c-4da9-9cb9-fd7edb708dfa","time":"2021-11-09T13:17:16.0988585Z"}

If you look at the logs you'll see that this is the URL we send over as the DestinationAddress: https://sa19bcc911.blob.core.windows.net/appinsights?sv=2015-04-05\u0026ss=b\u0026srt=c\u0026sp=w\u0026se=2024-11-08T13%3A18%3A05.2440000Z\u0026sig=wiyt6mVUxblf6Mvn9wIYYhX32ezFiPx6YvyY4mAR600%3D which looks like we're encoding the URL as UTF-8 (?)

pierskarsenbarg avatar Nov 09 '21 13:11 pierskarsenbarg

I think that encoding is by design, here is a comment from the json.Marshal function that is used by Go Autorest to encode the payload:

String values encode as JSON strings coerced to valid UTF-8, replacing invalid bytes with the Unicode replacement rune. So that the JSON will be safe to embed inside HTML

Unicode-encoded characters are valid JSON AFAIK. As this function is provided by Microsoft's SDK, I hope somebody would notice if it was problematic.

Now, the question is what actually goes wrong. Maybe, try doing this with the portal and then exporting the resulting ARM template to see what's different?

mikhailshilkov avatar Nov 09 '21 14:11 mikhailshilkov

When I try to create the ExportConfiguration using powershell eg.

`$sastoken = New-AzStorageContainerSASToken -Name appinsights82a92963 -ExpiryTime (Get-Date).AddYears(50) -Permission w

$sasuri = "https://blahblah.blob.core.windows.net/appinsights82a92963" + $sastoken

New-AzApplicationInsightsContinuousExport -ResourceGroupName "resourcegroupname" -Name "appinsights8305d678" -DocumentType "Request","Trace", "Custom Event" -StorageAccountId "/subscriptions/sid/resourceGroups/resourcegroup/providers/Microsoft.Storage/storageAccounts/7e1f6cc" -StorageLocation "uksouth" -StorageSASUri $sasuri`

it all works fine, but fails in Pulumi as the SAS token has unescaped characters in it

andyunsieso avatar Nov 09 '21 14:11 andyunsieso

@andyunsieso Could you please export the resulting ARM template? As you can see, Powershell is quite different in terms of parameter names etc.

mikhailshilkov avatar Nov 09 '21 15:11 mikhailshilkov

I have tried exporting the ARM template for the app insights using Azure Portal and powershell. It exports a number of types but won't export the export coniguration and says -

"Could not get resources of the type 'components/exportconfiguration'. Resources of this type will not be exported."}]}

andyunsieso avatar Nov 09 '21 18:11 andyunsieso

I managed to create a continuous export using the azure cli, but when I tried to inspect it I got the following message:

image

It seems that continuous export is being deprecated by Azure: https://docs.microsoft.com/en-us/azure/azure-monitor/app/export-telemetry which is probably why we can't get an export

pierskarsenbarg avatar Nov 10 '21 10:11 pierskarsenbarg

Okay, I logged what the Azure CLI does and apparently if does POST to the .../exportconfiguration URL.

Instead, Pulumi sends a PUT to the .../exportconfiguration/{name} URL and the API doesn't support creation via PUT. It turns out this API is from 2015 and isn't compliant to ARM API standards (where PUT has to do both Create and Update and be idempotent).

Effectively, this resource is broken until we teach it to send POST requests.

You should be able to import an existing resource and manage it further, if that helps.

mikhailshilkov avatar Nov 10 '21 13:11 mikhailshilkov

Thanks, will probably use power shell to create the ExportConfiguration in the first instance

andyunsieso avatar Nov 10 '21 13:11 andyunsieso

On February 29, 2024, continuous export will be deprecated as part of the classic Application Insights deprecation. source

So it's probably not worth investing into this particular resource. See #3018.

thomas11 avatar Jan 13 '24 20:01 thomas11