pulumi / pulumi-azure-native

Azure Native Provider
Apache License 2.0
127 stars 34 forks source link

Make imports case-insensitive #2010

Open ottosulin opened 2 years ago

ottosulin commented 2 years ago

What happened?

I was trying to run:

pulumi import azure-native:operationalinsights:workspace dev-logs /subscriptions/xx/resourcegroups/xx/providers/microsoft.operationalinsights/workspaces/dev-logs

Steps to reproduce

I was able to import a virtual network, but not a resource group or log analytics workspace, which is quite strange.

Expected Behavior

Generated code would appear.

Actual Behavior

But I got the following response (no more details even with increased verbosity and debug flag):

    error: preview failed

  azure-native:operationalinsights:workspace (dev-logs):
    error: Preview failed: autorest/azure: Service returned an error. Status=400 Code="MissingApiVersionParameter" Message="The api-version query parameter (?api-version=) is required for all requests."

Output of pulumi about

CLI          
Version      3.40.2
Go Version   go1.19.1
Go Compiler  gc

Plugins
NAME          VERSION
azure-native  1.74.0
go            unknown

Host     
OS       darwin
Version  12.6
Arch     arm64

This project is written in go: executable='/usr/local/go/bin/go' version='go version go1.19 darwin/arm64'

Current Stack: infra

TYPE                                  URN
pulumi:pulumi:Stack                   urn:pulumi:infra::dev::pulumi:pulumi:Stack::dev-infra
pulumi:providers:azure-native         urn:pulumi:infra::dev::pulumi:providers:azure-native::default
azure-native:network:VirtualNetwork   urn:pulumi:infra::dev::azure-native:network:VirtualNetwork::dev_vnet
azure-native:resources:ResourceGroup  urn:pulumi:infra::dev::azure-native:resources:ResourceGroup::resourceGroup

Found no pending operations associated with infra

Backend        
Name           xxx
URL            azblob://pulumidev
User           otto
Organizations  

Dependencies:
NAME                                       VERSION
github.com/pulumi/pulumi-azure-native/sdk  1.74.0
github.com/pulumi/pulumi/sdk/v3            3.39.1

Pulumi locates its logs in /var/folders/zx/3548g95x14xgsg9mz76stl280000gp/T/ by default

Additional context

No response

Contributing

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).

danielrbradley commented 2 years ago

Hello @ottosulin according to this part of the error message:

The api-version query parameter (?api-version=) is required for all requests

you need to add ?api-version= to your import statement e.g.

pulumi import \
  azure-native:operationalinsights:workspace dev-logs \
  /subscriptions/xx/resourcegroups/xx/providers/microsoft.operationalinsights/workspaces/dev-logs?api-version=[INSERT_VERSION_HERE]
danielrbradley commented 2 years ago

Actually, it looks like that's an internal message. Will look into what's the correct incantation is to get the import working.

scp-mb commented 2 years ago

@ottosulin @danielrbradley I seem to recall seeing this before, If my memory serves correctly I think it was down to the resource type being case sensitive, e.g. azure-native:operationalinsights:workspace should be azure-native:operationalinsights:Workspace

Don't quote me on that though. I could be misremembering.

mikahozz commented 1 year ago

I can verify that the case is significant here. For example: pulumi import azure-native:network:applicationgateway fails but pulumi import azure-native:network:ApplicationGateway works.

danielrbradley commented 1 year ago

Thank you both for the feedback, will re-close as resolved then.

scp-mb commented 1 year ago

@danielrbradley Changes either to the message or making the command case insensitive would be a good idea, as it's still confusing if you aren't aware of that quirk.

gainskills commented 1 year ago

It always fails when importing Azure front door rule even though ?api-version=2022-11-01-preview was added.

the error message:

  azure-native:cdn:Rule (name):
    error: autorest/azure: Service returned an error. Status=400 Code="BadRequest" Message="One or more rules contains actions 'RouteConfigurationOverride' that are not supported in the current API version. Please use the correct API version to retrieve the resource."

  pulumi:pulumi:Stack (FrontdoorIac-ZenoProd):
    error: update failed

related module: https://www.pulumi.com/registry/packages/azure-native/api-docs/cdn/rule/

but same URL works when testing with https://learn.microsoft.com/en-us/rest/api/frontdoor/azurefrontdoorstandardpremium/rules/get#code-try-0

Hello @ottosulin according to this part of the error message:

The api-version query parameter (?api-version=) is required for all requests

you need to add ?api-version= to your import statement e.g.

pulumi import \
  azure-native:operationalinsights:workspace dev-logs \
  /subscriptions/xx/resourcegroups/xx/providers/microsoft.operationalinsights/workspaces/dev-logs?api-version=[INSERT_VERSION_HERE]
danielrbradley commented 1 year ago

@gainskills the comment you quoted was incorrect - you should not need to include the api-version - this is automatically resolved by the provider. The issue identified by scp-mb and mikaahopelto is that the type token must be an exact match - including case.

The message you're getting is different

One or more rules contains actions 'RouteConfigurationOverride' that are not supported in the current API version. Please use the correct API version to retrieve the resource.

My first suggestion would be to look at the features you're using on the resource as it sounds like Azure is refusing to let you use and older version of the API which doesn't support the feature. You could instead use an explicit version of the resource such as azure-native:cdn/v20230501:Rule or azure-native:cdn/v20221101preview:Rule

gainskills commented 1 year ago

@gainskills the comment you quoted was incorrect - you should not need to include the api-version - this is automatically resolved by the provider. The issue identified by scp-mb and mikaahopelto is that the type token must be an exact match - including case.

The message you're getting is different

One or more rules contains actions 'RouteConfigurationOverride' that are not supported in the current API version. Please use the correct API version to retrieve the resource.

My first suggestion would be to look at the features you're using on the resource as it sounds like Azure is refusing to let you use and older version of the API which doesn't support the feature. You could instead use an explicit version of the resource such as azure-native:cdn/v20230501:Rule or azure-native:cdn/v20221101preview:Rule

awesome, it works with

pulumi import azure-native:cdn/v20221101preview:Rule ruleName "/subscriptions/subId/resourceGroups/rgName/providers/Microsoft.Cdn/profiles/afdName/ruleSets/rulesetName/rules/ruleName?api-version=2022-11-01-preview"

thanks for your help @danielrbradley