Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 83 additions & 7 deletions tencentcloud/resource_tc_elasticsearch_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,17 @@ resource "tencentcloud_elasticsearch_instance" "foo" {
node_info_list {
node_num = 2
node_type = "ES.S1.MEDIUM4"
encrypt = false
encrypt = false
}

es_acl {
black_list = [
"9.9.9.9",
"8.8.8.8",
]
white_list = [
"0.0.0.0",
]
}

tags = {
Expand Down Expand Up @@ -171,6 +181,33 @@ func resourceTencentCloudElasticsearchInstance() *schema.Resource {
},
},
},
"es_acl": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Description: "Kibana Access Control Configuration.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"black_list": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Description: "Blacklist of kibana access.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"white_list": {
Type: schema.TypeSet,
Optional: true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这种list类型的,读出来的顺序没有变化么

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里应该是无序的,我换成TypeSet

Computed: true,
Description: "Whitelist of kibana access.",
Elem: &schema.Schema{Type: schema.TypeString},
},
},
},
},
"license_type": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -385,7 +422,7 @@ func resourceTencentCloudElasticsearchInstanceCreate(d *schema.ResourceData, met
return retryError(errRet, InternalError)
}
if instance == nil || *instance.Status == ES_INSTANCE_STATUS_PROCESSING {
return resource.RetryableError(errors.New("elasticsearch instance status is processing, retry..."))
return resource.RetryableError(fmt.Errorf("elasticsearch instance status is processing, retry... status:%v", *instance.Status))
}
return nil
})
Expand Down Expand Up @@ -478,6 +515,16 @@ func resourceTencentCloudElasticsearchInstanceRead(d *schema.ResourceData, meta
}
_ = d.Set("node_info_list", nodeInfoList)

if instance.EsAcl != nil {
esAcls := make([]map[string]interface{}, 0, 1)
esAcl := map[string]interface{}{
"black_list": instance.EsAcl.BlackIpList,
"white_list": instance.EsAcl.WhiteIpList,
}
esAcls = append(esAcls, esAcl)
_ = d.Set("es_acl", esAcls)
}

