1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

3-shakeAdvent Calendar 2024

Day 18

Cloud Workstationsを独自ドメインで使いたい

Posted at

カスタムドメインを設定

Cloud Workstations のカスタム ドメインを設定する  |  Google Cloud

の構成をTerraformで構築します

Workstation ClusterのPrivate Endpointを有効にする

google_workstations_workstation_clusterのenable_private_endpointを有効にすることで、workstation clusterへのサービスアタッチメント用のURIが発行される(NEGのターゲット指定に使う)

resource "google_workstations_workstation_cluster" "default" {
...
  private_cluster_config {
    enable_private_endpoint = true
  }
  
  domain_config {
		domain = "workstations.example.com"
	}
...
}

外部アプリケーションロードバランサー作成

PSCをターゲットとするNEG作成

  • network_endpoint_type: PRIVATE_SERVICE_CONNECT
  • psc_target_service: private endpointを有効にしたWorkstation Clusterの サービス アタッチメントの URI を指定。サービスアタッチメントURIはWorkstation Clusterのコンソールから取得
resource "google_compute_region_network_endpoint_group" "default" {
  name                  = "workstations"
  network               = google_compute_network.default.id
  subnetwork            = google_compute_subnetwork.default.id
  network_endpoint_type = "PRIVATE_SERVICE_CONNECT"
  region                = local.location
  psc_target_service    = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}

UrlMapとBackend作成

バックエンド(NEG)の作成と受信リクエストをバックエンドに転送するためのUrlMap作成

resource "google_compute_region_url_map" "default" {
  name            = "workstations-elb-regional-url-map"
  region          = local.location
  default_service = google_compute_region_backend_service.default.id
}

resource "google_compute_region_backend_service" "default" {
  name                  = "workstations-elb-backend-service"
  region                = local.location
  protocol              = "HTTPS"
  load_balancing_scheme = "EXTERNAL_MANAGED"
  timeout_sec           = 10
  backend {
    group           = google_compute_region_network_endpoint_group.default.id
    balancing_mode  = "UTILIZATION"
    capacity_scaler = 1.0
  }
}

証明書とDNS Authorization作成

workstationsへのアクセスは https://<PORT>-<WORKSTATION_NAME>.<DOMAIN> の様な形式で、複数workstationsがある場合や、複数Portで公開する場合にはサブドメインが変わるのでワイルドカード証明書で取得する

resource "google_certificate_manager_dns_authorization" "default" {
  name        = "dns-auth"
  description = "The default dnss"
  domain      = "workstations.ureuzy.io"
  location    = local.location
}

resource "google_certificate_manager_certificate" "default" {
  name     = "workstations-cert"
  location = local.location
  managed {
    domains = [
      "*.${google_certificate_manager_dns_authorization.default.domain}"
    ]
    dns_authorizations = [
      google_certificate_manager_dns_authorization.default.id
    ]
  }
}

ターゲットHTTPSプロキシとフォワードルール作成

resource "google_compute_forwarding_rule" "default" {
  name                  = "workstations-elb-forwarding-rule"
  load_balancing_scheme = "EXTERNAL_MANAGED"
  port_range            = "443"
  region                = local.location
  depends_on            = [google_compute_subnetwork.proxy]
  ip_address            = google_compute_address.default.address
  target                = google_compute_region_target_https_proxy.default.id
  network               = google_compute_network.default.id
}

resource "google_compute_region_target_https_proxy" "default" {
  name                             = "workstations-elb-target-http-proxy"
  region                           = local.location
  url_map                          = google_compute_region_url_map.default.id
  certificate_manager_certificates = [google_certificate_manager_certificate.default.id]
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?