pulumi_wasm_providers_gcp_mini::compute

Module global_forwarding_rule

source
Expand description

Represents a GlobalForwardingRule resource. Global forwarding rules are used to forward traffic to the correct load balancer for HTTP load balancing. Global forwarding rules can only be used for HTTP load balancing.

For more information, see https://cloud.google.com/compute/docs/load-balancing/http/

§Example Usage

§Global Forwarding Rule Http

use pulumi_wasm_rust::Output;
use pulumi_wasm_rust::{add_export, pulumi_main};
#[pulumi_main]
fn test_main() -> Result<(), Error> {
    let default = global_forwarding_rule::create(
        "default",
        GlobalForwardingRuleArgs::builder()
            .name("global-rule")
            .port_range("80")
            .target("${defaultTargetHttpProxy.id}")
            .build_struct(),
    );
    let defaultBackendService = backend_service::create(
        "defaultBackendService",
        BackendServiceArgs::builder()
            .health_checks("${defaultHttpHealthCheck.id}")
            .name("backend")
            .port_name("http")
            .protocol("HTTP")
            .timeout_sec(10)
            .build_struct(),
    );
    let defaultHttpHealthCheck = http_health_check::create(
        "defaultHttpHealthCheck",
        HttpHealthCheckArgs::builder()
            .check_interval_sec(1)
            .name("check-backend")
            .request_path("/")
            .timeout_sec(1)
            .build_struct(),
    );
    let defaultTargetHttpProxy = target_http_proxy::create(
        "defaultTargetHttpProxy",
        TargetHttpProxyArgs::builder()
            .description("a description")
            .name("target-proxy")
            .url_map("${defaultURLMap.id}")
            .build_struct(),
    );
    let defaultURLMap = url_map::create(
        "defaultURLMap",
        UrlMapArgs::builder()
            .default_service("${defaultBackendService.id}")
            .description("a description")
            .host_rules(
                vec![
                    UrlMapHostRule::builder().hosts(vec!["mysite.com",])
                    .pathMatcher("allpaths").build_struct(),
                ],
            )
            .name("url-map-target-proxy")
            .path_matchers(
                vec![
                    UrlMapPathMatcher::builder()
                    .defaultService("${defaultBackendService.id}").name("allpaths")
                    .pathRules(vec![UrlMapPathMatcherPathRule::builder()
                    .paths(vec!["/*",]).service("${defaultBackendService.id}")
                    .build_struct(),]).build_struct(),
                ],
            )
            .build_struct(),
    );
}

§Global Forwarding Rule Internal

