UNPKG

@pulumi/gcp

Version:

A Pulumi package for creating and managing Google Cloud Platform resources.

805 lines • 27.1 kB
"use strict"; // *** WARNING: this file was generated by the Pulumi Terraform Bridge (tfgen) Tool. *** // *** Do not edit by hand unless you're certain you know what you are doing! *** Object.defineProperty(exports, "__esModule", { value: true }); exports.URLMap = void 0; const pulumi = require("@pulumi/pulumi"); const utilities = require("../utilities"); /** * 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: * * * [API documentation](https://cloud.google.com/compute/docs/reference/rest/v1/urlMaps) * * How-to Guides * * [Official Documentation](https://cloud.google.com/load-balancing/docs/url-map-concepts) * * ## Example Usage * * ### Url Map Bucket And Service * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const _default = new gcp.compute.HttpHealthCheck("default", { * name: "health-check", * requestPath: "/", * checkIntervalSec: 1, * timeoutSec: 1, * }); * const login = new gcp.compute.BackendService("login", { * name: "login", * portName: "http", * protocol: "HTTP", * timeoutSec: 10, * healthChecks: _default.id, * }); * const staticBucket = new gcp.storage.Bucket("static", { * name: "static-asset-bucket", * location: "US", * }); * const static = new gcp.compute.BackendBucket("static", { * name: "static-asset-backend-bucket", * bucketName: staticBucket.name, * enableCdn: true, * }); * const urlmap = new gcp.compute.URLMap("urlmap", { * 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", * }], * }); * ``` * ### Url Map Traffic Director Route * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const _default = new gcp.compute.HealthCheck("default", { * name: "health-check", * httpHealthCheck: { * port: 80, * }, * }); * const home = new gcp.compute.BackendService("home", { * name: "home", * portName: "http", * protocol: "HTTP", * timeoutSec: 10, * healthChecks: _default.id, * loadBalancingScheme: "INTERNAL_SELF_MANAGED", * }); * const urlmap = new gcp.compute.URLMap("urlmap", { * name: "urlmap", * description: "a description", * defaultService: home.id, * hostRules: [{ * hosts: ["mysite.com"], * pathMatcher: "allpaths", * }], * pathMatchers: [{ * name: "allpaths", * defaultService: home.id, * routeRules: [{ * priority: 1, * headerAction: { * requestHeadersToRemoves: ["RemoveMe2"], * requestHeadersToAdds: [{ * headerName: "AddSomethingElse", * headerValue: "MyOtherValue", * replace: true, * }], * responseHeadersToRemoves: ["RemoveMe3"], * responseHeadersToAdds: [{ * headerName: "AddMe", * headerValue: "MyValue", * replace: false, * }], * }, * matchRules: [{ * fullPathMatch: "a full path", * headerMatches: [{ * headerName: "someheader", * exactMatch: "match this exactly", * invertMatch: true, * }], * ignoreCase: true, * metadataFilters: [{ * filterMatchCriteria: "MATCH_ANY", * filterLabels: [{ * name: "PLANET", * value: "MARS", * }], * }], * queryParameterMatches: [{ * name: "a query parameter", * presentMatch: true, * }], * }], * urlRedirect: { * hostRedirect: "A host", * httpsRedirect: false, * pathRedirect: "some/path", * redirectResponseCode: "TEMPORARY_REDIRECT", * stripQuery: true, * }, * }], * }], * tests: [{ * service: home.id, * host: "hi.com", * path: "/home", * }], * }); * ``` * ### Url Map Traffic Director Route Partial * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const _default = new gcp.compute.HealthCheck("default", { * name: "health-check", * httpHealthCheck: { * port: 80, * }, * }); * const home = new gcp.compute.BackendService("home", { * name: "home", * portName: "http", * protocol: "HTTP", * timeoutSec: 10, * healthChecks: _default.id, * loadBalancingScheme: "INTERNAL_SELF_MANAGED", * }); * const urlmap = new gcp.compute.URLMap("urlmap", { * name: "urlmap", * description: "a description", * defaultService: home.id, * hostRules: [{ * hosts: ["mysite.com"], * pathMatcher: "allpaths", * }], * pathMatchers: [{ * name: "allpaths", * defaultService: home.id, * routeRules: [{ * priority: 1, * matchRules: [{ * prefixMatch: "/someprefix", * headerMatches: [{ * headerName: "someheader", * exactMatch: "match this exactly", * invertMatch: true, * }], * }], * urlRedirect: { * pathRedirect: "some/path", * redirectResponseCode: "TEMPORARY_REDIRECT", * }, * }], * }], * tests: [{ * service: home.id, * host: "hi.com", * path: "/home", * }], * }); * ``` * ### Url Map Traffic Director Path * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const _default = new gcp.compute.HealthCheck("default", { * name: "health-check", * httpHealthCheck: { * port: 80, * }, * }); * const home = new gcp.compute.BackendService("home", { * name: "home", * portName: "http", * protocol: "HTTP", * timeoutSec: 10, * healthChecks: _default.id, * loadBalancingScheme: "INTERNAL_SELF_MANAGED", * }); * const urlmap = new gcp.compute.URLMap("urlmap", { * 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: 750000000, * }, * 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", * }], * }); * ``` * ### Url Map Traffic Director Path Partial * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const _default = new gcp.compute.HealthCheck("default", { * name: "health-check", * httpHealthCheck: { * port: 80, * }, * }); * const home = new gcp.compute.BackendService("home", { * name: "home", * portName: "http", * protocol: "HTTP", * timeoutSec: 10, * healthChecks: _default.id, * loadBalancingScheme: "INTERNAL_SELF_MANAGED", * }); * const urlmap = new gcp.compute.URLMap("urlmap", { * 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, * }, * 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, * }], * }, * }], * maxStreamDuration: { * nanos: 500000, * seconds: "9", * }, * }, * }], * }], * tests: [{ * service: home.id, * host: "hi.com", * path: "/home", * }], * }); * ``` * ### Url Map Header Based Routing * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const defaultHttpHealthCheck = new gcp.compute.HttpHealthCheck("default", { * name: "health-check", * requestPath: "/", * checkIntervalSec: 1, * timeoutSec: 1, * }); * const _default = new gcp.compute.BackendService("default", { * name: "default", * portName: "http", * protocol: "HTTP", * timeoutSec: 10, * healthChecks: defaultHttpHealthCheck.id, * }); * const service_a = new gcp.compute.BackendService("service-a", { * name: "service-a", * portName: "http", * protocol: "HTTP", * timeoutSec: 10, * healthChecks: defaultHttpHealthCheck.id, * }); * const service_b = new gcp.compute.BackendService("service-b", { * name: "service-b", * portName: "http", * protocol: "HTTP", * timeoutSec: 10, * healthChecks: defaultHttpHealthCheck.id, * }); * const urlmap = new gcp.compute.URLMap("urlmap", { * 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", * }], * }], * }, * ], * }], * }); * ``` * ### Url Map Parameter Based Routing * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const defaultHttpHealthCheck = new gcp.compute.HttpHealthCheck("default", { * name: "health-check", * requestPath: "/", * checkIntervalSec: 1, * timeoutSec: 1, * }); * const _default = new gcp.compute.BackendService("default", { * name: "default", * portName: "http", * protocol: "HTTP", * timeoutSec: 10, * healthChecks: defaultHttpHealthCheck.id, * }); * const service_a = new gcp.compute.BackendService("service-a", { * name: "service-a", * portName: "http", * protocol: "HTTP", * timeoutSec: 10, * healthChecks: defaultHttpHealthCheck.id, * }); * const service_b = new gcp.compute.BackendService("service-b", { * name: "service-b", * portName: "http", * protocol: "HTTP", * timeoutSec: 10, * healthChecks: defaultHttpHealthCheck.id, * }); * const urlmap = new gcp.compute.URLMap("urlmap", { * 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", * }], * }], * }, * ], * }], * }); * ``` * ### Url Map Path Template Match * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const _default = new gcp.compute.HttpHealthCheck("default", { * name: "health-check", * requestPath: "/", * checkIntervalSec: 1, * timeoutSec: 1, * }); * const cart_backend = new gcp.compute.BackendService("cart-backend", { * name: "cart-service", * portName: "http", * protocol: "HTTP", * timeoutSec: 10, * loadBalancingScheme: "EXTERNAL_MANAGED", * healthChecks: _default.id, * }); * const user_backend = new gcp.compute.BackendService("user-backend", { * name: "user-service", * portName: "http", * protocol: "HTTP", * timeoutSec: 10, * loadBalancingScheme: "EXTERNAL_MANAGED", * healthChecks: _default.id, * }); * const staticBucket = new gcp.storage.Bucket("static", { * name: "static-asset-bucket", * location: "US", * }); * const static = new gcp.compute.BackendBucket("static", { * name: "static-asset-backend-bucket", * bucketName: staticBucket.name, * enableCdn: true, * }); * const urlmap = new gcp.compute.URLMap("urlmap", { * 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, * }, * ], * }], * }); * ``` * ### Url Map Custom Error Response Policy * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const _default = new gcp.compute.HttpHealthCheck("default", { * name: "health-check", * requestPath: "/", * checkIntervalSec: 1, * timeoutSec: 1, * }); * const example = new gcp.compute.BackendService("example", { * name: "login", * portName: "http", * protocol: "HTTP", * timeoutSec: 10, * loadBalancingScheme: "EXTERNAL_MANAGED", * healthChecks: _default.id, * }); * const errorBucket = new gcp.storage.Bucket("error", { * name: "static-asset-bucket", * location: "US", * }); * const error = new gcp.compute.BackendBucket("error", { * name: "error-backend-bucket", * bucketName: errorBucket.name, * enableCdn: true, * }); * const urlmap = new gcp.compute.URLMap("urlmap", { * name: "urlmap", * description: "a description", * defaultService: example.id, * defaultCustomErrorResponsePolicy: { * errorResponseRules: [{ * matchResponseCodes: ["5xx"], * path: "/internal_error.html", * overrideResponseCode: 502, * }], * errorService: error.id, * }, * hostRules: [{ * hosts: ["mysite.com"], * pathMatcher: "mysite", * }], * pathMatchers: [{ * name: "mysite", * defaultService: example.id, * defaultCustomErrorResponsePolicy: { * errorResponseRules: [ * { * matchResponseCodes: [ * "4xx", * "5xx", * ], * path: "/login_error.html", * overrideResponseCode: 404, * }, * { * matchResponseCodes: ["503"], * path: "/bad_gateway.html", * overrideResponseCode: 502, * }, * ], * errorService: error.id, * }, * pathRules: [{ * paths: ["/private/*"], * service: example.id, * customErrorResponsePolicy: { * errorResponseRules: [{ * matchResponseCodes: ["4xx"], * path: "/login.html", * overrideResponseCode: 401, * }], * errorService: error.id, * }, * }], * }], * }); * ``` * * ## 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: * * ```sh * $ pulumi import gcp:compute/uRLMap:URLMap default projects/{{project}}/global/urlMaps/{{name}} * ``` * * ```sh * $ pulumi import gcp:compute/uRLMap:URLMap default {{project}}/{{name}} * ``` * * ```sh * $ pulumi import gcp:compute/uRLMap:URLMap default {{name}} * ``` */ class URLMap extends pulumi.CustomResource { /** * Get an existing URLMap resource's state with the given name, ID, and optional extra * properties used to qualify the lookup. * * @param name The _unique_ name of the resulting resource. * @param id The _unique_ provider ID of the resource to lookup. * @param state Any extra arguments used during the lookup. * @param opts Optional settings to control the behavior of the CustomResource. */ static get(name, id, state, opts) { return new URLMap(name, state, Object.assign(Object.assign({}, opts), { id: id })); } /** * Returns true if the given object is an instance of URLMap. This is designed to work even * when multiple copies of the Pulumi SDK have been loaded into the same process. */ static isInstance(obj) { if (obj === undefined || obj === null) { return false; } return obj['__pulumiType'] === URLMap.__pulumiType; } constructor(name, argsOrState, opts) { let resourceInputs = {}; opts = opts || {}; if (opts.id) { const state = argsOrState; resourceInputs["creationTimestamp"] = state ? state.creationTimestamp : undefined; resourceInputs["defaultCustomErrorResponsePolicy"] = state ? state.defaultCustomErrorResponsePolicy : undefined; resourceInputs["defaultRouteAction"] = state ? state.defaultRouteAction : undefined; resourceInputs["defaultService"] = state ? state.defaultService : undefined; resourceInputs["defaultUrlRedirect"] = state ? state.defaultUrlRedirect : undefined; resourceInputs["description"] = state ? state.description : undefined; resourceInputs["fingerprint"] = state ? state.fingerprint : undefined; resourceInputs["headerAction"] = state ? state.headerAction : undefined; resourceInputs["hostRules"] = state ? state.hostRules : undefined; resourceInputs["mapId"] = state ? state.mapId : undefined; resourceInputs["name"] = state ? state.name : undefined; resourceInputs["pathMatchers"] = state ? state.pathMatchers : undefined; resourceInputs["project"] = state ? state.project : undefined; resourceInputs["selfLink"] = state ? state.selfLink : undefined; resourceInputs["tests"] = state ? state.tests : undefined; } else { const args = argsOrState; resourceInputs["defaultCustomErrorResponsePolicy"] = args ? args.defaultCustomErrorResponsePolicy : undefined; resourceInputs["defaultRouteAction"] = args ? args.defaultRouteAction : undefined; resourceInputs["defaultService"] = args ? args.defaultService : undefined; resourceInputs["defaultUrlRedirect"] = args ? args.defaultUrlRedirect : undefined; resourceInputs["description"] = args ? args.description : undefined; resourceInputs["headerAction"] = args ? args.headerAction : undefined; resourceInputs["hostRules"] = args ? args.hostRules : undefined; resourceInputs["name"] = args ? args.name : undefined; resourceInputs["pathMatchers"] = args ? args.pathMatchers : undefined; resourceInputs["project"] = args ? args.project : undefined; resourceInputs["tests"] = args ? args.tests : undefined; resourceInputs["creationTimestamp"] = undefined /*out*/; resourceInputs["fingerprint"] = undefined /*out*/; resourceInputs["mapId"] = undefined /*out*/; resourceInputs["selfLink"] = undefined /*out*/; } opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts); super(URLMap.__pulumiType, name, resourceInputs, opts); } } exports.URLMap = URLMap; /** @internal */ URLMap.__pulumiType = 'gcp:compute/uRLMap:URLMap'; //# sourceMappingURL=urlmap.js.map