使用 Pulumi 在 GCP 上设置负载均衡器前端

Setting up load balancer frontend with on GCP with Pulumi

现在我正在学习如何使用 Pulumi 设置由 GCP 存储桶提供服务的网站,但是,我一直停留在公开 IP 地址并将其附加到 LB 的最后一步。除了 This load balancer has no frontend configured

之外一切看起来都不错

我认为 ForwardingRule 是我需要的,但 BucketBackend 除外(请参阅下面的代码和输出)。

对如何前进有什么建议吗?

####### WEBSITE ##########
web_bucket = gcp.storage.Bucket('web',
    project="myproj",
    cors=[gcp.storage.BucketCorArgs(
        max_age_seconds=3600,
        methods=[
            "GET",
        ],
        origins=["https://myproj.com", "https://sandbox.myproj.com"],
        response_headers=["*"],
    )],
    force_destroy=True,
    location="US",
    uniform_bucket_level_access=True,
    website=gcp.storage.BucketWebsiteArgs(
        main_page_suffix="index.html",
        not_found_page="404.html",
    ),
)
pulumi.export('web bucket', web_bucket.url)

ssl_certificate = gcp.compute.SSLCertificate("SSLCertificate",
    project="myproj",
    name_prefix="certificate-",
    private_key=(lambda path: open(path).read())("ssl/private.key"),
    certificate=(lambda path: open(path).read())("ssl/certificate.crt"))

http_health_check = gcp.compute.HttpHealthCheck("httphealthcheck",
    project="myproj",
    request_path="/",
    check_interval_sec=1,
    timeout_sec=1
)

# Backend Bucket Service
web_backend = gcp.compute.BackendBucket("web-backend",
    project="myproj",
    description="Serves website",
    bucket_name=web_bucket.name,
    enable_cdn=True
)

# LB Backend hostpath and rules
url_map = gcp.compute.URLMap("urlmap",
    project="myproj",
    description="URL mapping",
    default_service=web_backend.id,
    host_rules=[gcp.compute.URLMapHostRuleArgs(
        hosts=["myproj.io"],
        path_matcher="allpaths",
    )],
    path_matchers=[gcp.compute.URLMapPathMatcherArgs(
        name="allpaths",
        default_service=web_backend.id,
        path_rules=[gcp.compute.URLMapPathMatcherPathRuleArgs(
            paths=["/*"],
            service=web_backend.id,
        )],
    )]
)

# Route to backed (bucket backend)
target_https_proxy = gcp.compute.TargetHttpsProxy("targethttpsproxy",
    project="myproj",
    url_map=url_map.id,
    ssl_certificates=[ssl_certificate.id])

# Forwarding rule for External Network Load Balancing using Backend Services
web_forward = gcp.compute.ForwardingRule("webforward",
    project="myproj",
    region="us-central1",
    port_range="80",
    backend_service=web_backend.id # this doesn't work
)
Diagnostics:
  gcp:compute:ForwardingRule (default):
    error: 1 error occurred:
        * Error creating ForwardingRule: googleapi: Error 400: Invalid value for field 'resource.backendService': 'https://compute.googleapis.com/compute/beta/projects/myproj/global/backendBuckets/web-backend-576fa1b'. Unexpected resource collection 'backendBuckets'., invalid

我使用了错误的转发规则 class。因为LAMB设置区域转发错误

# Forwarding rule for External Network Load Balancing using Backend Services
web_forward = gcp.compute.GlobalForwardingRule("webforward",
    project="myproj",
    port_range="443",
    target=nbprod_target_https_proxy.self_link
)