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