Expand description
UrlMaps are used to route requests to a backend service based on rules that you define for the host and path of an incoming URL.
To get more information about UrlMap, see:
§Example Usage
§Url Map Bucket And Service
resources:
urlmap:
type: gcp:compute:URLMap
properties:
name: urlmap
description: a description
defaultService: ${static.id}
hostRules:
- hosts:
- mysite.com
pathMatcher: mysite
- hosts:
- myothersite.com
pathMatcher: otherpaths
pathMatchers:
- name: mysite
defaultService: ${static.id}
pathRules:
- paths:
- /home
service: ${static.id}
- paths:
- /login
service: ${login.id}
- paths:
- /static
service: ${static.id}
- name: otherpaths
defaultService: ${static.id}
tests:
- service: ${static.id}
host: example.com
path: /home
login:
type: gcp:compute:BackendService
properties:
name: login
portName: http
protocol: HTTP
timeoutSec: 10
healthChecks: ${default.id}
default:
type: gcp:compute:HttpHealthCheck
properties:
name: health-check
requestPath: /
checkIntervalSec: 1
timeoutSec: 1
static:
type: gcp:compute:BackendBucket
properties:
name: static-asset-backend-bucket
bucketName: ${staticBucket.name}
enableCdn: true
staticBucket:
type: gcp:storage:Bucket
name: static
properties:
name: static-asset-bucket
location: US
§Url Map Traffic Director Route
ⓘ
use pulumi_wasm_rust::Output;
use pulumi_wasm_rust::{add_export, pulumi_main};
#[pulumi_main]
fn test_main() -> Result<(), Error> {
let default = health_check::create(
"default",
HealthCheckArgs::builder()
.http_health_check(
HealthCheckHttpHealthCheck::builder().port(80).build_struct(),
)
.name("health-check")
.build_struct(),
);
let home = backend_service::create(
"home",
BackendServiceArgs::builder()
.health_checks("${default.id}")
.load_balancing_scheme("INTERNAL_SELF_MANAGED")
.name("home")
.port_name("http")
.protocol("HTTP")
.timeout_sec(10)
.build_struct(),
);
let urlmap = url_map::create(
"urlmap",
UrlMapArgs::builder()
.default_service("${home.id}")
.description("a description")
.host_rules(
vec![
UrlMapHostRule::builder().hosts(vec!["mysite.com",])
.pathMatcher("allpaths").build_struct(),
],
)
.name("urlmap")
.path_matchers(
vec![
UrlMapPathMatcher::builder().defaultService("${home.id}")
.name("allpaths")
.routeRules(vec![UrlMapPathMatcherRouteRule::builder()
.headerAction(UrlMapPathMatcherRouteRuleHeaderAction::builder()
.requestHeadersToAdds(vec![UrlMapPathMatcherRouteRuleHeaderActionRequestHeadersToAdd::builder()
.headerName("AddSomethingElse").headerValue("MyOtherValue")
.replace(true).build_struct(),])
.requestHeadersToRemoves(vec!["RemoveMe2",])
.responseHeadersToAdds(vec![UrlMapPathMatcherRouteRuleHeaderActionResponseHeadersToAdd::builder()
.headerName("AddMe").headerValue("MyValue").replace(false)
.build_struct(),]).responseHeadersToRemoves(vec!["RemoveMe3",])
.build_struct())
.matchRules(vec![UrlMapPathMatcherRouteRuleMatchRule::builder()
.fullPathMatch("a full path")
.headerMatches(vec![UrlMapPathMatcherRouteRuleMatchRuleHeaderMatch::builder()
.exactMatch("match this exactly").headerName("someheader")
.invertMatch(true).build_struct(),]).ignoreCase(true)
.metadataFilters(vec![UrlMapPathMatcherRouteRuleMatchRuleMetadataFilter::builder()
.filterLabels(vec![UrlMapPathMatcherRouteRuleMatchRuleMetadataFilterFilterLabel::builder()
.name("PLANET").value("MARS").build_struct(),])
.filterMatchCriteria("MATCH_ANY").build_struct(),])
.queryParameterMatches(vec![UrlMapPathMatcherRouteRuleMatchRuleQueryParameterMatch::builder()
.name("a query parameter").presentMatch(true).build_struct(),])
.build_struct(),]).priority(1)
.urlRedirect(UrlMapPathMatcherRouteRuleUrlRedirect::builder()
.hostRedirect("A host").httpsRedirect(false)
.pathRedirect("some/path").redirectResponseCode("TEMPORARY_REDIRECT")
.stripQuery(true).build_struct()).build_struct(),]).build_struct(),
],
)
.tests(
vec![
UrlMapTest::builder().host("hi.com").path("/home")
.service("${home.id}").build_struct(),
],
)
.build_struct(),
);
}
§Url Map Traffic Director Route Partial
ⓘ
use pulumi_wasm_rust::Output;
use pulumi_wasm_rust::{add_export, pulumi_main};
#[pulumi_main]
fn test_main() -> Result<(), Error> {
let default = health_check::create(
"default",
HealthCheckArgs::builder()
.http_health_check(
HealthCheckHttpHealthCheck::builder().port(80).build_struct(),
)
.name("health-check")
.build_struct(),
);
let home = backend_service::create(
"home",
BackendServiceArgs::builder()
.health_checks("${default.id}")
.load_balancing_scheme("INTERNAL_SELF_MANAGED")
.name("home")
.port_name("http")
.protocol("HTTP")
.timeout_sec(10)
.build_struct(),
);
let urlmap = url_map::create(
"urlmap",
UrlMapArgs::builder()
.default_service("${home.id}")
.description("a description")
.host_rules(
vec![
UrlMapHostRule::builder().hosts(vec!["mysite.com",])
.pathMatcher("allpaths").build_struct(),
],
)
.name("urlmap")
.path_matchers(
vec![
UrlMapPathMatcher::builder().defaultService("${home.id}")
.name("allpaths")
.routeRules(vec![UrlMapPathMatcherRouteRule::builder()
.matchRules(vec![UrlMapPathMatcherRouteRuleMatchRule::builder()
.headerMatches(vec![UrlMapPathMatcherRouteRuleMatchRuleHeaderMatch::builder()
.exactMatch("match this exactly").headerName("someheader")
.invertMatch(true).build_struct(),]).prefixMatch("/someprefix")
.build_struct(),]).priority(1)
.urlRedirect(UrlMapPathMatcherRouteRuleUrlRedirect::builder()
.pathRedirect("some/path").redirectResponseCode("TEMPORARY_REDIRECT")
.build_struct()).build_struct(),]).build_struct(),
],
)
.tests(
vec![
UrlMapTest::builder().host("hi.com").path("/home")
.service("${home.id}").build_struct(),
],
)
.build_struct(),
);
}
§Url Map Traffic Director Path
resources:
urlmap:
type: gcp:compute:URLMap
properties:
name: urlmap
description: a description
defaultService: ${home.id}
hostRules:
- hosts:
- mysite.com
pathMatcher: allpaths
pathMatchers:
- name: allpaths
defaultService: ${home.id}
pathRules:
- paths:
- /home
routeAction:
corsPolicy:
allowCredentials: true
allowHeaders:
- Allowed content
allowMethods:
- GET
allowOriginRegexes:
- abc.*
allowOrigins:
- Allowed origin
exposeHeaders:
- Exposed header
maxAge: 30
disabled: false
faultInjectionPolicy:
abort:
httpStatus: 234
percentage: 5.6
delay:
fixedDelay:
seconds: 0
nanos: 50000
percentage: 7.8
requestMirrorPolicy:
backendService: ${home.id}
retryPolicy:
numRetries: 4
perTryTimeout:
seconds: 30
retryConditions:
- 5xx
- deadline-exceeded
timeout:
seconds: 20
nanos: 7.5e+08
urlRewrite:
hostRewrite: dev.example.com
pathPrefixRewrite: /v1/api/
weightedBackendServices:
- backendService: ${home.id}
weight: 400
headerAction:
requestHeadersToRemoves:
- RemoveMe
requestHeadersToAdds:
- headerName: AddMe
headerValue: MyValue
replace: true
responseHeadersToRemoves:
- RemoveMe
responseHeadersToAdds:
- headerName: AddMe
headerValue: MyValue
replace: false
tests:
- service: ${home.id}
host: hi.com
path: /home
home:
type: gcp:compute:BackendService
properties:
name: home
portName: http
protocol: HTTP
timeoutSec: 10
healthChecks: ${default.id}
loadBalancingScheme: INTERNAL_SELF_MANAGED
default:
type: gcp:compute:HealthCheck
properties:
name: health-check
httpHealthCheck:
port: 80
§Url Map Traffic Director Path Partial
ⓘ
use pulumi_wasm_rust::Output;
use pulumi_wasm_rust::{add_export, pulumi_main};
#[pulumi_main]
fn test_main() -> Result<(), Error> {
let default = health_check::create(
"default",
HealthCheckArgs::builder()
.http_health_check(
HealthCheckHttpHealthCheck::builder().port(80).build_struct(),
)
.name("health-check")
.build_struct(),
);
let home = backend_service::create(
"home",
BackendServiceArgs::builder()
.health_checks("${default.id}")
.load_balancing_scheme("INTERNAL_SELF_MANAGED")
.name("home")
.port_name("http")
.protocol("HTTP")
.timeout_sec(10)
.build_struct(),
);
let urlmap = url_map::create(
"urlmap",
UrlMapArgs::builder()
.default_service("${home.id}")
.description("a description")
.host_rules(
vec![
UrlMapHostRule::builder().hosts(vec!["mysite.com",])
.pathMatcher("allpaths").build_struct(),
],
)
.name("urlmap")
.path_matchers(
vec![
UrlMapPathMatcher::builder().defaultService("${home.id}")
.name("allpaths").pathRules(vec![UrlMapPathMatcherPathRule::builder()
.paths(vec!["/home",])
.routeAction(UrlMapPathMatcherPathRuleRouteAction::builder()
.corsPolicy(UrlMapPathMatcherPathRuleRouteActionCorsPolicy::builder()
.allowCredentials(true).allowHeaders(vec!["Allowed content",])
.allowMethods(vec!["GET",]).allowOriginRegexes(vec!["abc.*",])
.allowOrigins(vec!["Allowed origin",]).disabled(false)
.exposeHeaders(vec!["Exposed header",]).maxAge(30).build_struct())
.weightedBackendServices(vec![UrlMapPathMatcherPathRuleRouteActionWeightedBackendService::builder()
.backendService("${home.id}")
.headerAction(UrlMapPathMatcherPathRuleRouteActionWeightedBackendServiceHeaderAction::builder()
.requestHeadersToAdds(vec![UrlMapPathMatcherPathRuleRouteActionWeightedBackendServiceHeaderActionRequestHeadersToAdd::builder()
.headerName("AddMe").headerValue("MyValue").replace(true)
.build_struct(),]).requestHeadersToRemoves(vec!["RemoveMe",])
.responseHeadersToAdds(vec![UrlMapPathMatcherPathRuleRouteActionWeightedBackendServiceHeaderActionResponseHeadersToAdd::builder()
.headerName("AddMe").headerValue("MyValue").replace(false)
.build_struct(),]).responseHeadersToRemoves(vec!["RemoveMe",])
.build_struct()).weight(400).build_struct(),]).build_struct())
.build_struct(),]).build_struct(),
],
)
.tests(
vec![
UrlMapTest::builder().host("hi.com").path("/home")
.service("${home.id}").build_struct(),
],
)
.build_struct(),
);
}
§Url Map Header Based Routing
resources:
urlmap:
type: gcp:compute:URLMap
properties:
name: urlmap
description: header-based routing example
defaultService: ${default.id}
hostRules:
- hosts:
- '*'
pathMatcher: allpaths
pathMatchers:
- name: allpaths
defaultService: ${default.id}
routeRules:
- priority: 1
service: ${["service-a"].id}
matchRules:
- prefixMatch: /
ignoreCase: true
headerMatches:
- headerName: abtest
exactMatch: a
- priority: 2
service: ${["service-b"].id}
matchRules:
- ignoreCase: true
prefixMatch: /
headerMatches:
- headerName: abtest
exactMatch: b
default:
type: gcp:compute:BackendService
properties:
name: default
portName: http
protocol: HTTP
timeoutSec: 10
healthChecks: ${defaultHttpHealthCheck.id}
service-a:
type: gcp:compute:BackendService
properties:
name: service-a
portName: http
protocol: HTTP
timeoutSec: 10
healthChecks: ${defaultHttpHealthCheck.id}
service-b:
type: gcp:compute:BackendService
properties:
name: service-b
portName: http
protocol: HTTP
timeoutSec: 10
healthChecks: ${defaultHttpHealthCheck.id}
defaultHttpHealthCheck:
type: gcp:compute:HttpHealthCheck
name: default
properties:
name: health-check
requestPath: /
checkIntervalSec: 1
timeoutSec: 1
§Url Map Parameter Based Routing
resources:
urlmap:
type: gcp:compute:URLMap
properties:
name: urlmap
description: parameter-based routing example
defaultService: ${default.id}
hostRules:
- hosts:
- '*'
pathMatcher: allpaths
pathMatchers:
- name: allpaths
defaultService: ${default.id}
routeRules:
- priority: 1
service: ${["service-a"].id}
matchRules:
- prefixMatch: /
ignoreCase: true
queryParameterMatches:
- name: abtest
exactMatch: a
- priority: 2
service: ${["service-b"].id}
matchRules:
- ignoreCase: true
prefixMatch: /
queryParameterMatches:
- name: abtest
exactMatch: b
default:
type: gcp:compute:BackendService
properties:
name: default
portName: http
protocol: HTTP
timeoutSec: 10
healthChecks: ${defaultHttpHealthCheck.id}
service-a:
type: gcp:compute:BackendService
properties:
name: service-a
portName: http
protocol: HTTP
timeoutSec: 10
healthChecks: ${defaultHttpHealthCheck.id}
service-b:
type: gcp:compute:BackendService
properties:
name: service-b
portName: http
protocol: HTTP
timeoutSec: 10
healthChecks: ${defaultHttpHealthCheck.id}
defaultHttpHealthCheck:
type: gcp:compute:HttpHealthCheck
name: default
properties:
name: health-check
requestPath: /
checkIntervalSec: 1
timeoutSec: 1
§Url Map Path Template Match
resources:
urlmap:
type: gcp:compute:URLMap
properties:
name: urlmap
description: a description
defaultService: ${static.id}
hostRules:
- hosts:
- mysite.com
pathMatcher: mysite
pathMatchers:
- name: mysite
defaultService: ${static.id}
routeRules:
- matchRules:
- pathTemplateMatch: /xyzwebservices/v2/xyz/users/{username=*}/carts/{cartid=**}
service: ${["cart-backend"].id}
priority: 1
routeAction:
urlRewrite:
pathTemplateRewrite: /{username}-{cartid}/
- matchRules:
- pathTemplateMatch: /xyzwebservices/v2/xyz/users/*/accountinfo/*
service: ${["user-backend"].id}
priority: 2
cart-backend:
type: gcp:compute:BackendService
properties:
name: cart-service
portName: http
protocol: HTTP
timeoutSec: 10
loadBalancingScheme: EXTERNAL_MANAGED
healthChecks: ${default.id}
user-backend:
type: gcp:compute:BackendService
properties:
name: user-service
portName: http
protocol: HTTP
timeoutSec: 10
loadBalancingScheme: EXTERNAL_MANAGED
healthChecks: ${default.id}
default:
type: gcp:compute:HttpHealthCheck
properties:
name: health-check
requestPath: /
checkIntervalSec: 1
timeoutSec: 1
static:
type: gcp:compute:BackendBucket
properties:
name: static-asset-backend-bucket
bucketName: ${staticBucket.name}
enableCdn: true
staticBucket:
type: gcp:storage:Bucket
name: static
properties:
name: static-asset-bucket
location: US
§Url Map Custom Error Response Policy
ⓘ
use pulumi_wasm_rust::Output;
use pulumi_wasm_rust::{add_export, pulumi_main};
#[pulumi_main]
fn test_main() -> Result<(), Error> {
let default = http_health_check::create(
"default",
HttpHealthCheckArgs::builder()
.check_interval_sec(1)
.name("health-check")
.request_path("/")
.timeout_sec(1)
.build_struct(),
);
let error = backend_bucket::create(
"error",
BackendBucketArgs::builder()
.bucket_name("${errorBucket.name}")
.enable_cdn(true)
.name("error-backend-bucket")
.build_struct(),
);
let errorBucket = bucket::create(
"errorBucket",
BucketArgs::builder().location("US").name("static-asset-bucket").build_struct(),
);
let example = backend_service::create(
"example",
BackendServiceArgs::builder()
.health_checks("${default.id}")
.load_balancing_scheme("EXTERNAL_MANAGED")
.name("login")
.port_name("http")
.protocol("HTTP")
.timeout_sec(10)
.build_struct(),
);
let urlmap = url_map::create(
"urlmap",
UrlMapArgs::builder()
.default_custom_error_response_policy(
UrlMapDefaultCustomErrorResponsePolicy::builder()
.errorResponseRules(
vec![
UrlMapDefaultCustomErrorResponsePolicyErrorResponseRule::builder()
.matchResponseCodes(vec!["5xx",]).overrideResponseCode(502)
.path("/internal_error.html").build_struct(),
],
)
.errorService("${error.id}")
.build_struct(),
)
.default_service("${example.id}")
.description("a description")
.host_rules(
vec![
UrlMapHostRule::builder().hosts(vec!["mysite.com",])
.pathMatcher("mysite").build_struct(),
],
)
.name("urlmap")
.path_matchers(
vec![
UrlMapPathMatcher::builder()
.defaultCustomErrorResponsePolicy(UrlMapPathMatcherDefaultCustomErrorResponsePolicy::builder()
.errorResponseRules(vec![UrlMapPathMatcherDefaultCustomErrorResponsePolicyErrorResponseRule::builder()
.matchResponseCodes(vec!["4xx", "5xx",]).overrideResponseCode(404)
.path("/login_error.html").build_struct(),
UrlMapPathMatcherDefaultCustomErrorResponsePolicyErrorResponseRule::builder()
.matchResponseCodes(vec!["503",]).overrideResponseCode(502)
.path("/bad_gateway.html").build_struct(),])
.errorService("${error.id}").build_struct())
.defaultService("${example.id}").name("mysite")
.pathRules(vec![UrlMapPathMatcherPathRule::builder()
.customErrorResponsePolicy(UrlMapPathMatcherPathRuleCustomErrorResponsePolicy::builder()
.errorResponseRules(vec![UrlMapPathMatcherPathRuleCustomErrorResponsePolicyErrorResponseRule::builder()
.matchResponseCodes(vec!["4xx",]).overrideResponseCode(401)
.path("/login.html").build_struct(),]).errorService("${error.id}")
.build_struct()).paths(vec!["/private/*",]).service("${example.id}")
.build_struct(),]).build_struct(),
],
)
.build_struct(),
);
}
§Import
UrlMap can be imported using any of these accepted formats:
-
projects/{{project}}/global/urlMaps/{{name}}
-
{{project}}/{{name}}
-
{{name}}
When using the pulumi import
command, UrlMap can be imported using one of the formats above. For example:
$ pulumi import gcp:compute/uRLMap:URLMap default projects/{{project}}/global/urlMaps/{{name}}
$ pulumi import gcp:compute/uRLMap:URLMap default {{project}}/{{name}}
$ pulumi import gcp:compute/uRLMap:URLMap default {{name}}
Structs§
- Use builder syntax to set the inputs and finish with
build_struct()
.
Functions§
- Registers a new resource with the given unique name and arguments