@@ -50,7 +50,7 @@ func TestAccComputeGlobalForwardingRule_externalTcpProxyLbMigBackendExample(t *t
5050 ResourceName : "google_compute_global_forwarding_rule.default" ,
5151 ImportState : true ,
5252 ImportStateVerify : true ,
53- ImportStateVerifyIgnore : []string {"network" , "no_automate_dns_zone" , "port_range" , "target" , "ip_address" },
53+ ImportStateVerifyIgnore : []string {"network" , "subnetwork" , " no_automate_dns_zone" , "port_range" , "target" , "ip_address" },
5454 },
5555 },
5656 })
@@ -223,7 +223,7 @@ func TestAccComputeGlobalForwardingRule_externalHttpLbMigBackendCustomHeaderExam
223223 ResourceName : "google_compute_global_forwarding_rule.default" ,
224224 ImportState : true ,
225225 ImportStateVerify : true ,
226- ImportStateVerifyIgnore : []string {"network" , "no_automate_dns_zone" , "port_range" , "target" , "ip_address" },
226+ ImportStateVerifyIgnore : []string {"network" , "subnetwork" , " no_automate_dns_zone" , "port_range" , "target" , "ip_address" },
227227 },
228228 },
229229 })
@@ -408,7 +408,7 @@ func TestAccComputeGlobalForwardingRule_globalForwardingRuleHttpExample(t *testi
408408 ResourceName : "google_compute_global_forwarding_rule.default" ,
409409 ImportState : true ,
410410 ImportStateVerify : true ,
411- ImportStateVerifyIgnore : []string {"network" , "no_automate_dns_zone" , "port_range" , "target" },
411+ ImportStateVerifyIgnore : []string {"network" , "subnetwork" , " no_automate_dns_zone" , "port_range" , "target" },
412412 },
413413 },
414414 })
@@ -486,7 +486,7 @@ func TestAccComputeGlobalForwardingRule_globalForwardingRuleInternalExample(t *t
486486 ResourceName : "google_compute_global_forwarding_rule.default" ,
487487 ImportState : true ,
488488 ImportStateVerify : true ,
489- ImportStateVerifyIgnore : []string {"network" , "no_automate_dns_zone" , "port_range" , "target" },
489+ ImportStateVerifyIgnore : []string {"network" , "subnetwork" , " no_automate_dns_zone" , "port_range" , "target" },
490490 },
491491 },
492492 })
@@ -623,7 +623,7 @@ func TestAccComputeGlobalForwardingRule_globalForwardingRuleExternalManagedExamp
623623 ResourceName : "google_compute_global_forwarding_rule.default" ,
624624 ImportState : true ,
625625 ImportStateVerify : true ,
626- ImportStateVerifyIgnore : []string {"network" , "no_automate_dns_zone" , "port_range" , "target" },
626+ ImportStateVerifyIgnore : []string {"network" , "subnetwork" , " no_automate_dns_zone" , "port_range" , "target" },
627627 },
628628 },
629629 })
@@ -694,7 +694,7 @@ func TestAccComputeGlobalForwardingRule_globalForwardingRuleHybridExample(t *tes
694694 ResourceName : "google_compute_global_forwarding_rule.default" ,
695695 ImportState : true ,
696696 ImportStateVerify : true ,
697- ImportStateVerifyIgnore : []string {"network" , "no_automate_dns_zone" , "port_range" , "target" },
697+ ImportStateVerifyIgnore : []string {"network" , "subnetwork" , " no_automate_dns_zone" , "port_range" , "target" },
698698 },
699699 },
700700 })
@@ -835,6 +835,219 @@ resource "google_compute_global_forwarding_rule" "default" {
835835` , context )
836836}
837837
838+ func TestAccComputeGlobalForwardingRule_globalInternalHttpLbWithMigBackendExample (t * testing.T ) {
839+ t .Parallel ()
840+
841+ context := map [string ]interface {}{
842+ "random_suffix" : acctest .RandString (t , 10 ),
843+ }
844+
845+ acctest .VcrTest (t , resource.TestCase {
846+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
847+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderBetaFactories (t ),
848+ CheckDestroy : testAccCheckComputeGlobalForwardingRuleDestroyProducer (t ),
849+ Steps : []resource.TestStep {
850+ {
851+ Config : testAccComputeGlobalForwardingRule_globalInternalHttpLbWithMigBackendExample (context ),
852+ },
853+ {
854+ ResourceName : "google_compute_global_forwarding_rule.google_compute_forwarding_rule" ,
855+ ImportState : true ,
856+ ImportStateVerify : true ,
857+ ImportStateVerifyIgnore : []string {"network" , "subnetwork" , "no_automate_dns_zone" , "port_range" , "target" },
858+ },
859+ },
860+ })
861+ }
862+
863+ func testAccComputeGlobalForwardingRule_globalInternalHttpLbWithMigBackendExample (context map [string ]interface {}) string {
864+ return acctest .Nprintf (`
865+ # Global Internal HTTP load balancer with a managed instance group backend
866+
867+ # VPC network
868+ resource "google_compute_network" "gilb_network" {
869+ name = "tf-test-l7-gilb-network%{random_suffix}"
870+ provider = google-beta
871+ auto_create_subnetworks = false
872+ }
873+
874+ # proxy-only subnet
875+ resource "google_compute_subnetwork" "proxy_subnet" {
876+ name = "tf-test-l7-gilb-proxy-subnet%{random_suffix}"
877+ provider = google-beta
878+ ip_cidr_range = "10.0.0.0/24"
879+ region = "europe-west1"
880+ purpose = "GLOBAL_MANAGED_PROXY"
881+ role = "ACTIVE"
882+ network = google_compute_network.gilb_network.id
883+ }
884+
885+ # backend subnet
886+ resource "google_compute_subnetwork" "gilb_subnet" {
887+ name = "tf-test-l7-gilb-subnet%{random_suffix}"
888+ provider = google-beta
889+ ip_cidr_range = "10.0.1.0/24"
890+ region = "europe-west1"
891+ network = google_compute_network.gilb_network.id
892+ }
893+
894+ # forwarding rule
895+ resource "google_compute_global_forwarding_rule" "google_compute_forwarding_rule" {
896+ name = "tf-test-l7-gilb-forwarding-rule%{random_suffix}"
897+ provider = google-beta
898+ depends_on = [google_compute_subnetwork.proxy_subnet]
899+ ip_protocol = "TCP"
900+ load_balancing_scheme = "INTERNAL_MANAGED"
901+ port_range = "80"
902+ target = google_compute_target_http_proxy.default.id
903+ network = google_compute_network.gilb_network.id
904+ subnetwork = google_compute_subnetwork.gilb_subnet.id
905+ }
906+
907+ # HTTP target proxy
908+ resource "google_compute_target_http_proxy" "default" {
909+ name = "tf-test-l7-gilb-target-http-proxy%{random_suffix}"
910+ provider = google-beta
911+ url_map = google_compute_url_map.default.id
912+ }
913+
914+ # URL map
915+ resource "google_compute_url_map" "default" {
916+ name = "tf-test-l7-gilb-url-map%{random_suffix}"
917+ provider = google-beta
918+ default_service = google_compute_backend_service.default.id
919+ }
920+
921+ # backend service
922+ resource "google_compute_backend_service" "default" {
923+ name = "tf-test-l7-gilb-backend-subnet%{random_suffix}"
924+ provider = google-beta
925+ protocol = "HTTP"
926+ load_balancing_scheme = "INTERNAL_MANAGED"
927+ timeout_sec = 10
928+ health_checks = [google_compute_health_check.default.id]
929+ backend {
930+ group = google_compute_instance_group_manager.mig.instance_group
931+ balancing_mode = "UTILIZATION"
932+ capacity_scaler = 1.0
933+ }
934+ }
935+
936+ # instance template
937+ resource "google_compute_instance_template" "instance_template" {
938+ name = "tf-test-l7-gilb-mig-template%{random_suffix}"
939+ provider = google-beta
940+ machine_type = "e2-small"
941+ tags = ["http-server"]
942+
943+ network_interface {
944+ network = google_compute_network.gilb_network.id
945+ subnetwork = google_compute_subnetwork.gilb_subnet.id
946+ access_config {
947+ # add external ip to fetch packages
948+ }
949+ }
950+ disk {
951+ source_image = "debian-cloud/debian-10"
952+ auto_delete = true
953+ boot = true
954+ }
955+
956+ # install nginx and serve a simple web page
957+ metadata = {
958+ startup-script = <<-EOF1
959+ #! /bin/bash
960+ set -euo pipefail
961+
962+ export DEBIAN_FRONTEND=noninteractive
963+ apt-get update
964+ apt-get install -y nginx-light jq
965+
966+ NAME=$(curl -H "Metadata-Flavor: Google" "http://metadata.google.internal/computeMetadata/v1/instance/hostname")
967+ IP=$(curl -H "Metadata-Flavor: Google" "http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/0/ip")
968+ METADATA=$(curl -f -H "Metadata-Flavor: Google" "http://metadata.google.internal/computeMetadata/v1/instance/attributes/?recursive=True" | jq 'del(.["startup-script"])')
969+
970+ cat <<EOF > /var/www/html/index.html
971+ <pre>
972+ Name: $NAME
973+ IP: $IP
974+ Metadata: $METADATA
975+ </pre>
976+ EOF
977+ EOF1
978+ }
979+ lifecycle {
980+ create_before_destroy = true
981+ }
982+ }
983+
984+ # health check
985+ resource "google_compute_health_check" "default" {
986+ name = "tf-test-l7-gilb-hc%{random_suffix}"
987+ provider = google-beta
988+ http_health_check {
989+ port_specification = "USE_SERVING_PORT"
990+ }
991+ }
992+
993+ # MIG
994+ resource "google_compute_instance_group_manager" "mig" {
995+ name = "tf-test-l7-gilb-mig1%{random_suffix}"
996+ provider = google-beta
997+ zone = "europe-west1-b"
998+ version {
999+ instance_template = google_compute_instance_template.instance_template.id
1000+ name = "primary"
1001+ }
1002+ base_instance_name = "vm"
1003+ target_size = 2
1004+ }
1005+
1006+ # allow all access from IAP and health check ranges
1007+ resource "google_compute_firewall" "fw-iap" {
1008+ name = "tf-test-l7-gilb-fw-allow-iap-hc%{random_suffix}"
1009+ provider = google-beta
1010+ direction = "INGRESS"
1011+ network = google_compute_network.gilb_network.id
1012+ source_ranges = ["130.211.0.0/22", "35.191.0.0/16", "35.235.240.0/20"]
1013+ allow {
1014+ protocol = "tcp"
1015+ }
1016+ }
1017+
1018+ # allow http from proxy subnet to backends
1019+ resource "google_compute_firewall" "fw-gilb-to-backends" {
1020+ name = "tf-test-l7-gilb-fw-allow-gilb-to-backends%{random_suffix}"
1021+ provider = google-beta
1022+ direction = "INGRESS"
1023+ network = google_compute_network.gilb_network.id
1024+ source_ranges = ["10.0.0.0/24"]
1025+ target_tags = ["http-server"]
1026+ allow {
1027+ protocol = "tcp"
1028+ ports = ["80", "443", "8080"]
1029+ }
1030+ }
1031+
1032+ # test instance
1033+ resource "google_compute_instance" "vm-test" {
1034+ name = "tf-test-l7-gilb-test-vm%{random_suffix}"
1035+ provider = google-beta
1036+ zone = "europe-west1-b"
1037+ machine_type = "e2-small"
1038+ network_interface {
1039+ network = google_compute_network.gilb_network.id
1040+ subnetwork = google_compute_subnetwork.gilb_subnet.id
1041+ }
1042+ boot_disk {
1043+ initialize_params {
1044+ image = "debian-cloud/debian-10"
1045+ }
1046+ }
1047+ }
1048+ ` , context )
1049+ }
1050+
8381051func TestAccComputeGlobalForwardingRule_privateServiceConnectGoogleApisExample (t * testing.T ) {
8391052 t .Parallel ()
8401053
@@ -855,7 +1068,7 @@ func TestAccComputeGlobalForwardingRule_privateServiceConnectGoogleApisExample(t
8551068 ResourceName : "google_compute_global_forwarding_rule.default" ,
8561069 ImportState : true ,
8571070 ImportStateVerify : true ,
858- ImportStateVerifyIgnore : []string {"network" , "no_automate_dns_zone" , "ip_address" },
1071+ ImportStateVerifyIgnore : []string {"network" , "subnetwork" , " no_automate_dns_zone" , "ip_address" },
8591072 },
8601073 },
8611074 })
@@ -922,7 +1135,7 @@ func TestAccComputeGlobalForwardingRule_privateServiceConnectGoogleApisNoAutomat
9221135 ResourceName : "google_compute_global_forwarding_rule.default" ,
9231136 ImportState : true ,
9241137 ImportStateVerify : true ,
925- ImportStateVerifyIgnore : []string {"network" , "no_automate_dns_zone" , "ip_address" },
1138+ ImportStateVerifyIgnore : []string {"network" , "subnetwork" , " no_automate_dns_zone" , "ip_address" },
9261139 },
9271140 },
9281141 })
0 commit comments