Tsu*_*omu 4 terraform terraform-provider-gcp
为了创建 HTTP 负载均衡器,我创建了以下.tf文件:
resource "google_compute_instance_group_manager" "nginx" {
name = "nginx-igm"
base_instance_name = "nginx"
zone = var.zone
version {
instance_template = google_compute_instance_template.nginx.id
}
target_size = 2
auto_healing_policies {
health_check = google_compute_health_check.autohealing.id
initial_delay_sec = 300
}
}
resource "google_compute_health_check" "autohealing" {
name = "autohealing"
description = "Autohealing health check via http"
timeout_sec = 5
check_interval_sec = 5
healthy_threshold = 2
unhealthy_threshold = 2
http_health_check {
response = "<!DOCTYPE html>"
}
}
resource "google_compute_instance_template" "nginx" {
name = "nginx-template"
description = "This template is used to create nginx instances."
tags = ["http-server"]
instance_description = "Nginx instance"
machine_type = "e2-small"
can_ip_forward = false
scheduling {
automatic_restart = true
on_host_maintenance = "MIGRATE"
}
disk {
source_image = "ubuntu-2004-nginx"
auto_delete = true
boot = true
}
network_interface {
network = "default"
}
}
resource "google_compute_backend_service" "mig-backend" {
name = "mig-backend"
port_name = "http"
protocol = "HTTP"
timeout_sec = 3000
backend {
group = google_compute_instance_group_manager.nginx.self_link
}
health_checks = [google_compute_health_check.http-health-check.self_link]
log_config {
enable = true
}
}
resource "google_compute_url_map" "mig-url-map" {
name = "mig-url-map"
default_service = google_compute_backend_service.mig-backend.self_link
}
resource "google_compute_target_http_proxy" "mig-target-http-proxy" {
name = "mig-target-http-proxy"
url_map = google_compute_url_map.mig-url-map.self_link
}
resource "google_compute_global_forwarding_rule" "mig-global-forwarding-rule-http" {
name = "mig-global-forwarding-rule-http"
target = google_compute_target_http_proxy.mig-target-http-proxy.self_link
port_range = "80"
ip_address = google_compute_global_address.mig-lb-address.address
}
resource "google_compute_global_address" "mig-lb-address" {
name = "mig-lb-address"
}
Run Code Online (Sandbox Code Playgroud)
这个配置文件在这部分有一个明显的缺陷:
resource "google_compute_backend_service" "mig-backend" {
name = "mig-backend"
port_name = "http"
protocol = "HTTP"
timeout_sec = 3000
backend {
group = google_compute_instance_group_manager.nginx.self_link
}
health_checks = [google_compute_health_check.http-health-check.self_link]
log_config {
enable = true
}
}
Run Code Online (Sandbox Code Playgroud)
官方文档说后端服务的属性应该是“实例组或网络端点组资源的完全限定 URL”,但在我的例子中,我指定了实例组管理器backend.group的 URL 。实际上,我从 GCP 收到了此错误消息:
Error: Error creating BackendService: googleapi: Error 400: Invalid value for field 'resource.backends[0].group': 'https://www.googleapis.com/compute/v1/projects/oiax-lb-test/zones/asia-northeast2-a/instanceGroupManagers/nginx-igm'. Unexpected resource collection 'instanceGroupManagers'., invalid
Run Code Online (Sandbox Code Playgroud)
我应该如何更正我的配置文件以连接实例组和后端服务?
请参阅“instance_group”属性 - 管理器创建的实例组的完整 URL。
backend {
group = google_compute_instance_group_manager.nginx.instance_group
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1394 次 |
| 最近记录: |