pulumi_wasm_providers_gcp_mini::compute

Module backend_service

source
Expand description

A Backend Service defines a group of virtual machines that will serve traffic for load balancing. This resource is a global backend service, appropriate for external load balancing or self-managed internal load balancing. For managed internal load balancing, use a regional backend service instead.

Currently self-managed internal load balancing is only available in beta.

To get more information about BackendService, see:

Warning: All arguments including the following potentially sensitive values will be stored in the raw state as plain text: iap.oauth2_client_secret, iap.oauth2_client_secret_sha256, security_settings.aws_v4_authentication.access_key.

§Example Usage

§Backend Service Basic

use pulumi_wasm_rust::Output;
use pulumi_wasm_rust::{add_export, pulumi_main};
#[pulumi_main]
fn test_main() -> Result<(), Error> {
    let default = backend_service::create(
        "default",
        BackendServiceArgs::builder()
            .health_checks("${defaultHttpHealthCheck.id}")
            .name("backend-service")
            .build_struct(),
    );
    let defaultHttpHealthCheck = http_health_check::create(
        "defaultHttpHealthCheck",
        HttpHealthCheckArgs::builder()
            .check_interval_sec(1)
            .name("health-check")
            .request_path("/")
            .timeout_sec(1)
            .build_struct(),
    );
}

§Backend Service External Iap

use pulumi_wasm_rust::Output;
use pulumi_wasm_rust::{add_export, pulumi_main};
#[pulumi_main]
fn test_main() -> Result<(), Error> {
    let default = backend_service::create(
        "default",
        BackendServiceArgs::builder()
            .iap(
                BackendServiceIap::builder()
                    .enabled(true)
                    .oauth2ClientId("abc")
                    .oauth2ClientSecret("xyz")
                    .build_struct(),
            )
            .load_balancing_scheme("EXTERNAL")
            .name("tf-test-backend-service-external")
            .protocol("HTTP")
            .build_struct(),
    );
}

§Backend Service Cache Simple

use pulumi_wasm_rust::Output;
use pulumi_wasm_rust::{add_export, pulumi_main};
#[pulumi_main]
fn test_main() -> Result<(), Error> {
    let default = backend_service::create(
        "default",
        BackendServiceArgs::builder()
            .cdn_policy(
                BackendServiceCdnPolicy::builder()
                    .signedUrlCacheMaxAgeSec(7200)
                    .build_struct(),
            )
            .enable_cdn(true)
            .health_checks("${defaultHttpHealthCheck.id}")
            .name("backend-service")
            .build_struct(),
    );
    let defaultHttpHealthCheck = http_health_check::create(
        "defaultHttpHealthCheck",
        HttpHealthCheckArgs::builder()
            .check_interval_sec(1)
            .name("health-check")
            .request_path("/")
            .timeout_sec(1)
            .build_struct(),
    );
}

§Backend Service Cache Include Http Headers

use pulumi_wasm_rust::Output;
use pulumi_wasm_rust::{add_export, pulumi_main};
#[pulumi_main]
fn test_main() -> Result<(), Error> {
    let default = backend_service::create(
        "default",
        BackendServiceArgs::builder()
            .cdn_policy(
                BackendServiceCdnPolicy::builder()
                    .cacheKeyPolicy(
                        BackendServiceCdnPolicyCacheKeyPolicy::builder()
                            .includeHost(true)
                            .includeHttpHeaders(vec!["X-My-Header-Field",])
                            .includeProtocol(true)
                            .includeQueryString(true)
                            .build_struct(),
                    )
                    .cacheMode("USE_ORIGIN_HEADERS")
                    .build_struct(),
            )
            .enable_cdn(true)
            .name("backend-service")
            .build_struct(),
    );
}

§Backend Service Cache Include Named Cookies

use pulumi_wasm_rust::Output;
use pulumi_wasm_rust::{add_export, pulumi_main};
#[pulumi_main]
fn test_main() -> Result<(), Error> {
    let default = backend_service::create(
        "default",
        BackendServiceArgs::builder()
            .cdn_policy(
                BackendServiceCdnPolicy::builder()
                    .cacheKeyPolicy(
                        BackendServiceCdnPolicyCacheKeyPolicy::builder()
                            .includeHost(true)
                            .includeNamedCookies(
                                vec!["__next_preview_data", "__prerender_bypass",],
                            )
                            .includeProtocol(true)
                            .includeQueryString(true)
                            .build_struct(),
                    )
                    .cacheMode("CACHE_ALL_STATIC")
                    .clientTtl(7200)
                    .defaultTtl(3600)
                    .maxTtl(10800)
                    .build_struct(),
            )
            .enable_cdn(true)
            .name("backend-service")
            .build_struct(),
    );
}

