@@ -16,7 +16,6 @@ import (
16
16
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
17
17
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
18
18
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
19
- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
20
19
21
20
"github.com/chnsz/golangsdk"
22
21
@@ -54,7 +53,7 @@ func ResourceAccelerator() *schema.Resource {
54
53
},
55
54
"ip_sets" : {
56
55
Type : schema .TypeList ,
57
- MaxItems : 1 ,
56
+ MaxItems : 2 ,
58
57
Elem : AcceleratorAccelerateIpSchema (),
59
58
Required : true ,
60
59
ForceNew : true ,
@@ -123,19 +122,13 @@ func AcceleratorAccelerateIpSchema() *schema.Resource {
123
122
Specifies the acceleration area. The value can be one of the following:
124
123
- **OUTOFCM**: Outside the Chinese mainland
125
124
- **CM**: Chinese mainland` ,
126
- ValidateFunc : validation .StringInSlice ([]string {
127
- "OUTOFCM" , "CM" ,
128
- }, false ),
129
125
},
130
126
"ip_type" : {
131
127
Type : schema .TypeString ,
132
128
Optional : true ,
133
129
ForceNew : true ,
134
130
Default : "IPV4" ,
135
131
Description : `Specifies the IP address version.` ,
136
- ValidateFunc : validation .StringInSlice ([]string {
137
- "IPV4" ,
138
- }, false ),
139
132
},
140
133
"ip_address" : {
141
134
Type : schema .TypeString ,
@@ -251,14 +244,18 @@ func buildCreateAcceleratorIpSetsChildBody(d *schema.ResourceData) []map[string]
251
244
return nil
252
245
}
253
246
254
- raw := rawParams [0 ].(map [string ]interface {})
255
- params := map [string ]interface {}{
256
- "area" : utils .ValueIgnoreEmpty (raw ["area" ]),
257
- "ip_address" : utils .ValueIgnoreEmpty (raw ["ip_address" ]),
258
- "ip_type" : utils .ValueIgnoreEmpty (raw ["ip_type" ]),
247
+ ipSets := make ([]map [string ]interface {}, len (rawParams ))
248
+ for _ , v := range rawParams {
249
+ raw := v .(map [string ]interface {})
250
+ params := map [string ]interface {}{
251
+ "area" : utils .ValueIgnoreEmpty (raw ["area" ]),
252
+ "ip_address" : utils .ValueIgnoreEmpty (raw ["ip_address" ]),
253
+ "ip_type" : utils .ValueIgnoreEmpty (raw ["ip_type" ]),
254
+ }
255
+ ipSets = append (ipSets , params )
259
256
}
260
257
261
- return [] map [ string ] interface {}{ params }
258
+ return ipSets
262
259
}
263
260
264
261
func createAcceleratorWaitingForStateCompleted (ctx context.Context , d * schema.ResourceData , meta interface {}, t time.Duration ) error {
@@ -347,7 +344,7 @@ func resourceAcceleratorRead(_ context.Context, d *schema.ResourceData, meta int
347
344
mErr ,
348
345
d .Set ("name" , utils .PathSearch ("accelerator.name" , respBody , nil )),
349
346
d .Set ("description" , utils .PathSearch ("accelerator.description" , respBody , nil )),
350
- d .Set ("ip_sets" , flattenGetAcceleratorResponseBodyAccelerateIp ( respBody )),
347
+ d .Set ("ip_sets" , flattenAccelerateIpSets ( utils . PathSearch ( "accelerator.ip_sets" , respBody , make ([] interface {}, 0 )) )),
351
348
d .Set ("enterprise_project_id" , utils .PathSearch ("accelerator.enterprise_project_id" , respBody , nil )),
352
349
d .Set ("tags" , flattenGetAcceleratorResponseBodyResourceTag (respBody )),
353
350
d .Set ("status" , utils .PathSearch ("accelerator.status" , respBody , nil )),
@@ -360,20 +357,22 @@ func resourceAcceleratorRead(_ context.Context, d *schema.ResourceData, meta int
360
357
return diag .FromErr (mErr .ErrorOrNil ())
361
358
}
362
359
363
- func flattenGetAcceleratorResponseBodyAccelerateIp (resp interface {}) []interface {} {
364
- var rst []interface {}
365
- curArray := utils .PathSearch ("accelerator.ip_sets" , resp , make ([]interface {}, 0 )).([]interface {})
366
- if len (curArray ) < 1 {
360
+ func flattenAccelerateIpSets (resp interface {}) []map [string ]interface {} {
361
+ rawArray , _ := resp .([]interface {})
362
+ if len (rawArray ) == 0 {
367
363
return nil
368
364
}
369
365
370
- rst = []interface {}{
371
- map [string ]interface {}{
372
- "area" : utils .PathSearch ("area" , curArray [0 ], nil ),
373
- "ip_address" : utils .PathSearch ("ip_address" , curArray [0 ], nil ),
374
- "ip_type" : utils .PathSearch ("ip_type" , curArray [0 ], nil ),
375
- },
366
+ rst := make ([]map [string ]interface {}, len (rawArray ))
367
+ for i , v := range rawArray {
368
+ params := map [string ]interface {}{
369
+ "area" : utils .PathSearch ("area" , v , nil ),
370
+ "ip_address" : utils .PathSearch ("ip_address" , v , nil ),
371
+ "ip_type" : utils .PathSearch ("ip_type" , v , nil ),
372
+ }
373
+ rst [i ] = params
376
374
}
375
+
377
376
return rst
378
377
}
379
378
0 commit comments