resources:
  default:
    type: gcp:compute:GlobalForwardingRule
    properties:
      name: global-rule
      target: ${defaultTargetHttpProxy.id}
      portRange: '80'
      loadBalancingScheme: INTERNAL_SELF_MANAGED
      ipAddress: 0.0.0.0
      metadataFilters:
        - filterMatchCriteria: MATCH_ANY
          filterLabels:
            - name: PLANET
              value: MARS
  defaultTargetHttpProxy:
    type: gcp:compute:TargetHttpProxy
    name: default
    properties:
      name: target-proxy
      description: a description
      urlMap: ${defaultURLMap.id}
  defaultURLMap:
    type: gcp:compute:URLMap
    name: default
    properties:
      name: url-map-target-proxy
      description: a description
      defaultService: ${defaultBackendService.id}
      hostRules:
        - hosts:
            - mysite.com
          pathMatcher: allpaths
      pathMatchers:
        - name: allpaths
          defaultService: ${defaultBackendService.id}
          pathRules:
            - paths:
                - /*
              service: ${defaultBackendService.id}
  defaultBackendService:
    type: gcp:compute:BackendService
    name: default
    properties:
      name: backend
      portName: http
      protocol: HTTP
      timeoutSec: 10
      loadBalancingScheme: INTERNAL_SELF_MANAGED
      backends:
        - group: ${igm.instanceGroup}
          balancingMode: RATE
          capacityScaler: 0.4
          maxRatePerInstance: 50
      healthChecks: ${defaultHealthCheck.id}
  igm:
    type: gcp:compute:InstanceGroupManager
    properties:
      name: igm-internal
      versions:
        - instanceTemplate: ${instanceTemplate.id}
          name: primary
      baseInstanceName: internal-glb
      zone: us-central1-f
      targetSize: 1
  instanceTemplate:
    type: gcp:compute:InstanceTemplate
    name: instance_template
    properties:
      name: template-backend
      machineType: e2-medium
      networkInterfaces:
        - network: default
      disks:
        - sourceImage: ${debianImage.selfLink}
          autoDelete: true
          boot: true
  defaultHealthCheck:
    type: gcp:compute:HealthCheck
    name: default
    properties:
      name: check-backend
      checkIntervalSec: 1
      timeoutSec: 1
      tcpHealthCheck:
        port: '80'
variables:
  debianImage:
    fn::invoke:
      function: gcp:compute:getImage
      arguments:
        family: debian-11
        project: debian-cloud

§Global Forwarding Rule External Managed

use pulumi_wasm_rust::Output;
use pulumi_wasm_rust::{add_export, pulumi_main};
#[pulumi_main]
fn test_main() -> Result<(), Error> {
    let default = global_forwarding_rule::create(
        "default",
        GlobalForwardingRuleArgs::builder()
            .load_balancing_scheme("EXTERNAL_MANAGED")
            .name("global-rule")
            .network_tier("PREMIUM")
            .port_range("80")
            .target("${defaultTargetHttpProxy.id}")
            .build_struct(),
    );
    let defaultBackendService = backend_service::create(
        "defaultBackendService",
        BackendServiceArgs::builder()
            .load_balancing_scheme("EXTERNAL_MANAGED")
            .name("backend")
            .port_name("http")
            .protocol("HTTP")
            .timeout_sec(10)
            .build_struct(),
    );
    let defaultTargetHttpProxy = target_http_proxy::create(
        "defaultTargetHttpProxy",
        TargetHttpProxyArgs::builder()
            .description("a description")
            .name("target-proxy")
            .url_map("${defaultURLMap.id}")
            .build_struct(),
    );
    let defaultURLMap = url_map::create(
        "defaultURLMap",
        UrlMapArgs::builder()
            .default_service("${defaultBackendService.id}")
            .description("a description")
            .host_rules(
                vec![
                    UrlMapHostRule::builder().hosts(vec!["mysite.com",])
                    .pathMatcher("allpaths").build_struct(),
                ],
            )
            .name("url-map-target-proxy")
            .path_matchers(
                vec![
                    UrlMapPathMatcher::builder()
                    .defaultService("${defaultBackendService.id}").name("allpaths")
                    .pathRules(vec![UrlMapPathMatcherPathRule::builder()
                    .paths(vec!["/*",]).service("${defaultBackendService.id}")
                    .build_struct(),]).build_struct(),
                ],
            )
            .build_struct(),
    );
}

§Global Forwarding Rule Hybrid

configuration:
  # Roughly mirrors https://cloud.google.com/load-balancing/docs/https/setting-up-ext-https-hybrid
  subnetworkCidr:
    type: string
    default: 10.0.0.0/24
resources:
  default:
    type: gcp:compute:Network
    properties:
      name: my-network
  internal:
    type: gcp:compute:Network
    properties:
      name: my-internal-network
      autoCreateSubnetworks: false
  internalSubnetwork:
    type: gcp:compute:Subnetwork
    name: internal
    properties:
      name: my-subnetwork
      network: ${internal.id}
      ipCidrRange: ${subnetworkCidr}
      region: us-central1
      privateIpGoogleAccess: true
  # Zonal NEG with GCE_VM_IP_PORT
  defaultNetworkEndpointGroup:
    type: gcp:compute:NetworkEndpointGroup
    name: default
    properties:
      name: default-neg
      network: ${default.id}
      defaultPort: '90'
      zone: us-central1-a
      networkEndpointType: GCE_VM_IP_PORT
  # Zonal NEG with GCE_VM_IP
  internalNetworkEndpointGroup:
    type: gcp:compute:NetworkEndpointGroup
    name: internal
    properties:
      name: internal-neg
      network: ${internal.id}
      subnetwork: ${internalSubnetwork.id}
      zone: us-central1-a
      networkEndpointType: GCE_VM_IP
  # Hybrid connectivity NEG
  hybrid:
    type: gcp:compute:NetworkEndpointGroup
    properties:
      name: hybrid-neg
      network: ${default.id}
      defaultPort: '90'
      zone: us-central1-a
      networkEndpointType: NON_GCP_PRIVATE_IP_PORT
  hybrid-endpoint:
    type: gcp:compute:NetworkEndpoint
    properties:
      networkEndpointGroup: ${hybrid.name}
      port: ${hybrid.defaultPort}
      ipAddress: 127.0.0.1
  # Backend service for Zonal NEG
  defaultBackendService:
    type: gcp:compute:BackendService
    name: default
    properties:
      name: backend-default
      portName: http
      protocol: HTTP
      timeoutSec: 10
      backends:
        - group: ${defaultNetworkEndpointGroup.id}
          balancingMode: RATE
          maxRatePerEndpoint: 10
      healthChecks: ${defaultHealthCheck.id}
  # Backgend service for Hybrid NEG
  hybridBackendService:
    type: gcp:compute:BackendService
    name: hybrid
    properties:
      name: backend-hybrid
      portName: http
      protocol: HTTP
      timeoutSec: 10
      backends:
        - group: ${hybrid.id}
          balancingMode: RATE
          maxRatePerEndpoint: 10
      healthChecks: ${defaultHealthCheck.id}
  defaultHealthCheck:
    type: gcp:compute:HealthCheck
    name: default
    properties:
      name: health-check
      timeoutSec: 1
      checkIntervalSec: 1
      tcpHealthCheck:
        port: '80'
  defaultURLMap:
    type: gcp:compute:URLMap
    name: default
    properties:
      name: url-map-target-proxy
      description: a description
      defaultService: ${defaultBackendService.id}
      hostRules:
        - hosts:
            - mysite.com
          pathMatcher: allpaths
      pathMatchers:
        - name: allpaths
          defaultService: ${defaultBackendService.id}
          pathRules:
            - paths:
                - /*
              service: ${defaultBackendService.id}
            - paths:
                - /hybrid
              service: ${hybridBackendService.id}
  defaultTargetHttpProxy:
    type: gcp:compute:TargetHttpProxy
    name: default
    properties:
      name: target-proxy
      description: a description
      urlMap: ${defaultURLMap.id}
  defaultGlobalForwardingRule:
    type: gcp:compute:GlobalForwardingRule
    name: default
    properties:
      name: global-rule
      target: ${defaultTargetHttpProxy.id}
      portRange: '80'

§Private Service Connect Google Apis

use pulumi_wasm_rust::Output;
use pulumi_wasm_rust::{add_export, pulumi_main};
#[pulumi_main]
fn test_main() -> Result<(), Error> {
    let default = global_address::create(
        "default",
        GlobalAddressArgs::builder()
            .address("100.100.100.106")
            .address_type("INTERNAL")
            .name("global-psconnect-ip")
            .network("${network.id}")
            .project("${network.project}")
            .purpose("PRIVATE_SERVICE_CONNECT")
            .build_struct(),
    );
    let defaultGlobalForwardingRule = global_forwarding_rule::create(
        "defaultGlobalForwardingRule",
        GlobalForwardingRuleArgs::builder()
            .ip_address("${default.id}")
            .load_balancing_scheme("")
            .name("globalrule")
            .network("${network.id}")
            .project("${network.project}")
            .service_directory_registrations(
                GlobalForwardingRuleServiceDirectoryRegistrations::builder()
                    .namespace("sd-namespace")
                    .serviceDirectoryRegion("europe-west3")
                    .build_struct(),
            )
            .target("all-apis")
            .build_struct(),
    );
    let network = network::create(
        "network",
        NetworkArgs::builder()
            .auto_create_subnetworks(false)
            .name("my-network")
            .project("my-project-name")
            .build_struct(),
    );
    let vpcSubnetwork = subnetwork::create(
        "vpcSubnetwork",
        SubnetworkArgs::builder()
            .ip_cidr_range("10.2.0.0/16")
            .name("my-subnetwork")
            .network("${network.id}")
            .private_ip_google_access(true)
            .project("${network.project}")
            .region("us-central1")
            .build_struct(),
    );
}

§Private Service Connect Google Apis No Automate Dns

use pulumi_wasm_rust::Output;
use pulumi_wasm_rust::{add_export, pulumi_main};
#[pulumi_main]
fn test_main() -> Result<(), Error> {
    let default = global_address::create(
        "default",
        GlobalAddressArgs::builder()
            .address("100.100.100.106")
            .address_type("INTERNAL")
            .name("global-psconnect-ip")
            .network("${network.id}")
            .project("${network.project}")
            .purpose("PRIVATE_SERVICE_CONNECT")
            .build_struct(),
    );
    let defaultGlobalForwardingRule = global_forwarding_rule::create(
        "defaultGlobalForwardingRule",
        GlobalForwardingRuleArgs::builder()
            .ip_address("${default.id}")
            .load_balancing_scheme("")
            .name("globalrule")
            .network("${network.id}")
            .no_automate_dns_zone(false)
            .project("${network.project}")
            .target("all-apis")
            .build_struct(),
    );
    let network = network::create(
        "network",
        NetworkArgs::builder()
            .auto_create_subnetworks(false)
            .name("my-network")
            .project("my-project-name")
            .build_struct(),
    );
    let vpcSubnetwork = subnetwork::create(
        "vpcSubnetwork",
        SubnetworkArgs::builder()
            .ip_cidr_range("10.2.0.0/16")
            .name("my-subnetwork")
            .network("${network.id}")
            .private_ip_google_access(true)
            .project("${network.project}")
            .region("us-central1")
            .build_struct(),
    );
}

§Import

GlobalForwardingRule can be imported using any of these accepted formats:

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

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

  • {{name}}

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

$ pulumi import gcp:compute/globalForwardingRule:GlobalForwardingRule default projects/{{project}}/global/forwardingRules/{{name}}
$ pulumi import gcp:compute/globalForwardingRule:GlobalForwardingRule default {{project}}/{{name}}
$ pulumi import gcp:compute/globalForwardingRule:GlobalForwardingRule default {{name}}

Structs§

Functions§

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