pulumi / pulumi-azure-native

Azure Native Provider
Apache License 2.0
125 stars 33 forks source link

azure-native.eventgrid.EventSubscription resource ID es wrong in Typescript #3405

Open joseaznar opened 4 weeks ago

joseaznar commented 4 weeks ago

What happened?

When creating an EventSubscrition using Typescript we get an error and checking the Activity Log it's a 404 error because the resource ID isn't constructed correctly, in the following JSON you can see the error in the Activity Log:

"resourceId": "/subscriptions/****/resourceGroups/****/providers/Microsoft.EventGrid/namespaces/****/topics/****/providers/Microsoft.EventGrid/eventSubscriptions/sendToEventHub", "status": { "value": "Failed", "localizedValue": "Failed" }, "subStatus": { "value": "NotFound", "localizedValue": "Not Found (HTTP Status Code: 404)" },

When reviewing one created manually, the resource ID is as the following:

/subscriptions/****/resourceGroups/****/providers/Microsoft.EventGrid/namespaces/***/topics/****/eventSubscriptions/sendToEventHub

We can see there is a providers/Microsoft.EventGrid block at the end that is not needed.

Example

const eventSubscription = new azure_native.eventgrid.EventSubscription("eventSubscription", {
            eventSubscriptionName: "sendToEventHub",
            scope: eventGridTopicId,
            eventDeliverySchema: "CloudEventSchemaV1_0",
            deliveryWithResourceIdentity: {
                destination: {
                    endpointType: "EventHub",
                    resourceId: this.eventHubTopicId,
                },
                identity: {
                    type: "UserAssigned",
                    userAssignedIdentity: miEventGridPrincipalId,
                },
            },
        },
            {
                parent: this,
                dependsOn: [eventHub]
            });

Where the this.eventHubTopicId comes from the following output

this.eventGridTopicId = eventGridTopic.id.apply(id => id);

Output of pulumi about

Unable to give this information, but this is the package.json

{ "name": "***", "main": "index.ts", "devDependencies": { "@types/node": "^20" }, "dependencies": { "@pulumi/azure-native": "^2.47.1", "@pulumi/command": "^0.11.1", "@pulumi/pulumi": "^3.121.0" } }

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

thomas11 commented 3 weeks ago

Hi @joseaznar, sorry you're running into this issue. I tried to reproduce it but, not knowing EventHub and EventGrid well, I wasn't able to since a few required resources are missing from your example. It would be very helpful if you could provide a working program that shows the issue.

What I have so far fails with 400 "Invalid property".

import * as eventgrid from "@pulumi/azure-native/eventgrid";
import * as eventhub from "@pulumi/azure-native/eventhub";
import * as resources from "@pulumi/azure-native/resources";

const resourceGroup = new resources.ResourceGroup("resourceGroup");

const eventhubNs = new eventhub.Namespace("eventHubNamespace", {
    resourceGroupName: resourceGroup.name,
});

const eventHub = new eventhub.EventHub("eventHub", {
    resourceGroupName: resourceGroup.name,
    namespaceName: eventhubNs.name,
});

const eventGridTopic = new eventgrid.Topic("eventGridTopic", {
    resourceGroupName: resourceGroup.name,
});

const eventSubscription = new eventgrid.EventSubscription("eventSubscription", {
    eventSubscriptionName: "sendToEventHub",
    scope: eventGridTopic.id,
    eventDeliverySchema: "CloudEventSchemaV1_0",
    deliveryWithResourceIdentity: {
        destination: {
            endpointType: "EventHub",
            resourceId: eventHub.id,
        },
    },
});

export const topicId = eventGridTopic.id;
export const eventHubId = eventHub.id;

In your issue description eventGridTopicId and eventHubTopicId might have gotten mixed up. Could you clarify each one? Also, generally, you shouldn't need apply(id => id) and should be able to use id directly; is that not the case here?

Finally, could you also add the actual Pulumi output from when it fails?