if len(instance.TagList) > 0 {
tags := make(map[string]string)
for _, tag := range instance.TagList {
Expand Down Expand Up @@ -505,7 +552,7 @@ func resourceTencentCloudElasticsearchInstanceUpdate(d *schema.ResourceData, met
instanceName := d.Get("instance_name").(string)
// Update operation support at most one item at the same time
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
errRet := elasticsearchService.UpdateInstance(ctx, instanceId, instanceName, "", 0, nil, nil)
errRet := elasticsearchService.UpdateInstance(ctx, instanceId, instanceName, "", 0, nil, nil, nil)
if errRet != nil {
return retryError(errRet)
}
Expand All @@ -519,7 +566,7 @@ func resourceTencentCloudElasticsearchInstanceUpdate(d *schema.ResourceData, met
if d.HasChange("password") {
password := d.Get("password").(string)
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
errRet := elasticsearchService.UpdateInstance(ctx, instanceId, "", password, 0, nil, nil)
errRet := elasticsearchService.UpdateInstance(ctx, instanceId, "", password, 0, nil, nil, nil)
if errRet != nil {
return retryError(errRet)
}
Expand Down Expand Up @@ -592,7 +639,7 @@ func resourceTencentCloudElasticsearchInstanceUpdate(d *schema.ResourceData, met
if d.HasChange("basic_security_type") {
basicSecurityType := d.Get("basic_security_type").(int)
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
errRet := elasticsearchService.UpdateInstance(ctx, instanceId, "", "", int64(basicSecurityType), nil, nil)
errRet := elasticsearchService.UpdateInstance(ctx, instanceId, "", "", int64(basicSecurityType), nil, nil, nil)
if errRet != nil {
return retryError(errRet)
}
Expand All @@ -614,7 +661,7 @@ func resourceTencentCloudElasticsearchInstanceUpdate(d *schema.ResourceData, met
NodeType: helper.String(value["node_type"].(string)),
}
err = resource.Retry(writeRetryTimeout, func() *resource.RetryError {
errRet := elasticsearchService.UpdateInstance(ctx, instanceId, "", "", 0, nil, info)
errRet := elasticsearchService.UpdateInstance(ctx, instanceId, "", "", 0, nil, info, nil)
if errRet != nil {
return retryError(errRet)
}
Expand Down Expand Up @@ -649,7 +696,7 @@ func resourceTencentCloudElasticsearchInstanceUpdate(d *schema.ResourceData, met
nodeInfoList = append(nodeInfoList, &dataDisk)
}
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
errRet := elasticsearchService.UpdateInstance(ctx, instanceId, "", "", 0, nodeInfoList, nil)
errRet := elasticsearchService.UpdateInstance(ctx, instanceId, "", "", 0, nodeInfoList, nil, nil)
if errRet != nil {
return retryError(errRet)
}
Expand Down Expand Up @@ -687,6 +734,35 @@ func resourceTencentCloudElasticsearchInstanceUpdate(d *schema.ResourceData, met
}
d.SetPartial("tags")
}
if d.HasChange("es_acl") {
esAcl := es.EsAcl{}
if aclMap, ok := helper.InterfacesHeadMap(d, "es_acl"); ok {
if v, ok := aclMap["black_list"]; ok {
blist := v.(*schema.Set).List()
for _, d := range blist {
esAcl.BlackIpList = append(esAcl.BlackIpList, helper.String(d.(string)))
}
}
if v, ok := aclMap["white_list"]; ok {
wlist := v.(*schema.Set).List()
for _, d := range wlist {
esAcl.WhiteIpList = append(esAcl.WhiteIpList, helper.String(d.(string)))
}
}
}

err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
errRet := elasticsearchService.UpdateInstance(ctx, instanceId, "", "", 0, nil, nil, &esAcl)
if errRet != nil {
return retryError(errRet)
}
return nil
})
if err != nil {
return err
}
d.SetPartial("es_acl")
}

d.Partial(false)

Expand Down
12 changes: 12 additions & 0 deletions tencentcloud/resource_tc_elasticsearch_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ func TestAccTencentCloudNeedFixElasticsearchInstance_basic(t *testing.T) {
resource.TestCheckResourceAttr("tencentcloud_elasticsearch_instance.foo", "web_node_type_info.0.node_type", "ES.S1.MEDIUM8"),
resource.TestCheckResourceAttr("tencentcloud_elasticsearch_instance.foo", "node_info_list.0.node_type", "ES.S1.MEDIUM8"),
resource.TestCheckResourceAttr("tencentcloud_elasticsearch_instance.foo", "node_info_list.0.disk_size", "200"),
resource.TestCheckResourceAttr("tencentcloud_elasticsearch_instance.foo", "es_public_acl.#", "1"),
resource.TestCheckResourceAttr("tencentcloud_elasticsearch_instance.foo", "es_public_acl.0.white_list.#", "1"),
resource.TestCheckResourceAttr("tencentcloud_elasticsearch_instance.foo", "es_public_acl.0.black_list.#", "1"),
),
},
{
Expand Down Expand Up @@ -208,6 +211,15 @@ resource "tencentcloud_elasticsearch_instance" "foo" {
node_type = "ES.S1.MEDIUM8"
disk_size = 200
}

es_public_acl {
white_list {
"0.0.0.0"
}
black_list {
"1.1.1.1"
}
}

tags = {
test = "test"
Expand Down
5 changes: 4 additions & 1 deletion tencentcloud/service_tencentcloud_elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (me *ElasticsearchService) DeleteInstance(ctx context.Context, instanceId s
}

// UpdateInstance FIXME: use *Request instead of these suck params
func (me *ElasticsearchService) UpdateInstance(ctx context.Context, instanceId, instanceName, password string, basicSecurityType int64, nodeList []*es.NodeInfo, nodeTypeInfo *es.WebNodeTypeInfo) error {
func (me *ElasticsearchService) UpdateInstance(ctx context.Context, instanceId, instanceName, password string, basicSecurityType int64, nodeList []*es.NodeInfo, nodeTypeInfo *es.WebNodeTypeInfo, esAcl *es.EsAcl) error {
logId := getLogId(ctx)
request := es.NewUpdateInstanceRequest()
request.InstanceId = &instanceId
Expand All @@ -114,6 +114,9 @@ func (me *ElasticsearchService) UpdateInstance(ctx context.Context, instanceId,
if nodeTypeInfo != nil {
request.WebNodeTypeInfo = nodeTypeInfo
}
if esAcl != nil {
request.EsAcl = esAcl
}
ratelimit.Check(request.GetAction())
_, err := me.client.UseEsClient().UpdateInstance(request)
if err != nil {
Expand Down
16 changes: 16 additions & 0 deletions website/docs/r/elasticsearch_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ resource "tencentcloud_elasticsearch_instance" "foo" {
encrypt = false
}

es_acl {
black_list = [
"9.9.9.9",
"8.8.8.8",
]
white_list = [
"0.0.0.0",
]
}

tags = {
test = "test"
}
Expand All @@ -53,6 +63,7 @@ The following arguments are supported:
* `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`.
* `charge_type` - (Optional, String, ForceNew) The charge type of instance. Valid values are `PREPAID` and `POSTPAID_BY_HOUR`.
* `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`.
* `es_acl` - (Optional, List) Kibana Access Control Configuration.
* `instance_name` - (Optional, String) Name of the instance, which can contain 1 to 50 English letters, Chinese characters, digits, dashes(-), or underscores(_).
* `license_type` - (Optional, String) License type. Valid values are `oss`, `basic` and `platinum`. The default value is `platinum`.
* `multi_zone_infos` - (Optional, List, ForceNew) Details of AZs in multi-AZ deployment mode (which is required when deploy_mode is `1`).
Expand All @@ -61,6 +72,11 @@ The following arguments are supported:
* `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).
* `web_node_type_info` - (Optional, List) Visual node configuration.

The `es_acl` object supports the following:

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

The `multi_zone_infos` object supports the following:

* `availability_zone` - (Required, String) Availability zone.
Expand Down