8
8
"testing"
9
9
10
10
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
11
+ "github.com/hashicorp/terraform-plugin-testing/plancheck"
11
12
"github.com/hashicorp/terraform-plugin-testing/terraform"
12
13
"github.com/hashicorp/terraform-provider-google/google/acctest"
13
14
tpgcompute "github.com/hashicorp/terraform-provider-google/google/services/compute"
@@ -97,7 +98,6 @@ func TestAccComputeSubnetwork_update(t *testing.T) {
97
98
t .Parallel ()
98
99
99
100
var subnetwork compute.Subnetwork
100
-
101
101
cnName := fmt .Sprintf ("tf-test-%s" , acctest .RandString (t , 10 ))
102
102
subnetworkName := fmt .Sprintf ("tf-test-%s" , acctest .RandString (t , 10 ))
103
103
@@ -109,32 +109,28 @@ func TestAccComputeSubnetwork_update(t *testing.T) {
109
109
{
110
110
Config : testAccComputeSubnetwork_update1 (cnName , "10.2.0.0/24" , subnetworkName ),
111
111
Check : resource .ComposeTestCheckFunc (
112
- testAccCheckComputeSubnetworkExists (
113
- t , "google_compute_subnetwork.network-with-private-google-access" , & subnetwork ),
112
+ testAccCheckComputeSubnetworkExists (t , "google_compute_subnetwork.network-with-private-google-access" , & subnetwork ),
114
113
),
115
114
},
116
115
{
117
116
// Expand IP CIDR range and update private_ip_google_access
118
117
Config : testAccComputeSubnetwork_update2 (cnName , "10.2.0.0/16" , subnetworkName ),
119
118
Check : resource .ComposeTestCheckFunc (
120
- testAccCheckComputeSubnetworkExists (
121
- t , "google_compute_subnetwork.network-with-private-google-access" , & subnetwork ),
119
+ testAccCheckComputeSubnetworkExists (t , "google_compute_subnetwork.network-with-private-google-access" , & subnetwork ),
122
120
),
123
121
},
124
122
{
125
123
// Shrink IP CIDR range and update private_ip_google_access
126
124
Config : testAccComputeSubnetwork_update2 (cnName , "10.2.0.0/24" , subnetworkName ),
127
125
Check : resource .ComposeTestCheckFunc (
128
- testAccCheckComputeSubnetworkExists (
129
- t , "google_compute_subnetwork.network-with-private-google-access" , & subnetwork ),
126
+ testAccCheckComputeSubnetworkExists (t , "google_compute_subnetwork.network-with-private-google-access" , & subnetwork ),
130
127
),
131
128
},
132
129
{
133
130
// Add a secondary range and enable flow logs at once
134
131
Config : testAccComputeSubnetwork_update3 (cnName , "10.2.0.0/24" , subnetworkName ),
135
132
Check : resource .ComposeTestCheckFunc (
136
- testAccCheckComputeSubnetworkExists (
137
- t , "google_compute_subnetwork.network-with-private-google-access" , & subnetwork ),
133
+ testAccCheckComputeSubnetworkExists (t , "google_compute_subnetwork.network-with-private-google-access" , & subnetwork ),
138
134
),
139
135
},
140
136
{
@@ -150,6 +146,49 @@ func TestAccComputeSubnetwork_update(t *testing.T) {
150
146
}
151
147
}
152
148
149
+ func TestAccComputeSubnetwork_purposeUpdate (t * testing.T ) {
150
+ t .Parallel ()
151
+
152
+ var subnetwork compute.Subnetwork
153
+ cnName := fmt .Sprintf ("tf-test-%s" , acctest .RandString (t , 10 ))
154
+ subnetworkName := fmt .Sprintf ("tf-test-%s" , acctest .RandString (t , 10 ))
155
+
156
+ acctest .VcrTest (t , resource.TestCase {
157
+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
158
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
159
+ CheckDestroy : testAccCheckComputeSubnetworkDestroyProducer (t ),
160
+ Steps : []resource.TestStep {
161
+ {
162
+ // Create a subnetwork with the purpose set to PEER_MIGRATION
163
+ Config : testAccComputeSubnetwork_purposeUpdate (cnName , subnetworkName ),
164
+ Check : resource .ComposeTestCheckFunc (
165
+ testAccCheckComputeSubnetworkExists (t , "google_compute_subnetwork.network-with-migration-purpose" , & subnetwork ),
166
+ ),
167
+ },
168
+ {
169
+ ResourceName : "google_compute_subnetwork.network-with-migration-purpose" ,
170
+ ImportState : true ,
171
+ ImportStateVerify : true ,
172
+ },
173
+ {
174
+ // update the purpose from PEER_MIGRATION to PRIVATE
175
+ Config : testAccComputeSubnetwork_purposeUpdate1 (cnName , subnetworkName ),
176
+ ConfigPlanChecks : resource.ConfigPlanChecks {
177
+ PreApply : []plancheck.PlanCheck {
178
+ plancheck .ExpectResourceAction ("google_compute_subnetwork.network-with-migration-purpose" , plancheck .ResourceActionUpdate ),
179
+ },
180
+ },
181
+ },
182
+ {
183
+ ResourceName : "google_compute_subnetwork.network-with-migration-purpose" ,
184
+ ImportState : true ,
185
+ ImportStateVerify : true ,
186
+ },
187
+ },
188
+ })
189
+
190
+ }
191
+
153
192
func TestAccComputeSubnetwork_secondaryIpRanges (t * testing.T ) {
154
193
t .Parallel ()
155
194
@@ -542,6 +581,7 @@ resource "google_compute_subnetwork" "network-with-private-google-access" {
542
581
network = google_compute_network.custom-test.self_link
543
582
private_ip_google_access = true
544
583
}
584
+
545
585
` , cnName , subnetwork1Name , subnetwork2Name , subnetwork3Name )
546
586
}
547
587
@@ -599,6 +639,42 @@ resource "google_compute_subnetwork" "network-with-private-google-access" {
599
639
` , cnName , subnetworkName , cidrRange )
600
640
}
601
641
642
+ // Create a subnetwork with its purpose set to PEER_MIGRATION
643
+ func testAccComputeSubnetwork_purposeUpdate (cnName , subnetworkName string ) string {
644
+ return fmt .Sprintf (`
645
+ resource "google_compute_network" "custom-test" {
646
+ name = "%s"
647
+ auto_create_subnetworks = false
648
+ }
649
+
650
+ resource "google_compute_subnetwork" "network-with-migration-purpose" {
651
+ name = "%s"
652
+ ip_cidr_range = "10.4.0.0/16"
653
+ region = "us-central1"
654
+ network = google_compute_network.custom-test.self_link
655
+ purpose = "PEER_MIGRATION"
656
+ }
657
+ ` , cnName , subnetworkName )
658
+ }
659
+
660
+ // Returns a subnetwork with its purpose set to PRIVATE
661
+ func testAccComputeSubnetwork_purposeUpdate1 (cnName , subnetworkName string ) string {
662
+ return fmt .Sprintf (`
663
+ resource "google_compute_network" "custom-test" {
664
+ name = "%s"
665
+ auto_create_subnetworks = false
666
+ }
667
+
668
+ resource "google_compute_subnetwork" "network-with-migration-purpose" {
669
+ name = "%s"
670
+ ip_cidr_range = "10.4.0.0/16"
671
+ region = "us-central1"
672
+ network = google_compute_network.custom-test.self_link
673
+ purpose = "PRIVATE"
674
+ }
675
+ ` , cnName , subnetworkName )
676
+ }
677
+
602
678
func testAccComputeSubnetwork_secondaryIpRanges_update1 (cnName , subnetworkName string ) string {
603
679
return fmt .Sprintf (`
604
680
resource "google_compute_network" "custom-test" {
0 commit comments