@@ -513,3 +513,134 @@ resource "google_network_services_gateway" "default" {
513513}
514514` , context )
515515}
516+
517+ func TestAccComputeServiceAttachment_withNatIps (t * testing.T ) {
518+ t .Parallel ()
519+
520+ context := map [string ]interface {}{
521+ "random_suffix" : acctest .RandString (t , 10 ),
522+ }
523+
524+ acctest .VcrTest (t , resource.TestCase {
525+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
526+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
527+ CheckDestroy : testAccCheckComputeServiceAttachmentDestroyProducer (t ),
528+ Steps : []resource.TestStep {
529+ {
530+
531+ Config : testAccComputeServiceAttachment_withNatIps (context , false ),
532+ },
533+ {
534+ Config : testAccComputeServiceAttachment_withNatIps (context , true ),
535+ Check : resource .ComposeTestCheckFunc (
536+ resource .TestCheckResourceAttrSet (
537+ "google_compute_service_attachment.psc_ilb_service_attachment" , "connected_endpoints.0.nat_ips.0" ),
538+ ),
539+ },
540+ {
541+ ResourceName : "google_compute_service_attachment.psc_ilb_service_attachment" ,
542+ ImportState : true ,
543+ ImportStateVerify : true ,
544+ ImportStateVerifyIgnore : []string {"target_service" , "region" , "show_nat_ips" , "connected_endpoints.0.nat_ips" },
545+ },
546+ {
547+ Config : testAccComputeServiceAttachment_withNatIps (context , false ),
548+ Check : resource .ComposeTestCheckFunc (
549+ resource .TestCheckResourceAttr ("google_compute_service_attachment.psc_ilb_service_attachment" , "show_nat_ips" , "false" ),
550+ resource .TestCheckResourceAttr ("google_compute_service_attachment.psc_ilb_service_attachment" , "connected_endpoints.0.nat_ips.#" , "0" ),
551+ ),
552+ },
553+ },
554+ })
555+ }
556+
557+ func testAccComputeServiceAttachment_withNatIps (context map [string ]interface {}, showNatIps bool ) string {
558+ context ["show_nat_ips" ] = showNatIps
559+ return acctest .Nprintf (`
560+ resource "google_compute_service_attachment" "psc_ilb_service_attachment" {
561+ name = "tf-test-my-psc-ilb%{random_suffix}"
562+ region = "us-west2"
563+ description = "A service attachment configured with Terraform"
564+ enable_proxy_protocol = false
565+ connection_preference = "ACCEPT_AUTOMATIC"
566+ show_nat_ips = %{show_nat_ips}
567+ nat_subnets = [google_compute_subnetwork.psc_ilb_nat.id]
568+ target_service = google_compute_forwarding_rule.psc_ilb_target_service.id
569+ }
570+
571+ resource "google_compute_address" "psc_ilb_consumer_address" {
572+ name = "tf-test-psc-ilb-consumer-address%{random_suffix}"
573+ region = "us-west2"
574+ subnetwork = google_compute_subnetwork.psc_ilb_consumer_subnetwork.id
575+ address_type = "INTERNAL"
576+ }
577+
578+ resource "google_compute_forwarding_rule" "psc_ilb_consumer" {
579+ name = "tf-test-psc-ilb-consumer-forwarding-rule%{random_suffix}"
580+ region = "us-west2"
581+ target = google_compute_service_attachment.psc_ilb_service_attachment.id
582+ load_balancing_scheme = ""
583+ network = google_compute_network.consumer_network.name
584+ ip_address = google_compute_address.psc_ilb_consumer_address.id
585+ }
586+
587+ resource "google_compute_forwarding_rule" "psc_ilb_target_service" {
588+ name = "tf-test-producer-forwarding-rule%{random_suffix}"
589+ region = "us-west2"
590+ load_balancing_scheme = "INTERNAL"
591+ backend_service = google_compute_region_backend_service.producer_service_backend.id
592+ all_ports = true
593+ network = google_compute_network.producer_network.name
594+ subnetwork = google_compute_subnetwork.psc_ilb_producer_subnetwork.name
595+ }
596+
597+ resource "google_compute_region_backend_service" "producer_service_backend" {
598+ name = "tf-test-producer-service%{random_suffix}"
599+ region = "us-west2"
600+ health_checks = [google_compute_health_check.producer_service_health_check.id]
601+ }
602+
603+ resource "google_compute_health_check" "producer_service_health_check" {
604+ name = "tf-test-producer-service-health-check%{random_suffix}"
605+ check_interval_sec = 1
606+ timeout_sec = 1
607+ tcp_health_check {
608+ port = "80"
609+ }
610+ }
611+
612+ resource "google_compute_network" "producer_network" {
613+ name = "tf-test-psc-ilb-producer-network%{random_suffix}"
614+ auto_create_subnetworks = false
615+ delete_default_routes_on_create = true
616+ }
617+
618+ resource "google_compute_network" "consumer_network" {
619+ name = "tf-test-psc-ilb-consumer-network%{random_suffix}"
620+ auto_create_subnetworks = false
621+ delete_default_routes_on_create = true
622+ }
623+
624+ resource "google_compute_subnetwork" "psc_ilb_producer_subnetwork" {
625+ name = "tf-test-psc-ilb-producer-subnetwork%{random_suffix}"
626+ region = "us-west2"
627+ network = google_compute_network.producer_network.id
628+ ip_cidr_range = "10.0.0.0/16"
629+ }
630+
631+ resource "google_compute_subnetwork" "psc_ilb_consumer_subnetwork" {
632+ name = "tf-test-psc-ilb-consumer-subnetwork%{random_suffix}"
633+ region = "us-west2"
634+ network = google_compute_network.consumer_network.id
635+ ip_cidr_range = "10.2.0.0/16"
636+ }
637+
638+ resource "google_compute_subnetwork" "psc_ilb_nat" {
639+ name = "tf-test-psc-ilb-nat%{random_suffix}"
640+ region = "us-west2"
641+ network = google_compute_network.producer_network.id
642+ purpose = "PRIVATE_SERVICE_CONNECT"
643+ ip_cidr_range = "10.1.0.0/16"
644+ }
645+ ` , context )
646+ }
0 commit comments