Skip to content

Commit

Permalink
Adding noautomatednszone in the resource forwardingrule (#8102) (#…
Browse files Browse the repository at this point in the history
…5842)

* adding the new fields noAutomateDnsZone, need to validate the error with test step and the plan was not empty

* adding the tests scenarios, need to fix the test for global

* adding more tests, but requires a test with a no_autome_dns with true value

* added to the field, immutability and ignoring read from api, tests are passing

* removing comments from tests

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Jul 3, 2023
1 parent ce05082 commit 8bbd565
Show file tree
Hide file tree
Showing 7 changed files with 391 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .changelog/8102.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: added the `no_automate_dns_zone` field to `google_compute_forwarding_rule`.
```
142 changes: 131 additions & 11 deletions google-beta/resource_compute_forwarding_rule_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestAccComputeForwardingRule_internalHttpLbWithMigBackendExample(t *testing
ResourceName: "google_compute_forwarding_rule.google_compute_forwarding_rule",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"backend_service", "network", "subnetwork", "region", "port_range", "target"},
ImportStateVerifyIgnore: []string{"backend_service", "network", "subnetwork", "no_automate_dns_zone", "region", "port_range", "target"},
},
},
})
Expand Down Expand Up @@ -268,7 +268,7 @@ func TestAccComputeForwardingRule_internalTcpUdpLbWithMigBackendExample(t *testi
ResourceName: "google_compute_forwarding_rule.google_compute_forwarding_rule",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"backend_service", "network", "subnetwork", "region"},
ImportStateVerifyIgnore: []string{"backend_service", "network", "subnetwork", "no_automate_dns_zone", "region"},
},
},
})
Expand Down Expand Up @@ -476,7 +476,7 @@ func TestAccComputeForwardingRule_forwardingRuleExternallbExample(t *testing.T)
ResourceName: "google_compute_forwarding_rule.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"backend_service", "network", "subnetwork", "region", "port_range"},
ImportStateVerifyIgnore: []string{"backend_service", "network", "subnetwork", "no_automate_dns_zone", "region", "port_range"},
},
},
})
Expand Down Expand Up @@ -532,7 +532,7 @@ func TestAccComputeForwardingRule_forwardingRuleGlobalInternallbExample(t *testi
ResourceName: "google_compute_forwarding_rule.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"backend_service", "network", "subnetwork", "region"},
ImportStateVerifyIgnore: []string{"backend_service", "network", "subnetwork", "no_automate_dns_zone", "region"},
},
},
})
Expand Down Expand Up @@ -596,7 +596,7 @@ func TestAccComputeForwardingRule_forwardingRuleBasicExample(t *testing.T) {
ResourceName: "google_compute_forwarding_rule.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"backend_service", "network", "subnetwork", "region", "port_range", "target"},
ImportStateVerifyIgnore: []string{"backend_service", "network", "subnetwork", "no_automate_dns_zone", "region", "port_range", "target"},
},
},
})
Expand Down Expand Up @@ -635,7 +635,7 @@ func TestAccComputeForwardingRule_forwardingRuleL3DefaultExample(t *testing.T) {
ResourceName: "google_compute_forwarding_rule.fwd_rule",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"backend_service", "network", "subnetwork", "region"},
ImportStateVerifyIgnore: []string{"backend_service", "network", "subnetwork", "no_automate_dns_zone", "region"},
},
},
})
Expand Down Expand Up @@ -691,7 +691,7 @@ func TestAccComputeForwardingRule_forwardingRuleInternallbExample(t *testing.T)
ResourceName: "google_compute_forwarding_rule.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"backend_service", "network", "subnetwork", "region", "port_range", "target"},
ImportStateVerifyIgnore: []string{"backend_service", "network", "subnetwork", "no_automate_dns_zone", "region", "port_range", "target"},
},
},
})
Expand Down Expand Up @@ -760,7 +760,7 @@ func TestAccComputeForwardingRule_forwardingRuleHttpLbExample(t *testing.T) {
ResourceName: "google_compute_forwarding_rule.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"backend_service", "network", "subnetwork", "region", "port_range", "target"},
ImportStateVerifyIgnore: []string{"backend_service", "network", "subnetwork", "no_automate_dns_zone", "region", "port_range", "target"},
},
},
})
Expand Down Expand Up @@ -979,7 +979,7 @@ func TestAccComputeForwardingRule_forwardingRuleRegionalHttpXlbExample(t *testin
ResourceName: "google_compute_forwarding_rule.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"backend_service", "network", "subnetwork", "region", "port_range", "target", "ip_address"},
ImportStateVerifyIgnore: []string{"backend_service", "network", "subnetwork", "no_automate_dns_zone", "region", "port_range", "target", "ip_address"},
},
},
})
Expand Down Expand Up @@ -1205,7 +1205,7 @@ func TestAccComputeForwardingRule_forwardingRuleVpcPscExample(t *testing.T) {
ResourceName: "google_compute_forwarding_rule.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"backend_service", "network", "subnetwork", "region", "port_range", "target", "ip_address"},
ImportStateVerifyIgnore: []string{"backend_service", "network", "subnetwork", "no_automate_dns_zone", "region", "port_range", "target", "ip_address"},
},
},
})
Expand Down Expand Up @@ -1248,6 +1248,126 @@ resource "google_compute_address" "consumer_address" {
// Producer service attachment
resource "google_compute_network" "producer_net" {
name = "tf-test-producer-net%{random_suffix}"
auto_create_subnetworks = false
}
resource "google_compute_subnetwork" "producer_subnet" {
name = "tf-test-producer-net%{random_suffix}"
ip_cidr_range = "10.0.0.0/16"
region = "us-central1"
network = google_compute_network.producer_net.id
}
resource "google_compute_subnetwork" "psc_producer_subnet" {
name = "tf-test-producer-psc-net%{random_suffix}"
ip_cidr_range = "10.1.0.0/16"
region = "us-central1"
purpose = "PRIVATE_SERVICE_CONNECT"
network = google_compute_network.producer_net.id
}
resource "google_compute_service_attachment" "producer_service_attachment" {
name = "tf-test-producer-service%{random_suffix}"
region = "us-central1"
description = "A service attachment configured with Terraform"
enable_proxy_protocol = true
connection_preference = "ACCEPT_AUTOMATIC"
nat_subnets = [google_compute_subnetwork.psc_producer_subnet.name]
target_service = google_compute_forwarding_rule.producer_target_service.id
}
resource "google_compute_forwarding_rule" "producer_target_service" {
name = "tf-test-producer-forwarding-rule%{random_suffix}"
region = "us-central1"
load_balancing_scheme = "INTERNAL"
backend_service = google_compute_region_backend_service.producer_service_backend.id
all_ports = true
network = google_compute_network.producer_net.name
subnetwork = google_compute_subnetwork.producer_subnet.name
}
resource "google_compute_region_backend_service" "producer_service_backend" {
name = "tf-test-producer-service-backend%{random_suffix}"
region = "us-central1"
health_checks = [google_compute_health_check.producer_service_health_check.id]
}
resource "google_compute_health_check" "producer_service_health_check" {
name = "tf-test-producer-service-health-check%{random_suffix}"
check_interval_sec = 1
timeout_sec = 1
tcp_health_check {
port = "80"
}
}
`, context)
}