§Backend Service Cache

use pulumi_wasm_rust::Output;
use pulumi_wasm_rust::{add_export, pulumi_main};
#[pulumi_main]
fn test_main() -> Result<(), Error> {
    let default = backend_service::create(
        "default",
        BackendServiceArgs::builder()
            .cdn_policy(
                BackendServiceCdnPolicy::builder()
                    .cacheMode("CACHE_ALL_STATIC")
                    .clientTtl(7200)
                    .defaultTtl(3600)
                    .maxTtl(10800)
                    .negativeCaching(true)
                    .signedUrlCacheMaxAgeSec(7200)
                    .build_struct(),
            )
            .enable_cdn(true)
            .health_checks("${defaultHttpHealthCheck.id}")
            .name("backend-service")
            .build_struct(),
    );
    let defaultHttpHealthCheck = http_health_check::create(
        "defaultHttpHealthCheck",
        HttpHealthCheckArgs::builder()
            .check_interval_sec(1)
            .name("health-check")
            .request_path("/")
            .timeout_sec(1)
            .build_struct(),
    );
}

§Backend Service Cache Bypass Cache On Request Headers

use pulumi_wasm_rust::Output;
use pulumi_wasm_rust::{add_export, pulumi_main};
#[pulumi_main]
fn test_main() -> Result<(), Error> {
    let default = backend_service::create(
        "default",
        BackendServiceArgs::builder()
            .cdn_policy(
                BackendServiceCdnPolicy::builder()
                    .bypassCacheOnRequestHeaders(
                        vec![
                            BackendServiceCdnPolicyBypassCacheOnRequestHeader::builder()
                            .headerName("Authorization").build_struct(),
                            BackendServiceCdnPolicyBypassCacheOnRequestHeader::builder()
                            .headerName("Proxy-Authorization").build_struct(),
                        ],
                    )
                    .cacheMode("CACHE_ALL_STATIC")
                    .clientTtl(7200)
                    .defaultTtl(3600)
                    .maxTtl(10800)
                    .negativeCaching(true)
                    .signedUrlCacheMaxAgeSec(7200)
                    .build_struct(),
            )
            .enable_cdn(true)
            .health_checks("${defaultHttpHealthCheck.id}")
            .name("backend-service")
            .build_struct(),
    );
    let defaultHttpHealthCheck = http_health_check::create(
        "defaultHttpHealthCheck",
        HttpHealthCheckArgs::builder()
            .check_interval_sec(1)
            .name("health-check")
            .request_path("/")
            .timeout_sec(1)
            .build_struct(),
    );
}

§Backend Service Traffic Director Round Robin

use pulumi_wasm_rust::Output;
use pulumi_wasm_rust::{add_export, pulumi_main};
#[pulumi_main]
fn test_main() -> Result<(), Error> {
    let default = backend_service::create(
        "default",
        BackendServiceArgs::builder()
            .health_checks("${healthCheck.id}")
            .load_balancing_scheme("INTERNAL_SELF_MANAGED")
            .locality_lb_policy("ROUND_ROBIN")
            .name("backend-service")
            .build_struct(),
    );
    let healthCheck = health_check::create(
        "healthCheck",
        HealthCheckArgs::builder()
            .http_health_check(
                HealthCheckHttpHealthCheck::builder().port(80).build_struct(),
            )
            .name("health-check")
            .build_struct(),
    );
}

§Backend Service Traffic Director Ring Hash

use pulumi_wasm_rust::Output;
use pulumi_wasm_rust::{add_export, pulumi_main};
#[pulumi_main]
fn test_main() -> Result<(), Error> {
    let default = backend_service::create(
        "default",
        BackendServiceArgs::builder()
            .circuit_breakers(
                BackendServiceCircuitBreakers::builder()
                    .maxConnections(10)
                    .build_struct(),
            )
            .consistent_hash(
                BackendServiceConsistentHash::builder()
                    .httpCookie(
                        BackendServiceConsistentHashHttpCookie::builder()
                            .name("mycookie")
                            .ttl(
                                BackendServiceConsistentHashHttpCookieTtl::builder()
                                    .nanos(1111)
                                    .seconds(11)
                                    .build_struct(),
                            )
                            .build_struct(),
                    )
                    .build_struct(),
            )
            .health_checks("${healthCheck.id}")
            .load_balancing_scheme("INTERNAL_SELF_MANAGED")
            .locality_lb_policy("RING_HASH")
            .name("backend-service")
            .outlier_detection(
                BackendServiceOutlierDetection::builder()
                    .consecutiveErrors(2)
                    .consecutiveGatewayFailure(5)
                    .enforcingConsecutiveErrors(100)
                    .enforcingConsecutiveGatewayFailure(0)
                    .enforcingSuccessRate(100)
                    .maxEjectionPercent(10)
                    .successRateMinimumHosts(5)
                    .successRateRequestVolume(100)
                    .successRateStdevFactor(1900)
                    .build_struct(),
            )
            .session_affinity("HTTP_COOKIE")
            .build_struct(),
    );
    let healthCheck = health_check::create(
        "healthCheck",
        HealthCheckArgs::builder()
            .http_health_check(
                HealthCheckHttpHealthCheck::builder().port(80).build_struct(),
            )
            .name("health-check")
            .build_struct(),
    );
}

