@@ -12,6 +12,7 @@ import (
1212 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1313 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1414 elasticsearch "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/es/v20180416"
15+ es "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/es/v20180416"
1516
1617 "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
1718)
@@ -35,7 +36,7 @@ func ResourceTencentCloudElasticsearchLogstash() *schema.Resource {
3536 "zone" : {
3637 Required : true ,
3738 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. " ,
3940 },
4041
4142 "logstash_version" : {
@@ -53,7 +54,7 @@ func ResourceTencentCloudElasticsearchLogstash() *schema.Resource {
5354 "subnet_id" : {
5455 Required : true ,
5556 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. " ,
5758 },
5859
5960 "node_num" : {
@@ -172,6 +173,39 @@ func ResourceTencentCloudElasticsearchLogstash() *schema.Resource {
172173 },
173174 },
174175 },
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+ },
175209 },
176210 }
177211}
@@ -277,6 +311,30 @@ func resourceTencentCloudElasticsearchLogstashCreate(d *schema.ResourceData, met
277311 request .OperationDuration = & operationDuration
278312 }
279313
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+
280338 err := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
281339 result , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseEsClient ().CreateLogstashInstance (request )
282340 if e != nil {
@@ -341,10 +399,6 @@ func resourceTencentCloudElasticsearchLogstashRead(d *schema.ResourceData, meta
341399 _ = d .Set ("instance_name" , logstash .InstanceName )
342400 }
343401
344- if logstash .Zone != nil {
345- _ = d .Set ("zone" , logstash .Zone )
346- }
347-
348402 if logstash .LogstashVersion != nil {
349403 _ = d .Set ("logstash_version" , logstash .LogstashVersion )
350404 }
@@ -418,7 +472,27 @@ func resourceTencentCloudElasticsearchLogstashRead(d *schema.ResourceData, meta
418472
419473 _ = d .Set ("operation_duration" , []interface {}{operationDurationMap })
420474 }
475+ if logstash .DeployMode != nil {
476+ _ = d .Set ("deploy_mode" , logstash .DeployMode )
477+ }
421478
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+ }
422496 return nil
423497}
424498
@@ -446,7 +520,7 @@ func resourceTencentCloudElasticsearchLogstashUpdate(d *schema.ResourceData, met
446520
447521 request .InstanceId = & instanceId
448522
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" }
450524
451525 for _ , v := range immutableArgs {
452526 if d .HasChange (v ) {
0 commit comments