Terraform GCP:如何将MIG连接到后端服务?
为了创建HTTP负载平衡器,我创建了以下Terraform GCP:如何将MIG连接到后端服务?,terraform,terraform-provider-gcp,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 = go
.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"
}
表示后端服务的backend.group
属性应该是“实例组或网络端点组资源的完全限定URL”,但在我的示例中,我指定了实例组管理器的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
如何更正配置文件以连接实例组和后端服务?请参阅“实例组”属性—管理器创建的实例组的完整URL
backend {
group = google_compute_instance_group_manager.nginx.instance_group
}
backend {
group = google_compute_instance_group_manager.nginx.instance_group
}