在此处阅读文档:
https://www.terraform.io/docs/providers/google/r/compute_backend_service.html
我们可以定义后端服务:
resource "google_compute_backend_service" "kubernetes-nginx-prod" {
name = "kubernetes-nginx-prod"
health_checks = [google_compute_health_check.kubernetes-nginx-prod-healthcheck.self_link]
backend {
group = replace(google_container_node_pool.pool-1.instance_group_urls[0], "instanceGroupManagers", "instanceGroups")
# TODO missing port 31443
}
}
似乎我们无法通过Terraform设置来设置后端服务端口:
在没有此设置的情况下重新创建后端服务实际上会导致我们停机,并且必须手动编写端口。
答案 0 :(得分:2)
例如,我们需要引用实例组中提供的端口名。
resource "google_compute_backend_service" "test" {
name = "test-service"
port_name = "test-port"
protocol = "HTTP"
timeout_sec = 5
health_checks = []
backend {
group = "${google_compute_instance_group.test-ig.self_link}"
}
}
resource "google_compute_instance_group" "test-ig" {
name = "test-ig"
instances = []
named_port {
name = "test-port"
port = "${var.app_port}"
}
zone = "${var.zone}"
}