@@ -12,6 +12,7 @@ import (
12
12
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
13
13
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
14
14
elasticsearch "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/es/v20180416"
15
+ es "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/es/v20180416"
15
16
16
17
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
17
18
)
@@ -35,7 +36,7 @@ func ResourceTencentCloudElasticsearchLogstash() *schema.Resource {
35
36
"zone" : {
36
37
Required : true ,
37
38
Type : schema .TypeString ,
38
- Description : "Available zone." ,
39
+ Description : "Available zone. Create multi zone instance, parameter zone need input '-', details input to multi_zone_infos. " ,
39
40
},
40
41
41
42
"logstash_version" : {
@@ -53,7 +54,7 @@ func ResourceTencentCloudElasticsearchLogstash() *schema.Resource {
53
54
"subnet_id" : {
54
55
Required : true ,
55
56
Type : schema .TypeString ,
56
- Description : "Subnet id." ,
57
+ Description : "Subnet id. Create multi zone instance, parameter subnet_id need input '-', details input to multi_zone_infos. " ,
57
58
},
58
59
59
60
"node_num" : {
@@ -172,6 +173,39 @@ func ResourceTencentCloudElasticsearchLogstash() *schema.Resource {
172
173
},
173
174
},
174
175
},
176
+ "deploy_mode" : {
177
+ Type : schema .TypeInt ,
178
+ Optional : true ,
179
+ Default : ES_DEPLOY_MODE_SINGLE_REGION ,
180
+ ValidateFunc : tccommon .ValidateAllowedIntValue (ES_DEPLOY_MODE ),
181
+ Description : "Deployment mode, 0: single availability zone, 1: multiple availability zones." ,
182
+ },
183
+ "multi_zone_infos" : {
184
+ Type : schema .TypeList ,
185
+ Optional : true ,
186
+ Computed : true ,
187
+ Description : "Details of availability zones when deploying multiple availability zones." ,
188
+ Elem : & schema.Resource {
189
+ Schema : map [string ]* schema.Schema {
190
+ "availability_zone" : {
191
+ Type : schema .TypeString ,
192
+ Required : true ,
193
+ Description : "Availability zone." ,
194
+ },
195
+ "subnet_id" : {
196
+ Type : schema .TypeString ,
197
+ Required : true ,
198
+ Description : "Subnet id." ,
199
+ },
200
+ "hidden" : {
201
+ Type : schema .TypeBool ,
202
+ Optional : true ,
203
+ Computed : true ,
204
+ Description : "Whether it is a hidden availability zone." ,
205
+ },
206
+ },
207
+ },
208
+ },
175
209
},
176
210
}
177
211
}
@@ -277,6 +311,30 @@ func resourceTencentCloudElasticsearchLogstashCreate(d *schema.ResourceData, met
277
311
request .OperationDuration = & operationDuration
278
312
}
279
313
314
+ if v , ok := d .GetOk ("deploy_mode" ); ok {
315
+ deployMode := v .(int )
316
+ request .DeployMode = helper .IntUint64 (deployMode )
317
+ if deployMode == ES_DEPLOY_MODE_MULTI_REGION {
318
+ if v , ok := d .GetOk ("multi_zone_infos" ); ok {
319
+ infos := v .([]interface {})
320
+ request .MultiZoneInfo = make ([]* es.ZoneDetail , 0 , len (infos ))
321
+ for _ , item := range infos {
322
+ value := item .(map [string ]interface {})
323
+ info := es.ZoneDetail {
324
+ Zone : helper .String (value ["availability_zone" ].(string )),
325
+ SubnetId : helper .String (value ["subnet_id" ].(string )),
326
+ }
327
+ if v , ok := value ["hidden" ].(bool ); ok {
328
+ info .Hidden = helper .Bool (v )
329
+ }
330
+ request .MultiZoneInfo = append (request .MultiZoneInfo , & info )
331
+ }
332
+ } else {
333
+ return fmt .Errorf ("elasticsearch multi_zone_infos can not be empty when deploy mode is %d" , deployMode )
334
+ }
335
+ }
336
+ }
337
+
280
338
err := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
281
339
result , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseEsClient ().CreateLogstashInstance (request )
282
340
if e != nil {
@@ -341,10 +399,6 @@ func resourceTencentCloudElasticsearchLogstashRead(d *schema.ResourceData, meta
341
399
_ = d .Set ("instance_name" , logstash .InstanceName )
342
400
}
343
401
344
- if logstash .Zone != nil {
345
- _ = d .Set ("zone" , logstash .Zone )
346
- }
347
-
348
402
if logstash .LogstashVersion != nil {
349
403
_ = d .Set ("logstash_version" , logstash .LogstashVersion )
350
404
}
@@ -418,7 +472,27 @@ func resourceTencentCloudElasticsearchLogstashRead(d *schema.ResourceData, meta
418
472
419
473
_ = d .Set ("operation_duration" , []interface {}{operationDurationMap })
420
474
}
475
+ if logstash .DeployMode != nil {
476
+ _ = d .Set ("deploy_mode" , logstash .DeployMode )
477
+ }
421
478
479
+ multiZoneInfos := make ([]map [string ]interface {}, 0 , len (logstash .MultiZoneInfo ))
480
+ for _ , item := range logstash .MultiZoneInfo {
481
+ info := make (map [string ]interface {}, 2 )
482
+ info ["availability_zone" ] = item .Zone
483
+ info ["subnet_id" ] = item .SubnetId
484
+ info ["hidden" ] = item .Hidden
485
+ multiZoneInfos = append (multiZoneInfos , info )
486
+ }
487
+ _ = d .Set ("multi_zone_infos" , multiZoneInfos )
488
+
489
+ if len (multiZoneInfos ) > 0 {
490
+ _ = d .Set ("zone" , "-" )
491
+ } else {
492
+ if logstash .Zone != nil {
493
+ _ = d .Set ("zone" , logstash .Zone )
494
+ }
495
+ }
422
496
return nil
423
497
}
424
498
@@ -446,7 +520,7 @@ func resourceTencentCloudElasticsearchLogstashUpdate(d *schema.ResourceData, met
446
520
447
521
request .InstanceId = & instanceId
448
522
449
- immutableArgs := []string {"zone" , "logstash_version" , "vpc_id" , "subnet_id" , "charge_type" , "charge_period" , "time_unit" , "auto_voucher" , "voucher_ids" , "renew_flag" , "disk_type" , "license_type" }
523
+ immutableArgs := []string {"zone" , "logstash_version" , "vpc_id" , "subnet_id" , "charge_type" , "charge_period" , "time_unit" , "auto_voucher" , "voucher_ids" , "renew_flag" , "disk_type" , "license_type" , "deploy_mode" , "multi_zone_infos" }
450
524
451
525
for _ , v := range immutableArgs {
452
526
if d .HasChange (v ) {
0 commit comments