Skip to content

Commit 905c7b9

Browse files
authored
feat(es): [119594704] tencentcloud_elasticsearch_instance support cos_backup (#2822)
* add * add
1 parent 3fda001 commit 905c7b9

File tree

5 files changed

+132
-9
lines changed

5 files changed

+132
-9
lines changed

.changelog/2822.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_elasticsearch_instance: support `cos_backup`
3+
```

tencentcloud/services/es/resource_tc_elasticsearch_instance.go

Lines changed: 109 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,26 @@ func ResourceTencentCloudElasticsearchInstance() *schema.Resource {
242242
ValidateFunc: tccommon.ValidateAllowedStringValue(ES_KIBANA_PUBLIC_ACCESS),
243243
Description: "Kibana public network access status. Valid values are `OPEN` and `CLOSE`.",
244244
},
245+
"cos_backup": {
246+
Type: schema.TypeList,
247+
Optional: true,
248+
MaxItems: 1,
249+
Description: "COS automatic backup information.",
250+
Elem: &schema.Resource{
251+
Schema: map[string]*schema.Schema{
252+
"is_auto_backup": {
253+
Type: schema.TypeBool,
254+
Required: true,
255+
Description: "Whether to enable automatic backup of cos.",
256+
},
257+
"backup_time": {
258+
Type: schema.TypeString,
259+
Required: true,
260+
Description: "Automatic backup execution time (accurate to the hour), e.g. `22:00`.",
261+
},
262+
},
263+
},
264+
},
245265
// computed
246266
"elasticsearch_domain": {
247267
Type: schema.TypeString,
@@ -446,7 +466,7 @@ func resourceTencentCloudElasticsearchInstanceCreate(d *schema.ResourceData, met
446466
}
447467
if isUpdate {
448468
err = resource.Retry(tccommon.WriteRetryTimeout*2, func() *resource.RetryError {
449-
errRet := elasticsearchService.UpdateInstance(ctx, instanceId, "", "", kibanaPublicAccess, 0, nil, nil, &esAcl)
469+
errRet := elasticsearchService.UpdateInstance(ctx, instanceId, "", "", kibanaPublicAccess, 0, nil, nil, &esAcl, nil)
450470
if errRet != nil {
451471
return tccommon.RetryError(errRet)
452472
}
@@ -462,6 +482,38 @@ func resourceTencentCloudElasticsearchInstanceCreate(d *schema.ResourceData, met
462482
}
463483
}
464484

485+
if v, ok := d.GetOk("cos_backup"); ok {
486+
cosBackup := es.CosBackup{}
487+
for _, item := range v.([]interface{}) {
488+
value := item.(map[string]interface{})
489+
if v, ok := value["is_auto_backup"]; ok {
490+
cosBackup.IsAutoBackup = helper.Bool(v.(bool))
491+
}
492+
493+
if v, ok := value["backup_time"]; ok && v.(string) != "" {
494+
cosBackup.BackupTime = helper.String(v.(string))
495+
}
496+
}
497+
498+
err = resource.Retry(tccommon.WriteRetryTimeout*2, func() *resource.RetryError {
499+
errRet := elasticsearchService.UpdateInstance(ctx, instanceId, "", "", "", 0, nil, nil, nil, &cosBackup)
500+
if errRet != nil {
501+
return tccommon.RetryError(errRet)
502+
}
503+
504+
return nil
505+
})
506+
507+
if err != nil {
508+
return err
509+
}
510+
511+
err = tencentCloudElasticsearchInstanceUpgradeWaiting(ctx, &elasticsearchService, instanceId)
512+
if err != nil {
513+
return err
514+
}
515+
}
516+
465517
// tags
466518
if tags := helper.GetTags(d, "tags"); len(tags) > 0 {
467519
client := meta.(tccommon.ProviderMeta).GetAPIV3Conn()
@@ -568,6 +620,21 @@ func resourceTencentCloudElasticsearchInstanceRead(d *schema.ResourceData, meta
568620
_ = d.Set("es_acl", esAcls)
569621
}
570622

623+
if instance.CosBackup != nil {
624+
cosBackupList := make([]map[string]interface{}, 0, 1)
625+
cosBackupMap := map[string]interface{}{}
626+
if instance.CosBackup.IsAutoBackup != nil {
627+
cosBackupMap["is_auto_backup"] = instance.CosBackup.IsAutoBackup
628+
}
629+
630+
if instance.CosBackup.BackupTime != nil {
631+
cosBackupMap["backup_time"] = instance.CosBackup.BackupTime
632+
}
633+
634+
cosBackupList = append(cosBackupList, cosBackupMap)
635+
_ = d.Set("cos_backup", cosBackupList)
636+
}
637+
571638
if len(instance.TagList) > 0 {
572639
tags := make(map[string]string)
573640
for _, tag := range instance.TagList {
@@ -595,7 +662,7 @@ func resourceTencentCloudElasticsearchInstanceUpdate(d *schema.ResourceData, met
595662
instanceName := d.Get("instance_name").(string)
596663
// Update operation support at most one item at the same time
597664
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
598-
errRet := elasticsearchService.UpdateInstance(ctx, instanceId, instanceName, "", "", 0, nil, nil, nil)
665+
errRet := elasticsearchService.UpdateInstance(ctx, instanceId, instanceName, "", "", 0, nil, nil, nil, nil)
599666
if errRet != nil {
600667
return tccommon.RetryError(errRet)
601668
}
@@ -612,7 +679,7 @@ func resourceTencentCloudElasticsearchInstanceUpdate(d *schema.ResourceData, met
612679
if d.HasChange("password") {
613680
password := d.Get("password").(string)
614681
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
615-
errRet := elasticsearchService.UpdateInstance(ctx, instanceId, "", password, "", 0, nil, nil, nil)
682+
errRet := elasticsearchService.UpdateInstance(ctx, instanceId, "", password, "", 0, nil, nil, nil, nil)
616683
if errRet != nil {
617684
return tccommon.RetryError(errRet)
618685
}
@@ -631,7 +698,7 @@ func resourceTencentCloudElasticsearchInstanceUpdate(d *schema.ResourceData, met
631698
if d.HasChange("kibana_public_access") {
632699
if v, ok := d.GetOk("kibana_public_access"); ok {
633700
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
634-
errRet := elasticsearchService.UpdateInstance(ctx, instanceId, "", "", v.(string), 0, nil, nil, nil)
701+
errRet := elasticsearchService.UpdateInstance(ctx, instanceId, "", "", v.(string), 0, nil, nil, nil, nil)
635702
if errRet != nil {
636703
return tccommon.RetryError(errRet)
637704
}
@@ -690,7 +757,7 @@ func resourceTencentCloudElasticsearchInstanceUpdate(d *schema.ResourceData, met
690757
licenseType := d.Get("license_type").(string)
691758
licenseTypeUpgrading := licenseType != "oss"
692759
err := resource.Retry(tccommon.WriteRetryTimeout*2, func() *resource.RetryError {
693-
errRet := elasticsearchService.UpdateInstance(ctx, instanceId, "", "", "", int64(basicSecurityType), nil, nil, nil)
760+
errRet := elasticsearchService.UpdateInstance(ctx, instanceId, "", "", "", int64(basicSecurityType), nil, nil, nil, nil)
694761
if errRet != nil {
695762
err := errRet.(*sdkErrors.TencentCloudSDKError)
696763
if err.Code == es.INVALIDPARAMETER && licenseTypeUpgrading {
@@ -721,7 +788,7 @@ func resourceTencentCloudElasticsearchInstanceUpdate(d *schema.ResourceData, met
721788
NodeType: helper.String(value["node_type"].(string)),
722789
}
723790
err = resource.Retry(tccommon.WriteRetryTimeout*2, func() *resource.RetryError {
724-
errRet := elasticsearchService.UpdateInstance(ctx, instanceId, "", "", "", 0, nil, info, nil)
791+
errRet := elasticsearchService.UpdateInstance(ctx, instanceId, "", "", "", 0, nil, info, nil, nil)
725792
if errRet != nil {
726793
return tccommon.RetryError(errRet)
727794
}
@@ -760,7 +827,7 @@ func resourceTencentCloudElasticsearchInstanceUpdate(d *schema.ResourceData, met
760827
nodeInfoList = append(nodeInfoList, &dataDisk)
761828
}
762829
err := resource.Retry(tccommon.WriteRetryTimeout*2, func() *resource.RetryError {
763-
errRet := elasticsearchService.UpdateInstance(ctx, instanceId, "", "", "", 0, nodeInfoList, nil, nil)
830+
errRet := elasticsearchService.UpdateInstance(ctx, instanceId, "", "", "", 0, nodeInfoList, nil, nil, nil)
764831
if errRet != nil {
765832
return tccommon.RetryError(errRet)
766833
}
@@ -811,7 +878,7 @@ func resourceTencentCloudElasticsearchInstanceUpdate(d *schema.ResourceData, met
811878
}
812879

813880
err := resource.Retry(tccommon.WriteRetryTimeout*2, func() *resource.RetryError {
814-
errRet := elasticsearchService.UpdateInstance(ctx, instanceId, "", "", "", 0, nil, nil, &esAcl)
881+
errRet := elasticsearchService.UpdateInstance(ctx, instanceId, "", "", "", 0, nil, nil, &esAcl, nil)
815882
if errRet != nil {
816883
return tccommon.RetryError(errRet)
817884
}
@@ -826,6 +893,40 @@ func resourceTencentCloudElasticsearchInstanceUpdate(d *schema.ResourceData, met
826893
}
827894
}
828895

896+
if d.HasChange("cos_backup") {
897+
if v, ok := d.GetOk("cos_backup"); ok {
898+
cosBackup := es.CosBackup{}
899+
for _, item := range v.([]interface{}) {
900+
value := item.(map[string]interface{})
901+
if v, ok := value["is_auto_backup"]; ok {
902+
cosBackup.IsAutoBackup = helper.Bool(v.(bool))
903+
}
904+
905+
if v, ok := value["backup_time"]; ok && v.(string) != "" {
906+
cosBackup.BackupTime = helper.String(v.(string))
907+
}
908+
}
909+
910+
err := resource.Retry(tccommon.WriteRetryTimeout*2, func() *resource.RetryError {
911+
errRet := elasticsearchService.UpdateInstance(ctx, instanceId, "", "", "", 0, nil, nil, nil, &cosBackup)
912+
if errRet != nil {
913+
return tccommon.RetryError(errRet)
914+
}
915+
916+
return nil
917+
})
918+
919+
if err != nil {
920+
return err
921+
}
922+
923+
err = tencentCloudElasticsearchInstanceUpgradeWaiting(ctx, &elasticsearchService, instanceId)
924+
if err != nil {
925+
return err
926+
}
927+
}
928+
}
929+
829930
d.Partial(false)
830931

831932
return resourceTencentCloudElasticsearchInstanceRead(d, meta)

tencentcloud/services/es/resource_tc_elasticsearch_instance.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ resource "tencentcloud_elasticsearch_instance" "example" {
5252
]
5353
}
5454
55+
cos_backup {
56+
is_auto_backup = true
57+
backup_time = "22:00"
58+
}
59+
5560
tags = {
5661
test = "test"
5762
}

tencentcloud/services/es/service_tencentcloud_elasticsearch.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (me *ElasticsearchService) DeleteInstance(ctx context.Context, instanceId s
107107
}
108108

109109
// UpdateInstance FIXME: use *Request instead of these suck params
110-
func (me *ElasticsearchService) UpdateInstance(ctx context.Context, instanceId, instanceName, password, kibanaPublicAccess string, basicSecurityType int64, nodeList []*es.NodeInfo, nodeTypeInfo *es.WebNodeTypeInfo, esAcl *es.EsAcl) error {
110+
func (me *ElasticsearchService) UpdateInstance(ctx context.Context, instanceId, instanceName, password, kibanaPublicAccess string, basicSecurityType int64, nodeList []*es.NodeInfo, nodeTypeInfo *es.WebNodeTypeInfo, esAcl *es.EsAcl, cosBackup *es.CosBackup) error {
111111
logId := tccommon.GetLogId(ctx)
112112
request := es.NewUpdateInstanceRequest()
113113
request.InstanceId = &instanceId
@@ -132,6 +132,9 @@ func (me *ElasticsearchService) UpdateInstance(ctx context.Context, instanceId,
132132
if esAcl != nil {
133133
request.EsAcl = esAcl
134134
}
135+
if cosBackup != nil {
136+
request.CosBackup = cosBackup
137+
}
135138
ratelimit.Check(request.GetAction())
136139
_, err := me.client.UseEsClient().UpdateInstance(request)
137140
if err != nil {

website/docs/r/elasticsearch_instance.html.markdown

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ resource "tencentcloud_elasticsearch_instance" "example" {
6363
]
6464
}
6565
66+
cos_backup {
67+
is_auto_backup = true
68+
backup_time = "22:00"
69+
}
70+
6671
tags = {
6772
test = "test"
6873
}
@@ -163,6 +168,7 @@ The following arguments are supported:
163168
* `basic_security_type` - (Optional, Int) Whether to enable X-Pack security authentication in Basic Edition 6.8 and above. Valid values are `1` and `2`. `1` is disabled, `2` is enabled, and default value is `1`. Notice: this parameter is only take effect on `basic` license.
164169
* `charge_period` - (Optional, Int, ForceNew) The tenancy of the prepaid instance, and uint is month. NOTE: it only works when charge_type is set to `PREPAID`.
165170
* `charge_type` - (Optional, String, ForceNew) The charge type of instance. Valid values are `PREPAID` and `POSTPAID_BY_HOUR`.
171+
* `cos_backup` - (Optional, List) COS automatic backup information.
166172
* `deploy_mode` - (Optional, Int, ForceNew) Cluster deployment mode. Valid values are `0` and `1`. `0` is single-AZ deployment, and `1` is multi-AZ deployment. Default value is `0`.
167173
* `es_acl` - (Optional, List) Kibana Access Control Configuration.
168174
* `instance_name` - (Optional, String) Name of the instance, which can contain 1 to 50 English letters, Chinese characters, digits, dashes(-), or underscores(_).
@@ -174,6 +180,11 @@ The following arguments are supported:
174180
* `tags` - (Optional, Map) A mapping of tags to assign to the instance. For tag limits, please refer to [Use Limits](https://intl.cloud.tencent.com/document/product/651/13354).
175181
* `web_node_type_info` - (Optional, List) Visual node configuration.
176182

183+
The `cos_backup` object supports the following:
184+
185+
* `backup_time` - (Required, String) Automatic backup execution time (accurate to the hour), e.g. `22:00`.
186+
* `is_auto_backup` - (Required, Bool) Whether to enable automatic backup of cos.
187+
177188
The `es_acl` object supports the following:
178189

179190
* `black_list` - (Optional, Set) Blacklist of kibana access.

0 commit comments

Comments
 (0)