Skip to content

Commit

Permalink
kibana私网配置只在实例创建完成后配置
Browse files Browse the repository at this point in the history
  • Loading branch information
ohno2018 committed Jun 20, 2024
1 parent a4a13ec commit 857c005
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 66 deletions.
42 changes: 0 additions & 42 deletions alicloud/resource_alicloud_elasticsearch_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,20 +277,6 @@ func resourceAlicloudElasticsearch() *schema.Resource {
DiffSuppressFunc: elasticsearchEnableKibanaPublicDiffSuppressFunc,
},

"enable_kibana_private_network": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},

"kibana_private_whitelist": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
DiffSuppressFunc: elasticsearchEnableKibanaPrivateDiffSuppressFunc,
},

"zone_count": {
Type: schema.TypeInt,
ForceNew: true,
Expand Down Expand Up @@ -403,10 +389,6 @@ func resourceAlicloudElasticsearchRead(d *schema.ResourceData, meta interface{})
d.Set("kibana_port", object["kibanaPort"])
}

d.Set("enable_kibana_private_network", object["enableKibanaPrivateNetwork"])
kibanaPrivateIPWhitelist := object["kibanaPrivateIPWhitelist"].([]interface{})
d.Set("kibana_private_whitelist", filterWhitelist(convertArrayInterfaceToArrayString(kibanaPrivateIPWhitelist), d.Get("kibana_private_whitelist").(*schema.Set)))

// Data node configuration
d.Set("data_node_amount", object["nodeAmount"])
d.Set("data_node_spec", object["nodeSpec"].(map[string]interface{})["spec"])
Expand Down Expand Up @@ -533,30 +515,6 @@ func resourceAlicloudElasticsearchUpdate(d *schema.ResourceData, meta interface{
d.SetPartial("kibana_whitelist")
}

if d.HasChange("enable_kibana_private_network") {
content := make(map[string]interface{})
content["networkType"] = string(PRIVATE)
content["nodeType"] = string(KIBANA)
content["actionType"] = elasticsearchService.getActionType(d.Get("enable_kibana_private_network").(bool))
if err := elasticsearchService.TriggerNetwork(d, content, meta); err != nil {
return WrapError(err)
}

d.SetPartial("enable_kibana_private_network")
}

if d.HasChange("kibana_private_whitelist") {
content := make(map[string]interface{})
content["networkType"] = string(PRIVATE)
content["nodeType"] = string(KIBANA)
content["whiteIpList"] = d.Get("kibana_private_whitelist").(*schema.Set).List()
if err := elasticsearchService.ModifyWhiteIps(d, content, meta); err != nil {
return WrapError(err)
}

d.SetPartial("kibana_private_whitelist")
}

if d.HasChange("tags") {
if err := updateInstanceTags(d, meta); err != nil {
return WrapError(err)
Expand Down
80 changes: 58 additions & 22 deletions alicloud/resource_alicloud_elasticsearch_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func testSweepElasticsearch(region string) error {
return nil
}

func TestAccAlicloudElasticsearchInstance_basic(t *testing.T) {
func TestAccAliCloudElasticsearchInstance_basic(t *testing.T) {
var instance *elasticsearch.DescribeInstanceResponse

resourceId := "alicloud_elasticsearch_instance.default"
Expand Down Expand Up @@ -199,6 +199,9 @@ func TestAccAlicloudElasticsearchInstance_basic(t *testing.T) {
"kibana_node_spec": KibanaSpec,
"instance_charge_type": string(PostPaid),
"zone_count": "1",
"kms_encrypted_password": "Yourpassword1234",
"kms_encryption_context": "context01",
"resource_group_id": "groupId01",
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
Expand Down Expand Up @@ -258,6 +261,28 @@ func TestAccAlicloudElasticsearchInstance_basic(t *testing.T) {
}),
),
},
{
Config: testAccConfig(map[string]interface{}{
"kms_encrypted_password": "Yourpassword1235",
"kms_encryption_context": "context02",
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"kms_encrypted_password": "Yourpassword1235",
"kms_encryption_context": "context02",
}),
),
},
{
Config: testAccConfig(map[string]interface{}{
"resource_group_id": "groupId02",
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"resource_group_id": "groupId02",
}),
),
},
{
Config: testAccConfig(map[string]interface{}{
"description": name[:len(name)-1],
Expand All @@ -272,15 +297,15 @@ func TestAccAlicloudElasticsearchInstance_basic(t *testing.T) {
Config: testAccConfig(map[string]interface{}{
"data_node_spec": DataNodeSpecForUpdate,
"data_node_amount": DataNodeAmountForUpdate,
"data_node_disk_type": DataNodeEssdDiskType,
"data_node_disk_type": DataNodeSsdDiskType,
"data_node_disk_size": DataNodeDiskForEssdUpdate,
"data_node_disk_performance_level": DataNodeDiskPerformanceLevel2,
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"data_node_spec": DataNodeSpecForUpdate,
"data_node_amount": DataNodeAmountForUpdate,
"data_node_disk_type": DataNodeEssdDiskType,
"data_node_disk_type": DataNodeSsdDiskType,
"data_node_disk_size": DataNodeDiskForEssdUpdate,
"data_node_disk_performance_level": DataNodeDiskPerformanceLevel2,
}),
Expand Down Expand Up @@ -344,7 +369,7 @@ func TestAccAlicloudElasticsearchInstance_basic(t *testing.T) {
})
}

func TestAccAlicloudElasticsearchInstance_version(t *testing.T) {
func TestAccAliCloudElasticsearchInstance_version(t *testing.T) {
var instance *elasticsearch.DescribeInstanceResponse

resourceId := "alicloud_elasticsearch_instance.default"
Expand Down Expand Up @@ -410,7 +435,7 @@ func TestAccAlicloudElasticsearchInstance_version(t *testing.T) {
})
}

func TestAccAlicloudElasticsearchInstance_multizone(t *testing.T) {
func TestAccAliCloudElasticsearchInstance_multizone(t *testing.T) {
var instance *elasticsearch.DescribeInstanceResponse

resourceId := "alicloud_elasticsearch_instance.default"
Expand Down Expand Up @@ -476,7 +501,7 @@ func TestAccAlicloudElasticsearchInstance_multizone(t *testing.T) {
})
}

func TestAccAlicloudElasticsearchInstance_encrypt_disk(t *testing.T) {
func TestAccAliCloudElasticsearchInstance_encrypt_disk(t *testing.T) {
var instance *elasticsearch.DescribeInstanceResponse

resourceId := "alicloud_elasticsearch_instance.default"
Expand Down Expand Up @@ -531,7 +556,7 @@ func TestAccAlicloudElasticsearchInstance_encrypt_disk(t *testing.T) {
})
}

func TestAccAlicloudElasticsearchInstance_prepaid_autorenew(t *testing.T) {
func TestAccAliCloudElasticsearchInstance_prepaid_autorenew(t *testing.T) {
var instance *elasticsearch.DescribeInstanceResponse

resourceId := "alicloud_elasticsearch_instance.default"
Expand Down Expand Up @@ -646,11 +671,21 @@ func TestAccAlicloudElasticsearchInstance_prepaid_autorenew(t *testing.T) {
}),
),
},
{
Config: testAccConfig(map[string]interface{}{
"instance_charge_type": "PostPaid",
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"instance_charge_type": "PostPaid",
}),
),
},
},
})
}

