@@ -1093,7 +1093,7 @@ func TestAccContainerCluster_withMaintenanceWindow(t *testing.T) {
1093
1093
})
1094
1094
}
1095
1095
1096
- func TestAccContainerCluster_withIPAllocationPolicy (t * testing.T ) {
1096
+ func TestAccContainerCluster_withIPAllocationPolicy_existingSecondaryRanges (t * testing.T ) {
1097
1097
t .Parallel ()
1098
1098
1099
1099
cluster := fmt .Sprintf ("cluster-test-%s" , acctest .RandString (10 ))
@@ -1103,53 +1103,79 @@ func TestAccContainerCluster_withIPAllocationPolicy(t *testing.T) {
1103
1103
CheckDestroy : testAccCheckContainerClusterDestroy ,
1104
1104
Steps : []resource.TestStep {
1105
1105
{
1106
- Config : testAccContainerCluster_withIPAllocationPolicy (
1107
- cluster ,
1108
- map [string ]string {
1109
- "pods" : "10.1.0.0/16" ,
1110
- "services" : "10.2.0.0/20" ,
1111
- },
1112
- map [string ]string {
1113
- "cluster_secondary_range_name" : "pods" ,
1114
- "services_secondary_range_name" : "services" ,
1115
- },
1116
- ),
1117
- Check : resource .ComposeTestCheckFunc (
1118
- resource .TestCheckResourceAttr ("google_container_cluster.with_ip_allocation_policy" ,
1119
- "ip_allocation_policy.0.cluster_secondary_range_name" , "pods" ),
1120
- resource .TestCheckResourceAttr ("google_container_cluster.with_ip_allocation_policy" ,
1121
- "ip_allocation_policy.0.services_secondary_range_name" , "services" ),
1122
- ),
1106
+ Config : testAccContainerCluster_withIPAllocationPolicy_existingSecondaryRanges (cluster ),
1123
1107
},
1124
1108
{
1125
1109
ResourceName : "google_container_cluster.with_ip_allocation_policy" ,
1126
1110
ImportStateIdPrefix : "us-central1-a/" ,
1127
1111
ImportState : true ,
1128
1112
ImportStateVerify : true ,
1129
1113
},
1114
+ },
1115
+ })
1116
+ }
1117
+
1118
+ func TestAccContainerCluster_withIPAllocationPolicy_specificIPRanges (t * testing.T ) {
1119
+ t .Parallel ()
1120
+
1121
+ cluster := fmt .Sprintf ("cluster-test-%s" , acctest .RandString (10 ))
1122
+ resource .Test (t , resource.TestCase {
1123
+ PreCheck : func () { testAccPreCheck (t ) },
1124
+ Providers : testAccProviders ,
1125
+ CheckDestroy : testAccCheckContainerClusterDestroy ,
1126
+ Steps : []resource.TestStep {
1127
+ {
1128
+ Config : testAccContainerCluster_withIPAllocationPolicy_specificIPRanges (cluster ),
1129
+ },
1130
1130
{
1131
- Config : testAccContainerCluster_withIPAllocationPolicy (
1132
- cluster ,
1133
- map [string ]string {
1134
- "pods" : "10.1.0.0/16" ,
1135
- "services" : "10.2.0.0/20" ,
1136
- },
1137
- map [string ]string {},
1138
- ),
1139
- ExpectError : regexp .MustCompile ("clusters using IP aliases must specify secondary ranges" ),
1140
- },
1141
- {
1142
- Config : testAccContainerCluster_withIPAllocationPolicy (
1143
- cluster ,
1144
- map [string ]string {
1145
- "pods" : "10.1.0.0/16" ,
1146
- },
1147
- map [string ]string {
1148
- "cluster_secondary_range_name" : "pods" ,
1149
- "services_secondary_range_name" : "services" ,
1150
- },
1151
- ),
1152
- ExpectError : regexp .MustCompile ("secondary range \" services\" does not exist in network" ),
1131
+ ResourceName : "google_container_cluster.with_ip_allocation_policy" ,
1132
+ ImportStateIdPrefix : "us-central1-a/" ,
1133
+ ImportState : true ,
1134
+ ImportStateVerify : true ,
1135
+ },
1136
+ },
1137
+ })
1138
+ }
1139
+
1140
+ func TestAccContainerCluster_withIPAllocationPolicy_specificSizes (t * testing.T ) {
1141
+ t .Parallel ()
1142
+
1143
+ cluster := fmt .Sprintf ("cluster-test-%s" , acctest .RandString (10 ))
1144
+ resource .Test (t , resource.TestCase {
1145
+ PreCheck : func () { testAccPreCheck (t ) },
1146
+ Providers : testAccProviders ,
1147
+ CheckDestroy : testAccCheckContainerClusterDestroy ,
1148
+ Steps : []resource.TestStep {
1149
+ {
1150
+ Config : testAccContainerCluster_withIPAllocationPolicy_specificSizes (cluster ),
1151
+ },
1152
+ {
1153
+ ResourceName : "google_container_cluster.with_ip_allocation_policy" ,
1154
+ ImportStateIdPrefix : "us-central1-a/" ,
1155
+ ImportState : true ,
1156
+ ImportStateVerify : true ,
1157
+ },
1158
+ },
1159
+ })
1160
+ }
1161
+
1162
+ func TestAccContainerCluster_withIPAllocationPolicy_createSubnetwork (t * testing.T ) {
1163
+ t .Parallel ()
1164
+
1165
+ cluster := fmt .Sprintf ("cluster-test-%s" , acctest .RandString (10 ))
1166
+ resource .Test (t , resource.TestCase {
1167
+ PreCheck : func () { testAccPreCheck (t ) },
1168
+ Providers : testAccProviders ,
1169
+ CheckDestroy : testAccCheckContainerClusterDestroy ,
1170
+ Steps : []resource.TestStep {
1171
+ {
1172
+ Config : testAccContainerCluster_withIPAllocationPolicy_createSubnetwork (cluster ),
1173
+ },
1174
+ {
1175
+ ResourceName : "google_container_cluster.with_ip_allocation_policy" ,
1176
+ ImportStateIdPrefix : "us-central1-a/" ,
1177
+ ImportState : true ,
1178
+ ImportStateVerify : true ,
1153
1179
},
1154
1180
},
1155
1181
})
@@ -2233,23 +2259,59 @@ resource "google_container_cluster" "with_maintenance_window" {
2233
2259
}` , clusterName , maintenancePolicy )
2234
2260
}
2235
2261
2236
- func testAccContainerCluster_withIPAllocationPolicy (cluster string , ranges , policy map [string ]string ) string {
2262
+ func testAccContainerCluster_withIPAllocationPolicy_existingSecondaryRanges (cluster string ) string {
2263
+ return fmt .Sprintf (`
2264
+ resource "google_compute_network" "container_network" {
2265
+ name = "container-net-%s"
2266
+ auto_create_subnetworks = false
2267
+ }
2237
2268
2238
- var secondaryRanges bytes.Buffer
2239
- for rangeName , cidr := range ranges {
2240
- secondaryRanges .WriteString (fmt .Sprintf (`
2269
+ resource "google_compute_subnetwork" "container_subnetwork" {
2270
+ name = "${google_compute_network.container_network.name}"
2271
+ network = "${google_compute_network.container_network.name}"
2272
+ ip_cidr_range = "10.0.0.0/24"
2273
+ region = "us-central1"
2274
+
2275
+ secondary_ip_range {
2276
+ range_name = "pods"
2277
+ ip_cidr_range = "10.1.0.0/16"
2278
+ }
2241
2279
secondary_ip_range {
2242
- range_name = "%s"
2243
- ip_cidr_range = "%s"
2244
- }` , rangeName , cidr ))
2280
+ range_name = "services"
2281
+ ip_cidr_range = "10.2.0.0/20"
2282
+ }
2283
+ }
2284
+
2285
+ resource "google_container_cluster" "with_ip_allocation_policy" {
2286
+ name = "%s"
2287
+ zone = "us-central1-a"
2288
+
2289
+ network = "${google_compute_network.container_network.name}"
2290
+ subnetwork = "${google_compute_subnetwork.container_subnetwork.name}"
2291
+
2292
+ initial_node_count = 1
2293
+ ip_allocation_policy {
2294
+ cluster_secondary_range_name = "pods"
2295
+ services_secondary_range_name = "services"
2245
2296
}
2297
+ }` , cluster , cluster )
2298
+ }
2246
2299
2247
- var ipAllocationPolicy bytes.Buffer
2248
- for key , value := range policy {
2249
- ipAllocationPolicy .WriteString (fmt .Sprintf (`
2250
- %s = "%s"` , key , value ))
2300
+ func testAccContainerCluster_withIPAllocationPolicy_specificIPRanges (cluster string ) string {
2301
+ return fmt .Sprintf (`
2302
+ resource "google_container_cluster" "with_ip_allocation_policy" {
2303
+ name = "%s"
2304
+ zone = "us-central1-a"
2305
+
2306
+ initial_node_count = 1
2307
+ ip_allocation_policy {
2308
+ cluster_ipv4_cidr_block = "10.90.0.0/19"
2309
+ services_ipv4_cidr_block = "10.40.0.0/19"
2251
2310
}
2311
+ }` , cluster )
2312
+ }
2252
2313
2314
+ func testAccContainerCluster_withIPAllocationPolicy_specificSizes (cluster string ) string {
2253
2315
return fmt .Sprintf (`
2254
2316
resource "google_compute_network" "container_network" {
2255
2317
name = "container-net-%s"
@@ -2261,8 +2323,6 @@ resource "google_compute_subnetwork" "container_subnetwork" {
2261
2323
network = "${google_compute_network.container_network.name}"
2262
2324
ip_cidr_range = "10.0.0.0/24"
2263
2325
region = "us-central1"
2264
-
2265
- %s
2266
2326
}
2267
2327
2268
2328
resource "google_container_cluster" "with_ip_allocation_policy" {
@@ -2274,9 +2334,23 @@ resource "google_container_cluster" "with_ip_allocation_policy" {
2274
2334
2275
2335
initial_node_count = 1
2276
2336
ip_allocation_policy {
2277
- %s
2337
+ cluster_ipv4_cidr_block = "/16"
2338
+ services_ipv4_cidr_block = "/22"
2339
+ }
2340
+ }` , cluster , cluster )
2341
+ }
2342
+
2343
+ func testAccContainerCluster_withIPAllocationPolicy_createSubnetwork (cluster string ) string {
2344
+ return fmt .Sprintf (`
2345
+ resource "google_container_cluster" "with_ip_allocation_policy" {
2346
+ name = "%s"
2347
+ zone = "us-central1-a"
2348
+
2349
+ initial_node_count = 1
2350
+ ip_allocation_policy {
2351
+ create_subnetwork = true
2278
2352
}
2279
- }` , acctest . RandString ( 10 ), secondaryRanges . String (), cluster , ipAllocationPolicy . String () )
2353
+ }` , cluster )
2280
2354
}
2281
2355
2282
2356
func testAccContainerCluster_withPodSecurityPolicy (clusterName string , enabled bool ) string {
0 commit comments