@@ -139,6 +139,67 @@ func testAccResourceNsxtPolicyNATRuleBasicT1(t *testing.T, withContext bool, pre
139
139
})
140
140
}
141
141
142
+ func TestAccResourceNsxtPolicyNATRule_withPolicyBasedVpnMode (t * testing.T ) {
143
+ name := getAccTestResourceName ()
144
+ updateName := getAccTestResourceName ()
145
+ snet := "22.1.1.2"
146
+ dnet := "33.1.1.2"
147
+ tnet := "44.1.1.2"
148
+ action := model .PolicyNatRule_ACTION_DNAT
149
+
150
+ resource .ParallelTest (t , resource.TestCase {
151
+ PreCheck : func () { testAccPreCheck (t ); testAccNSXVersion (t , "4.0.0" ) },
152
+ Providers : testAccProviders ,
153
+ CheckDestroy : func (state * terraform.State ) error {
154
+ return testAccNsxtPolicyNATRuleCheckDestroy (state , name , false )
155
+ },
156
+ Steps : []resource.TestStep {
157
+ {
158
+ Config : testAccNsxtPolicyNATRuleTier1CreateTemplateWithPolicyBasedVpnMode (name , action , testAccResourcePolicyNATRuleSourceNet , testAccResourcePolicyNATRuleDestNet , testAccResourcePolicyNATRuleTransNet , model .PolicyNatRule_POLICY_BASED_VPN_MODE_BYPASS , false ),
159
+ Check : resource .ComposeTestCheckFunc (
160
+ testAccNsxtPolicyNATRuleExists (testAccResourcePolicyNATRuleName , false ),
161
+ resource .TestCheckResourceAttr (testAccResourcePolicyNATRuleName , "display_name" , name ),
162
+ resource .TestCheckResourceAttr (testAccResourcePolicyNATRuleName , "description" , "Acceptance Test" ),
163
+ resource .TestCheckResourceAttr (testAccResourcePolicyNATRuleName , "destination_networks.#" , "1" ),
164
+ resource .TestCheckResourceAttr (testAccResourcePolicyNATRuleName , "source_networks.#" , "1" ),
165
+ resource .TestCheckResourceAttr (testAccResourcePolicyNATRuleName , "translated_networks.#" , "1" ),
166
+ resource .TestCheckResourceAttr (testAccResourcePolicyNATRuleName , "destination_networks.0" , testAccResourcePolicyNATRuleDestNet ),
167
+ resource .TestCheckResourceAttr (testAccResourcePolicyNATRuleName , "source_networks.0" , testAccResourcePolicyNATRuleSourceNet ),
168
+ resource .TestCheckResourceAttr (testAccResourcePolicyNATRuleName , "translated_networks.0" , testAccResourcePolicyNATRuleTransNet ),
169
+ resource .TestCheckResourceAttr (testAccResourcePolicyNATRuleName , "tag.#" , "2" ),
170
+ resource .TestCheckResourceAttr (testAccResourcePolicyNATRuleName , "action" , action ),
171
+ resource .TestCheckResourceAttr (testAccResourcePolicyNATRuleName , "logging" , "false" ),
172
+ resource .TestCheckResourceAttr (testAccResourcePolicyNATRuleName , "firewall_match" , model .PolicyNatRule_FIREWALL_MATCH_BYPASS ),
173
+ resource .TestCheckResourceAttr (testAccResourcePolicyNATRuleName , "policy_based_vpn_mode" , model .PolicyNatRule_POLICY_BASED_VPN_MODE_BYPASS ),
174
+ resource .TestCheckResourceAttrSet (testAccResourcePolicyNATRuleName , "path" ),
175
+ resource .TestCheckResourceAttrSet (testAccResourcePolicyNATRuleName , "revision" ),
176
+ ),
177
+ },
178
+ {
179
+ Config : testAccNsxtPolicyNATRuleTier1CreateTemplateWithPolicyBasedVpnMode (updateName , action , snet , dnet , tnet , model .PolicyNatRule_POLICY_BASED_VPN_MODE_MATCH , false ),
180
+ Check : resource .ComposeTestCheckFunc (
181
+ testAccNsxtPolicyNATRuleExists (testAccResourcePolicyNATRuleName , false ),
182
+ resource .TestCheckResourceAttr (testAccResourcePolicyNATRuleName , "display_name" , updateName ),
183
+ resource .TestCheckResourceAttr (testAccResourcePolicyNATRuleName , "description" , "Acceptance Test" ),
184
+ resource .TestCheckResourceAttr (testAccResourcePolicyNATRuleName , "destination_networks.#" , "1" ),
185
+ resource .TestCheckResourceAttr (testAccResourcePolicyNATRuleName , "source_networks.#" , "1" ),
186
+ resource .TestCheckResourceAttr (testAccResourcePolicyNATRuleName , "translated_networks.#" , "1" ),
187
+ resource .TestCheckResourceAttr (testAccResourcePolicyNATRuleName , "destination_networks.0" , dnet ),
188
+ resource .TestCheckResourceAttr (testAccResourcePolicyNATRuleName , "source_networks.0" , snet ),
189
+ resource .TestCheckResourceAttr (testAccResourcePolicyNATRuleName , "translated_networks.0" , tnet ),
190
+ resource .TestCheckResourceAttr (testAccResourcePolicyNATRuleName , "tag.#" , "2" ),
191
+ resource .TestCheckResourceAttr (testAccResourcePolicyNATRuleName , "action" , action ),
192
+ resource .TestCheckResourceAttr (testAccResourcePolicyNATRuleName , "logging" , "false" ),
193
+ resource .TestCheckResourceAttr (testAccResourcePolicyNATRuleName , "firewall_match" , model .PolicyNatRule_FIREWALL_MATCH_BYPASS ),
194
+ resource .TestCheckResourceAttr (testAccResourcePolicyNATRuleName , "policy_based_vpn_mode" , model .PolicyNatRule_POLICY_BASED_VPN_MODE_MATCH ),
195
+ resource .TestCheckResourceAttrSet (testAccResourcePolicyNATRuleName , "path" ),
196
+ resource .TestCheckResourceAttrSet (testAccResourcePolicyNATRuleName , "revision" ),
197
+ ),
198
+ },
199
+ },
200
+ })
201
+ }
202
+
142
203
func TestAccResourceNsxtPolicyNATRule_basicT0 (t * testing.T ) {
143
204
name := getAccTestResourceName ()
144
205
updateName := getAccTestResourceName ()
@@ -455,16 +516,16 @@ data "nsxt_policy_service" "test" {
455
516
456
517
resource "nsxt_policy_nat_rule" "test" {
457
518
%s
458
- display_name = "%s"
459
- description = "Acceptance Test"
460
- gateway_path = nsxt_policy_tier1_gateway.test.path
461
- action = "%s"
462
- source_networks = ["%s"]
463
- destination_networks = ["%s"]
464
- translated_networks = ["%s"]
465
- logging = false
466
- firewall_match = "%s"
467
- service = data.nsxt_policy_service.test.path
519
+ display_name = "%s"
520
+ description = "Acceptance Test"
521
+ gateway_path = nsxt_policy_tier1_gateway.test.path
522
+ action = "%s"
523
+ source_networks = ["%s"]
524
+ destination_networks = ["%s"]
525
+ translated_networks = ["%s"]
526
+ logging = false
527
+ firewall_match = "%s"
528
+ service = data.nsxt_policy_service.test.path
468
529
469
530
tag {
470
531
scope = "scope1"
@@ -479,6 +540,44 @@ resource "nsxt_policy_nat_rule" "test" {
479
540
` , context , name , action , sourceNet , destNet , translatedNet , model .PolicyNatRule_FIREWALL_MATCH_BYPASS )
480
541
}
481
542
543
+ func testAccNsxtPolicyNATRuleTier1CreateTemplateWithPolicyBasedVpnMode (name string , action string , sourceNet string , destNet string , translatedNet string , policyBasedVpnMode string , withContext bool ) string {
544
+ context := ""
545
+ if withContext {
546
+ context = testAccNsxtPolicyMultitenancyContext ()
547
+ }
548
+ return testAccNsxtPolicyEdgeClusterReadTemplate (getEdgeClusterName ()) +
549
+ testAccNsxtPolicyTier1WithEdgeClusterTemplate ("test" , false , withContext ) + fmt .Sprintf (`
550
+ data "nsxt_policy_service" "test" {
551
+ display_name = "DNS-UDP"
552
+ }
553
+
554
+ resource "nsxt_policy_nat_rule" "test" {
555
+ %s
556
+ display_name = "%s"
557
+ description = "Acceptance Test"
558
+ gateway_path = nsxt_policy_tier1_gateway.test.path
559
+ action = "%s"
560
+ source_networks = ["%s"]
561
+ destination_networks = ["%s"]
562
+ translated_networks = ["%s"]
563
+ logging = false
564
+ firewall_match = "%s"
565
+ service = data.nsxt_policy_service.test.path
566
+ policy_based_vpn_mode = "%s"
567
+
568
+ tag {
569
+ scope = "scope1"
570
+ tag = "tag1"
571
+ }
572
+
573
+ tag {
574
+ scope = "scope2"
575
+ tag = "tag2"
576
+ }
577
+ }
578
+ ` , context , name , action , sourceNet , destNet , translatedNet , model .PolicyNatRule_FIREWALL_MATCH_BYPASS , policyBasedVpnMode )
579
+ }
580
+
482
581
func testAccNsxtPolicyNATRuleTier1UpdateMultipleSourceNetworksTemplate (name string , action string , sourceNet1 string , sourceNet2 string , destNet string , translatedNet string , withContext bool ) string {
483
582
context := ""
484
583
if withContext {
@@ -488,15 +587,15 @@ func testAccNsxtPolicyNATRuleTier1UpdateMultipleSourceNetworksTemplate(name stri
488
587
testAccNsxtPolicyTier1WithEdgeClusterTemplate ("test" , false , withContext ) + fmt .Sprintf (`
489
588
resource "nsxt_policy_nat_rule" "test" {
490
589
%s
491
- display_name = "%s"
492
- description = "Acceptance Test"
493
- gateway_path = nsxt_policy_tier1_gateway.test.path
494
- action = "%s"
495
- source_networks = ["%s", "%s"]
496
- destination_networks = ["%s"]
497
- translated_networks = ["%s"]
498
- logging = false
499
- firewall_match = "%s"
590
+ display_name = "%s"
591
+ description = "Acceptance Test"
592
+ gateway_path = nsxt_policy_tier1_gateway.test.path
593
+ action = "%s"
594
+ source_networks = ["%s", "%s"]
595
+ destination_networks = ["%s"]
596
+ translated_networks = ["%s"]
597
+ logging = false
598
+ firewall_match = "%s"
500
599
501
600
tag {
502
601
scope = "scope1"
@@ -549,15 +648,15 @@ resource "nsxt_policy_tier0_gateway_interface" "test" {
549
648
}
550
649
551
650
resource "nsxt_policy_nat_rule" "test" {
552
- display_name = "%s"
553
- description = "Acceptance Test"
554
- gateway_path = nsxt_policy_tier0_gateway.test.path
555
- action = "%s"
556
- source_networks = ["%s"]
557
- translated_networks = ["%s"]
558
- logging = false
559
- firewall_match = "%s"
560
- scope = [nsxt_policy_tier0_gateway_interface.test[1].path, nsxt_policy_tier0_gateway_interface.test[0].path]
651
+ display_name = "%s"
652
+ description = "Acceptance Test"
653
+ gateway_path = nsxt_policy_tier0_gateway.test.path
654
+ action = "%s"
655
+ source_networks = ["%s"]
656
+ translated_networks = ["%s"]
657
+ logging = false
658
+ firewall_match = "%s"
659
+ scope = [nsxt_policy_tier0_gateway_interface.test[1].path, nsxt_policy_tier0_gateway_interface.test[0].path]
561
660
562
661
tag {
563
662
scope = "scope1"
@@ -577,14 +676,14 @@ func testAccNsxPolicyNatRuleNoTranslatedNetworkTemplate(name string, action stri
577
676
return testAccNsxtPolicyEdgeClusterReadTemplate (getEdgeClusterName ()) +
578
677
testAccNsxtPolicyTier1WithEdgeClusterTemplate ("test" , false , false ) + fmt .Sprintf (`
579
678
resource "nsxt_policy_nat_rule" "test" {
580
- display_name = "%s"
581
- description = "Acceptance Test"
582
- gateway_path = nsxt_policy_tier1_gateway.test.path
583
- action = "%s"
584
- source_networks = ["%s"]
585
- destination_networks = ["%s"]
586
- logging = false
587
- firewall_match = "%s"
679
+ display_name = "%s"
680
+ description = "Acceptance Test"
681
+ gateway_path = nsxt_policy_tier1_gateway.test.path
682
+ action = "%s"
683
+ source_networks = ["%s"]
684
+ destination_networks = ["%s"]
685
+ logging = false
686
+ firewall_match = "%s"
588
687
589
688
tag {
590
689
scope = "scope1"
0 commit comments