func TestAccAlicloudElasticsearchInstance_network(t *testing.T) {
func TestAccAliCloudElasticsearchInstance_network(t *testing.T) {
var instance *elasticsearch.DescribeInstanceResponse

resourceId := "alicloud_elasticsearch_instance.default"
Expand Down Expand Up @@ -693,7 +728,7 @@ func TestAccAlicloudElasticsearchInstance_network(t *testing.T) {
"instance_charge_type": string(PostPaid),
"zone_count": "1",
"enable_public": "true",
"enable_kibana_private_network": "true",
"enable_kibana_public_network": "true",
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
Expand All @@ -709,7 +744,7 @@ func TestAccAlicloudElasticsearchInstance_network(t *testing.T) {
"instance_charge_type": string(PostPaid),
"zone_count": "1",
"enable_public": "true",
"enable_kibana_private_network": "true",
"enable_kibana_public_network": "true",
}),
),
},
Expand All @@ -729,16 +764,6 @@ func TestAccAlicloudElasticsearchInstance_network(t *testing.T) {
}),
),
},
{
Config: testAccConfig(map[string]interface{}{
"kibana_private_whitelist": []string{"192.168.0.0/24", "127.0.0.1/32"},
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"kibana_private_whitelist.#": "2",
}),
),
},
{
Config: testAccConfig(map[string]interface{}{
"public_whitelist": []string{"192.168.0.0/24", "127.0.0.1/32"},
Expand Down Expand Up @@ -777,6 +802,18 @@ func TestAccAlicloudElasticsearchInstance_network(t *testing.T) {
}),
),
},
{
Config: testAccConfig(map[string]interface{}{
"enable_public": "false",
"enable_kibana_public_network": "false",
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"enable_public": "false",
"enable_kibana_public_network": "false",
}),
),
},
},
})
}
Expand All @@ -792,7 +829,6 @@ var elasticsearchMap = map[string]string{
"status": "active",
"enable_public": "false",
"enable_kibana_public_network": "true",
"enable_kibana_private_network": "false",
"id": CHECKSET,
"vswitch_id": CHECKSET,
}
Expand All @@ -806,4 +842,4 @@ func resourceElasticsearchInstanceConfigDependence(name string) string {
default = "%s"
}
`, ElasticsearchInstanceCommonTestCase, name)
}
}
4 changes: 2 additions & 2 deletions website/docs/r/elasticsearch_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Provides an Elasticsearch instance resource. It contains data nodes, dedicated m

-> **NOTE:** Only one operation is supported in a request. So if `data_node_spec` and `data_node_disk_size` are both changed, system will respond error.

-> **NOTE:** Kibana private network configuration is not supported at the time of instance creation. it is only supported after the instance has been created, by calling the relevant API operations.

-> **NOTE:** At present, `version` can not be modified once instance has been created.

-> **NOTE:** Available since v1.30.0.
Expand Down Expand Up @@ -87,8 +89,6 @@ The following arguments are supported:
* `enable_public` - (Optional, Available since v1.87.0) Bool, default to false. When it set to true, the instance can enable public network access。
* `kibana_whitelist` - (Optional) Set the Kibana's IP whitelist in internet network.
* `enable_kibana_public_network` - (Optional, Available since v1.87.0) Bool, default to true. When it set to false, the instance can enable kibana public network access。
* `kibana_private_whitelist` - (Optional, Available since v1.87.0) Set the Kibana's IP whitelist in private network.
* `enable_kibana_private_network` - (Optional, Available since v1.87.0) Bool, default to false. When it set to true, the instance can close kibana private network access。
* `master_node_spec` - (Optional) The dedicated master node spec. If specified, dedicated master node will be created.
* `master_node_disk_type` - (Optional, Available since 1.208.1) The single master node storage space. Valid values are `PrePaid`, `PostPaid`.
* `client_node_amount` - (Optional, Available since v1.101.0) The Elasticsearch cluster's client node quantity, between 2 and 25.
Expand Down

0 comments on commit 857c005

Please sign in to comment.