stela
stela

Reputation: 59

Error creating Azure CDN Endpoint: Invalid HostName - Must be a valid domain name, IP version 4, or IP version 6

I'm trying to create an Azure CDN endpoint using CDKTF, but I'm encountering an error that I can't seem to resolve. The error message I'm getting is:Error: creating Endpoint: (Name "test" / Profile Name "test-profile" / Resource Group "test-rg"): cdn.EndpointsClient#Create: Failure sending request: StatusCode=400 -- Original Error: Code="BadRequest" Message="HostName \"https://testmain.z6.web.core.windows.net/" is invalid. It must be a valid domain name, IP version 4, or IP version 6."

const cdnProfile = 
new CdnProfile(this, env.CreateId(profileNameId), {
      name: env.CreateId(profileNameId),
      location: 'Global',
      sku: SkuType.Premium_Verizon,
      resourceGroupName: resGroup.name,
});

const hostName = mainStorageAccount.primaryWebEndpoint.replace(/^https?:\/\//, '').replace(/\/$/, '');
const cdnEndpointConfig = {
  name: env.CreateId(cdnEndpointId),
  profileName: cdnProfile.name,
  location: Region.WEST_EUROPE,
  resourceGroupName: resGroup.name,

  querystringCachingBehaviour: 'NotSet',
  optimizationType: 'GeneralWebDelivery',
  isCompressionEnabled: false,
  origin: [
    {
      name: mainStorageAccount.name,
      hostName: hostName,
      httpPort: 80,
      httpsPort: 443,
    },
  ],
};
new CdnEndpoint(this, cdnEndpointConfig.name, cdnEndpointConfig);

I'm not sure how to correctly format it to satisfy the CDN endpoint creation.
How can I properly format the hostName to meet the requirements of a valid domain name,any help would be greatly appreciated.

Upvotes: 0

Views: 326

Answers (1)

stela
stela

Reputation: 59

Update: If you're encountering the same issue: Don't bother with using mainStorageAccount.primaryWebEndpoint and struggling with replacements that don't work. Simply use mainStorageAccount.primaryWebHost as your origin host name.

Upvotes: 0

Related Questions