The AFDBuilder class is designed to simplify the creation and configuration of Azure Front Door (AFD) resources using Pulumi. This class follows the Builder pattern, providing a fluent interface for defining various aspects of an AFD, including profiles, endpoints, custom domains, and response headers.
constructor(props: BuilderProps)
Initializes the AFDBuilder with the provided arguments.
Parameters:
props: BuilderProps - The basic configuration properties for the AFD resource.Usage:
const afdBuilder = new AFDBuilder({
name: 'my-front-door',
group: { resourceGroupName: 'my-resource-group' },
// other necessary arguments
});
withSdk(sdk: cdn.SkuName)Sets the SKU for the Azure Front Door.
Parameters:
sdk: cdn.SkuName - The SKU to set for the AFD:
Standard_AzureFrontDoor: Standard tier with basic featuresPremium_AzureFrontDoor: Premium tier with advanced security and performance featuresReturns: IAFDBuilder - The current AFDBuilder instance for method chaining.
Usage:
afdBuilder.withSdk(cdn.SkuName.Premium_AzureFrontDoor);
withCustomDomains(domains: string[])Sets custom domains for the Azure Front Door.
Parameters:
domains: string[] - Array of custom domain names to associate with the AFD.Returns: IAFDBuilder - The current AFDBuilder instance for method chaining.
Usage:
afdBuilder.withCustomDomains([
'www.example.com',
'api.example.com'
]);
withCustomDomainsIf(condition: boolean, domains: string[])Conditionally sets custom domains for the Azure Front Door.
Parameters:
condition: boolean - Whether to apply the custom domains.domains: string[] - Array of custom domain names to associate with the AFD.Returns: IAFDBuilder - The current AFDBuilder instance for method chaining.
Usage:
afdBuilder.withCustomDomainsIf(isProd, [
'www.example.com',
'api.example.com'
]);
withEndpoint(endpoint: AFDBuilderEndpoint)Sets the endpoint configuration for the Azure Front Door.
Parameters:
endpoint: AFDBuilderEndpoint - The endpoint configuration including routing rules and origins.Returns: IAFDBuilder - The current AFDBuilder instance for method chaining.
Usage:
afdBuilder.withEndpoint({
origins: [{
name: 'backend',
hostName: 'backend.example.com',
httpPort: 80,
httpsPort: 443
}],
routes: [{
name: 'default',
patterns: ['/*'],
originGroup: 'backend-group'
}]
} as AFDBuilderEndpoint);
withEndpointIf(condition: boolean, endpoint: AFDBuilderEndpoint)Conditionally sets the endpoint configuration for the Azure Front Door.
Parameters:
condition: boolean - Whether to apply the endpoint configuration.endpoint: AFDBuilderEndpoint - The endpoint configuration to set.Returns: IAFDBuilder - The current AFDBuilder instance for method chaining.
withResponseHeaders(headers: ResponseHeaderType)Sets custom response headers for the Azure Front Door.
Parameters:
headers: ResponseHeaderType - The response headers configuration to set.Returns: IAFDBuilder - The current AFDBuilder instance for method chaining.
Usage:
afdBuilder.withResponseHeaders({
'X-Content-Type-Options': 'nosniff',
'X-Frame-Options': 'DENY',
'X-XSS-Protection': '1; mode=block'
} as ResponseHeaderType);
withResponseHeadersIf(condition: boolean, headers: ResponseHeaderType)Conditionally sets custom response headers for the Azure Front Door.
Parameters:
condition: boolean - Whether to apply the response headers.headers: ResponseHeaderType - The response headers configuration to set.Returns: IAFDBuilder - The current AFDBuilder instance for method chaining.
build()Builds and deploys the AFD instance based on the current configuration.
Returns: ResourceInfo - Resource information for the deployed AFD instance.
Usage:
const afdResource = afdBuilder.build();
Here’s a complete example demonstrating how to use the AFDBuilder with all available properties:
import { AFDBuilder } from './Builder/AFDBuilder';
import * as cdn from '@pulumi/azure-native/cdn';
const afdBuilder = new AFDBuilder({
name: 'my-front-door',
group: { resourceGroupName: 'my-resource-group' },
// other necessary arguments
});
afdBuilder
.withSdk(cdn.SkuName.Premium_AzureFrontDoor)
.withCustomDomains([
'www.example.com',
'api.example.com'
])
.withEndpoint({
origins: [{
name: 'backend',
hostName: 'backend.example.com',
httpPort: 80,
httpsPort: 443
}],
routes: [{
name: 'default',
patterns: ['/*'],
originGroup: 'backend-group'
}]
} as AFDBuilderEndpoint)
.withResponseHeaders({
'X-Content-Type-Options': 'nosniff',
'X-Frame-Options': 'DENY',
'X-XSS-Protection': '1; mode=block'
} as ResponseHeaderType);
const afdResource = afdBuilder.build();
This guideline should help developers understand and reuse the methods in the AFDBuilder class effectively.