§Backend Service Stateful Session Affinity

use pulumi_wasm_rust::Output;
use pulumi_wasm_rust::{add_export, pulumi_main};
#[pulumi_main]
fn test_main() -> Result<(), Error> {
    let default = backend_service::create(
        "default",
        BackendServiceArgs::builder()
            .health_checks("${healthCheck.id}")
            .load_balancing_scheme("EXTERNAL_MANAGED")
            .locality_lb_policy("RING_HASH")
            .name("backend-service")
            .session_affinity("STRONG_COOKIE_AFFINITY")
            .strong_session_affinity_cookie(
                BackendServiceStrongSessionAffinityCookie::builder()
                    .name("mycookie")
                    .ttl(
                        BackendServiceStrongSessionAffinityCookieTtl::builder()
                            .nanos(1111)
                            .seconds(11)
                            .build_struct(),
                    )
                    .build_struct(),
            )
            .build_struct(),
    );
    let healthCheck = health_check::create(
        "healthCheck",
        HealthCheckArgs::builder()
            .http_health_check(
                HealthCheckHttpHealthCheck::builder().port(80).build_struct(),
            )
            .name("health-check")
            .build_struct(),
    );
}

§Backend Service Network Endpoint

resources:
  externalProxy:
    type: gcp:compute:GlobalNetworkEndpointGroup
    name: external_proxy
    properties:
      name: network-endpoint
      networkEndpointType: INTERNET_FQDN_PORT
      defaultPort: '443'
  proxy:
    type: gcp:compute:GlobalNetworkEndpoint
    properties:
      globalNetworkEndpointGroup: ${externalProxy.id}
      fqdn: test.example.com
      port: ${externalProxy.defaultPort}
  default:
    type: gcp:compute:BackendService
    properties:
      name: backend-service
      enableCdn: true
      timeoutSec: 10
      connectionDrainingTimeoutSec: 10
      customRequestHeaders:
        - 'host: ${proxy.fqdn}'
      customResponseHeaders:
        - 'X-Cache-Hit: {cdn_cache_status}'
      backends:
        - group: ${externalProxy.id}

§Backend Service External Managed

use pulumi_wasm_rust::Output;
use pulumi_wasm_rust::{add_export, pulumi_main};
#[pulumi_main]
fn test_main() -> Result<(), Error> {
    let default = backend_service::create(
        "default",
        BackendServiceArgs::builder()
            .health_checks("${defaultHealthCheck.id}")
            .load_balancing_scheme("EXTERNAL_MANAGED")
            .name("backend-service")
            .build_struct(),
    );
    let defaultHealthCheck = health_check::create(
        "defaultHealthCheck",
        HealthCheckArgs::builder()
            .http_health_check(
                HealthCheckHttpHealthCheck::builder().port(80).build_struct(),
            )
            .name("health-check")
            .build_struct(),
    );
}

§Backend Service Ip Address Selection Policy

use pulumi_wasm_rust::Output;
use pulumi_wasm_rust::{add_export, pulumi_main};
#[pulumi_main]
fn test_main() -> Result<(), Error> {
    let default = backend_service::create(
        "default",
        BackendServiceArgs::builder()
            .ip_address_selection_policy("IPV6_ONLY")
            .load_balancing_scheme("EXTERNAL_MANAGED")
            .name("backend-service")
            .build_struct(),
    );
}

§Import

BackendService can be imported using any of these accepted formats:

  • projects/{{project}}/global/backendServices/{{name}}

  • {{project}}/{{name}}

  • {{name}}

When using the pulumi import command, BackendService can be imported using one of the formats above. For example:

$ pulumi import gcp:compute/backendService:BackendService default projects/{{project}}/global/backendServices/{{name}}
$ pulumi import gcp:compute/backendService:BackendService default {{project}}/{{name}}
$ pulumi import gcp:compute/backendService:BackendService default {{name}}

Structs§

Functions§

  • Registers a new resource with the given unique name and arguments