func TestAccComputeForwardingRule_forwardingRuleVpcPscNoAutomateDnsExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": RandString(t, 10),
}

VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeForwardingRuleDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeForwardingRule_forwardingRuleVpcPscNoAutomateDnsExample(context),
},
{
ResourceName: "google_compute_forwarding_rule.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"backend_service", "network", "subnetwork", "no_automate_dns_zone", "region", "port_range", "target", "ip_address"},
},
},
})
}

func testAccComputeForwardingRule_forwardingRuleVpcPscNoAutomateDnsExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_compute_forwarding_rule" "default" {
name = "tf-test-psc-endpoint%{random_suffix}"
region = "us-central1"
load_balancing_scheme = ""
target = google_compute_service_attachment.producer_service_attachment.id
network = google_compute_network.consumer_net.name
ip_address = google_compute_address.consumer_address.id
allow_psc_global_access = true
no_automate_dns_zone = true
}
resource "google_compute_network" "consumer_net" {
name = "tf-test-consumer-net%{random_suffix}"
auto_create_subnetworks = false
}
resource "google_compute_subnetwork" "consumer_subnet" {
name = "tf-test-consumer-net%{random_suffix}"
ip_cidr_range = "10.0.0.0/16"
region = "us-central1"
network = google_compute_network.consumer_net.id
}
resource "google_compute_address" "consumer_address" {
name = "tf-test-website-ip%{random_suffix}-1"
region = "us-central1"
subnetwork = google_compute_subnetwork.consumer_subnet.id
address_type = "INTERNAL"
}
resource "google_compute_network" "producer_net" {
name = "tf-test-producer-net%{random_suffix}"
auto_create_subnetworks = false
Expand Down Expand Up @@ -1329,7 +1449,7 @@ func TestAccComputeForwardingRule_forwardingRuleRegionalSteeringExample(t *testi
ResourceName: "google_compute_forwarding_rule.steering",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"backend_service", "network", "subnetwork", "region"},
ImportStateVerifyIgnore: []string{"backend_service", "network", "subnetwork", "no_automate_dns_zone", "region"},
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestAccComputeGlobalForwardingRule_externalTcpProxyLbMigBackendExample(t *t
ResourceName: "google_compute_global_forwarding_rule.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"network", "port_range", "target", "ip_address"},
ImportStateVerifyIgnore: []string{"network", "no_automate_dns_zone", "port_range", "target", "ip_address"},
},
},
})
Expand Down Expand Up @@ -223,7 +223,7 @@ func TestAccComputeGlobalForwardingRule_externalHttpLbMigBackendCustomHeaderExam
ResourceName: "google_compute_global_forwarding_rule.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"network", "port_range", "target", "ip_address"},
ImportStateVerifyIgnore: []string{"network", "no_automate_dns_zone", "port_range", "target", "ip_address"},
},
},
})
Expand Down Expand Up @@ -408,7 +408,7 @@ func TestAccComputeGlobalForwardingRule_globalForwardingRuleHttpExample(t *testi
ResourceName: "google_compute_global_forwarding_rule.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"network", "port_range", "target"},
ImportStateVerifyIgnore: []string{"network", "no_automate_dns_zone", "port_range", "target"},
},
},
})
Expand Down Expand Up @@ -486,7 +486,7 @@ func TestAccComputeGlobalForwardingRule_globalForwardingRuleInternalExample(t *t
ResourceName: "google_compute_global_forwarding_rule.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"network", "port_range", "target"},
ImportStateVerifyIgnore: []string{"network", "no_automate_dns_zone", "port_range", "target"},
},
},
})
Expand Down Expand Up @@ -623,7 +623,7 @@ func TestAccComputeGlobalForwardingRule_globalForwardingRuleExternalManagedExamp
ResourceName: "google_compute_global_forwarding_rule.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"network", "port_range", "target"},
ImportStateVerifyIgnore: []string{"network", "no_automate_dns_zone", "port_range", "target"},
},
},
})
Expand Down Expand Up @@ -694,7 +694,7 @@ func TestAccComputeGlobalForwardingRule_globalForwardingRuleHybridExample(t *tes
ResourceName: "google_compute_global_forwarding_rule.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"network", "port_range", "target"},
ImportStateVerifyIgnore: []string{"network", "no_automate_dns_zone", "port_range", "target"},
},
},
})
Expand Down Expand Up @@ -855,7 +855,7 @@ func TestAccComputeGlobalForwardingRule_privateServiceConnectGoogleApisExample(t
ResourceName: "google_compute_global_forwarding_rule.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"network", "ip_address"},
ImportStateVerifyIgnore: []string{"network", "no_automate_dns_zone", "ip_address"},
},
},
})
Expand Down Expand Up @@ -902,6 +902,74 @@ resource "google_compute_global_forwarding_rule" "default" {
`, context)
}

func TestAccComputeGlobalForwardingRule_privateServiceConnectGoogleApisNoAutomateDnsExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"project": envvar.GetTestProjectFromEnv(),
"random_suffix": RandString(t, 10),
}

VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: ProtoV5ProviderBetaFactories(t),
CheckDestroy: testAccCheckComputeGlobalForwardingRuleDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeGlobalForwardingRule_privateServiceConnectGoogleApisNoAutomateDnsExample(context),
},
{
ResourceName: "google_compute_global_forwarding_rule.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"network", "no_automate_dns_zone", "ip_address"},
},
},
})
}

func testAccComputeGlobalForwardingRule_privateServiceConnectGoogleApisNoAutomateDnsExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_compute_network" "network" {
provider = google-beta
project = "%{project}"
name = "tf-test-my-network%{random_suffix}"
auto_create_subnetworks = false
}
resource "google_compute_subnetwork" "vpc_subnetwork" {
provider = google-beta
project = google_compute_network.network.project
name = "tf-test-my-subnetwork%{random_suffix}"
ip_cidr_range = "10.2.0.0/16"
region = "us-central1"
network = google_compute_network.network.id
private_ip_google_access = true
}
resource "google_compute_global_address" "default" {
provider = google-beta
project = google_compute_network.network.project
name = "tf-test-global-psconnect-ip%{random_suffix}"
address_type = "INTERNAL"
purpose = "PRIVATE_SERVICE_CONNECT"
network = google_compute_network.network.id
address = "100.100.100.106"
}
resource "google_compute_global_forwarding_rule" "default" {
provider = google-beta
project = google_compute_network.network.project
name = "globalrule%{random_suffix}"
target = "all-apis"
network = google_compute_network.network.id
ip_address = google_compute_global_address.default.id
load_balancing_scheme = ""
no_automate_dns_zone = false
}
`, context)
}

func testAccCheckComputeGlobalForwardingRuleDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
Expand Down
Loading

0 comments on commit 8bbd565

Please sign in to comment.