Skip to content

Commit 2f06c6f

Browse files
Make allow_global_access conditionally immutable for INTERNAL_MANAGED forwarding rules (#15079)
1 parent b834fdc commit 2f06c6f

File tree

2 files changed

+188
-0
lines changed

2 files changed

+188
-0
lines changed

mmv1/templates/terraform/constants/compute_forwarding_rule.go.tmpl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ func forwardingRuleCustomizeDiff(_ context.Context, diff *schema.ResourceDiff, v
1212
}
1313
}
1414
}
15+
16+
// Force recreation if allow_global_access changes for INTERNAL_MANAGED load balancing scheme
17+
if diff.Id() != "" && diff.HasChange("allow_global_access") {
18+
if loadBalancingScheme, ok := diff.Get("load_balancing_scheme").(string); ok && loadBalancingScheme == "INTERNAL_MANAGED" {
19+
diff.ForceNew("allow_global_access")
20+
}
21+
}
22+
1523
return nil
1624
}
1725

mmv1/third_party/terraform/services/compute/resource_compute_forwarding_rule_test.go.tmpl

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,3 +920,183 @@ resource "google_compute_network" "custom-test" {
920920
}
921921
`, context)
922922
}
923+
924+
func TestAccComputeForwardingRule_allowGlobalAccessUpdate_Internal(t *testing.T) {
925+
t.Parallel()
926+
927+
suffix := acctest.RandString(t, 10)
928+
poolName := fmt.Sprintf("tf-test-%s", suffix)
929+
ruleName := fmt.Sprintf("tf-test-%s", suffix)
930+
931+
acctest.VcrTest(t, resource.TestCase{
932+
PreCheck: func() { acctest.AccTestPreCheck(t) },
933+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
934+
CheckDestroy: testAccCheckComputeForwardingRuleDestroyProducer(t),
935+
Steps: []resource.TestStep{
936+
{
937+
Config: testAccComputeForwardingRule_allowGlobalAccess_Internal(poolName, ruleName, false),
938+
},
939+
{
940+
ResourceName: "google_compute_forwarding_rule.foobar",
941+
ImportState: true,
942+
ImportStateVerify: true,
943+
ImportStateVerifyIgnore: []string{"backend_service", "network", "subnetwork", "region"},
944+
},
945+
{
946+
Config: testAccComputeForwardingRule_allowGlobalAccess_Internal(poolName, ruleName, true),
947+
},
948+
{
949+
ResourceName: "google_compute_forwarding_rule.foobar",
950+
ImportState: true,
951+
ImportStateVerify: true,
952+
ImportStateVerifyIgnore: []string{"backend_service", "network", "subnetwork", "region"},
953+
},
954+
},
955+
})
956+
}
957+
958+
func TestAccComputeForwardingRule_allowGlobalAccessUpdate_InternalManaged(t *testing.T) {
959+
t.Parallel()
960+
961+
suffix := acctest.RandString(t, 10)
962+
poolName := fmt.Sprintf("tf-test-%s", suffix)
963+
ruleName := fmt.Sprintf("tf-test-%s", suffix)
964+
965+
acctest.VcrTest(t, resource.TestCase{
966+
PreCheck: func() { acctest.AccTestPreCheck(t) },
967+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
968+
CheckDestroy: testAccCheckComputeForwardingRuleDestroyProducer(t),
969+
Steps: []resource.TestStep{
970+
{
971+
Config: testAccComputeForwardingRule_allowGlobalAccess_InternalManaged(poolName, ruleName, false),
972+
},
973+
{
974+
ResourceName: "google_compute_forwarding_rule.foobar",
975+
ImportState: true,
976+
ImportStateVerify: true,
977+
ImportStateVerifyIgnore: []string{"target", "network", "subnetwork", "region"},
978+
},
979+
{
980+
// This should trigger recreation due to immutability for INTERNAL_MANAGED
981+
Config: testAccComputeForwardingRule_allowGlobalAccess_InternalManaged(poolName, ruleName, true),
982+
},
983+
{
984+
ResourceName: "google_compute_forwarding_rule.foobar",
985+
ImportState: true,
986+
ImportStateVerify: true,
987+
ImportStateVerifyIgnore: []string{"target", "network", "subnetwork", "region"},
988+
},
989+
},
990+
})
991+
}
992+
993+
func testAccComputeForwardingRule_allowGlobalAccess_Internal(poolName, ruleName string, allowGlobalAccess bool) string {
994+
return fmt.Sprintf(`
995+
resource "google_compute_network" "default" {
996+
name = "%s-network"
997+
auto_create_subnetworks = false
998+
}
999+
1000+
resource "google_compute_subnetwork" "default" {
1001+
name = "%s-subnet"
1002+
ip_cidr_range = "10.0.0.0/16"
1003+
region = "us-central1"
1004+
network = google_compute_network.default.id
1005+
}
1006+
1007+
resource "google_compute_health_check" "default" {
1008+
name = "%s-hc"
1009+
check_interval_sec = 1
1010+
timeout_sec = 1
1011+
tcp_health_check {
1012+
port = "80"
1013+
}
1014+
}
1015+
1016+
resource "google_compute_region_backend_service" "default" {
1017+
name = "%s-backend"
1018+
region = "us-central1"
1019+
health_checks = [google_compute_health_check.default.id]
1020+
load_balancing_scheme = "INTERNAL"
1021+
protocol = "TCP"
1022+
}
1023+
1024+
resource "google_compute_forwarding_rule" "foobar" {
1025+
name = "%s"
1026+
region = "us-central1"
1027+
network = google_compute_network.default.id
1028+
subnetwork = google_compute_subnetwork.default.id
1029+
load_balancing_scheme = "INTERNAL"
1030+
backend_service = google_compute_region_backend_service.default.id
1031+
all_ports = true
1032+
allow_global_access = %t
1033+
}
1034+
`, poolName, poolName, poolName, poolName, ruleName, allowGlobalAccess)
1035+
}
1036+
1037+
func testAccComputeForwardingRule_allowGlobalAccess_InternalManaged(poolName, ruleName string, allowGlobalAccess bool) string {
1038+
return fmt.Sprintf(`
1039+
resource "google_compute_network" "default" {
1040+
name = "%s-network"
1041+
auto_create_subnetworks = false
1042+
}
1043+
1044+
resource "google_compute_subnetwork" "default" {
1045+
name = "%s-subnet"
1046+
ip_cidr_range = "10.0.0.0/16"
1047+
region = "us-central1"
1048+
network = google_compute_network.default.id
1049+
}
1050+
1051+
resource "google_compute_subnetwork" "proxy" {
1052+
name = "%s-proxy-subnet"
1053+
ip_cidr_range = "10.1.0.0/24"
1054+
region = "us-central1"
1055+
network = google_compute_network.default.id
1056+
purpose = "REGIONAL_MANAGED_PROXY"
1057+
role = "ACTIVE"
1058+
}
1059+
1060+
resource "google_compute_health_check" "default" {
1061+
name = "%s-hc"
1062+
check_interval_sec = 1
1063+
timeout_sec = 1
1064+
http_health_check {
1065+
port = "80"
1066+
}
1067+
}
1068+
1069+
resource "google_compute_region_backend_service" "default" {
1070+
name = "%s-backend"
1071+
region = "us-central1"
1072+
health_checks = [google_compute_health_check.default.id]
1073+
load_balancing_scheme = "INTERNAL_MANAGED"
1074+
protocol = "HTTP"
1075+
}
1076+
1077+
resource "google_compute_region_url_map" "default" {
1078+
name = "%s-url-map"
1079+
region = "us-central1"
1080+
default_service = google_compute_region_backend_service.default.id
1081+
}
1082+
1083+
resource "google_compute_region_target_http_proxy" "default" {
1084+
name = "%s-http-proxy"
1085+
region = "us-central1"
1086+
url_map = google_compute_region_url_map.default.id
1087+
}
1088+
1089+
resource "google_compute_forwarding_rule" "foobar" {
1090+
name = "%s"
1091+
region = "us-central1"
1092+
network = google_compute_network.default.id
1093+
subnetwork = google_compute_subnetwork.default.id
1094+
load_balancing_scheme = "INTERNAL_MANAGED"
1095+
target = google_compute_region_target_http_proxy.default.id
1096+
port_range = "80"
1097+
allow_global_access = %t
1098+
1099+
depends_on = [google_compute_subnetwork.proxy]
1100+
}
1101+
`, poolName, poolName, poolName, poolName, poolName, poolName, poolName, ruleName, allowGlobalAccess)
1102+
}

0 commit comments

Comments
 (0)