https://pulumi.com logo
Title
r

refined-tomato-5322

04/08/2021, 6:51 AM
Hi all. I'm still wrestling with setting up endpoints. I'm getting an InvalidResource error along with the message "Invalid @odata.type property value". I'm sure I'm certain I'm doing something ridiculously stupid here. I've attempted using the Microsoft.Azure.Management.Cdn.Models NameSpace classes from here: MS Docs, and of course from the Pulumi Docs with no luck. Any insights would be appreciated. Here is my code (TypeScript):
addCdnEndpoint(cdnProfile: cdn.Profile, durationOfCache?: string) {
        this.endpoint = new cdn.Endpoint(this.baseName, {
            endpointName: this.storageAccount.name.apply(sa => `cdn-endpnt-${sa}`),
            location: cdnProfile.location,
            resourceGroupName: this.resourceGroup.name,
            isHttpAllowed: false,
            isHttpsAllowed: true,
            originHostHeader: this.endpointOrigin,
            profileName: cdnProfile.name,
            origins: [{
                hostName: this.endpointOrigin,
                httpsPort: 443,
                name: "blobstorage",
            }],
            deliveryPolicy: {
                description: "Test description for a policy.",
                rules: [{
                    name: "httptohttps",
                    order: 1,
                    conditions: [{
                        name: "RequestScheme",
                        parameters: {
                            matchValues: [ "HTTP" ],
                            odataType: "#Microsoft.Azure.Cdn.Models.DeliveryRuleRequestSchemeConditionResponse",
                            operator: "Any",
                        },
                    }],
                    actions: [
                        {
                            name: "UrlRedirect",
                            parameters: {
                                destinationProtocol: "https",
                                redirectType: "PermanentRedirect",
                                odataType: "#Microsoft.Azure.Cdn.Models.UrlRewriteAction",
                            },
                        }
                    ],
                    },
                    {
                    name: "cachebehavior",
                    order:2,
                    actions: [
                        durationOfCache ? {
                            name: "CacheExpiration",
                            parameters: {
                                cacheBehavior: "Override",
                                cacheDuration: durationOfCache,
                                cacheType: "All",
                                odataType: "#Microsoft.Azure.Cdn.Models.DeliveryRuleCacheExpirationActionParameters",
                            },
                        } :
                        {
                            name: "CacheExpiration",
                            parameters: {
                                cacheBehavior: "BypassCache",
                                cacheType: "All",
                                odataType: "#Microsoft.Azure.Cdn.Models.DeliveryRuleCacheExpirationActionParameters",
                            },
                        },                             
                    ]    
                    },
                ],
            },
            
        });
Thank you in advance for any help.
t

tall-librarian-49374

04/08/2021, 7:28 AM
I can’t spot any problems with this… If you are okay sharing the logs, could you run
pulumi up --skip-preview --yes -v=9 --debug --logflow --logtostderr
and send the output to mikhail@pulumi.com ?
r

refined-tomato-5322

04/08/2021, 1:36 PM
Thank you so much @tall-librarian-49374! I will get this sent over to you. E-mail will come from michael@lundie.io . Cheers!
t

tall-librarian-49374

04/08/2021, 3:10 PM
Thank you for the logs. Again, the HTTP logs look good to me so I’m not sure what Azure complains about… It looks fairly similar to e.g. this example https://github.com/Azure/azure-rest-api-specs/blob/master/specification/cdn/resour[…]/Microsoft.Cdn/stable/2020-09-01/examples/Endpoints_Create.json Have you tried reducing the resource to a single property with
odataType
to understand which one is to blame, or whether they are all broken?
r

refined-tomato-5322

04/09/2021, 1:21 AM
Have you tried reducing the resource to a single property with 
odataType
 to understand which one is to blame, or whether they are all broken?
Absolutely. It seems to be a problem with all of them. I'll experiment with the templates you linked to and see if I have the same problem. Thank you very much!
t

tall-librarian-49374

04/09/2021, 6:10 AM
Odd… Please share your findings. I really want to understand this.
r

refined-tomato-5322

04/09/2021, 2:51 PM
I finally figured this out. Thank you again for all of your help. It was something relatively "simple" in the end. My confusion perhaps came from the lack of consistency in naming of the input types which corresponded to the cdn.models name space. (I'm also new to Azure and Pulumi, so I'm certain my lack of experience plays a big part in my confusion!) Take the example below (which is now correct):
conditions: [ {
  name: "RequestScheme",
  parameters: {
    operator: "Equal",
    matchValues: [  "HTTP"  ],
    odataType:"#Microsoft.Azure.Cdn.Models.DeliveryRuleRequestSchemeConditionParameters"
  }
}],
The parameters expected input type is:
parameters: pulumi.Input<inputs.cdn.RequestSchemeMatchConditionParameters
So I had initially assumed odataType namespace would be the same. Looking at the Azure Docs gets me closer to the actual type - but not quite. The correct odataType model was in fact "DeliveryRuleRequestSchemeConditionParameters". (I wonder why it is not: "DeliveryRuleRequestScheme_*Match*_ConditionParameters".) The templates you linked to made me realise the naming conventions being used and with some experimentation I managed to get there. The correct types were as follows: for "UrlRedirect" Action: #Microsoft.Azure.Cdn.Models.DeliveryRuleUrlRedirectActionParameters for "RequestScheme" Condition: #Microsoft.Azure.Cdn.Models.DeliveryRuleRequestSchemeConditionParameters for "CacheExpiration" action: #Microsoft.Azure.Cdn.Models.DeliveryRuleCacheExpirationActionParameters Thank you again very much!
t

tall-librarian-49374

04/09/2021, 2:58 PM
Oh, I see. So you are able to pass arbitrary values as
odataType
? I was hoping we would validate it if it was wrong.