Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/alicloud_click_house_db_cluster: add support to open public connection. #8413

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
75 changes: 75 additions & 0 deletions alicloud/resource_alicloud_click_house_db_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ func resourceAlicloudClickHouseDbCluster() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"open_public_connection": {
Type: schema.TypeBool,
Optional: true,
},
"public_connection_string": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -351,6 +359,12 @@ func resourceAlicloudClickHouseDbClusterRead(d *schema.ResourceData, meta interf
d.Set("vpc_id", object["VpcId"])
d.Set("connection_string", object["ConnectionString"])
d.Set("port", object["Port"])
d.Set("public_connection_string", object["PublicConnectionString"])
if object["PublicConnectionString"].(string) == "" {
d.Set("open_public_connection", false)
} else {
d.Set("open_public_connection", true)
}

if ZoneIdVswitchMap, ok := object["ZoneIdVswitchMap"]; ok {
vMap := ZoneIdVswitchMap.(map[string]interface{})
Expand Down Expand Up @@ -669,6 +683,67 @@ func resourceAlicloudClickHouseDbClusterUpdate(d *schema.ResourceData, meta inte
d.SetPartial("renewal_status")
}
}
if d.HasChange("open_public_connection") && !d.IsNewResource() {
openPublicConnection := d.Get("open_public_connection").(bool)
if openPublicConnection {
action := "AllocateClusterPublicConnection"
request := map[string]interface{}{
"DBClusterId": d.Id(),
"RegionId": client.RegionId,
}
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError {
response, err = client.RpcPost("clickhouse", "2019-11-11", action, nil, request, false)
if err != nil {
if IsExpectedErrors(err, []string{"IncorrectDBInstanceState"}) || NeedRetry(err) {
wait()
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
addDebug(action, response, request)
if err != nil {
return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR)
}
clickhouseService := ClickhouseService{client}
stateConf := BuildStateConf([]string{"NetAddressCreating"}, []string{"Running"}, d.Timeout(schema.TimeoutCreate), 5*time.Second, clickhouseService.ClickHouseDbClusterStateRefreshFunc(d.Id(), []string{}))
if _, err := stateConf.WaitForState(); err != nil {
return WrapErrorf(err, IdMsg, d.Id())
}
d.SetPartial("open_public_connection")
} else {
action := "ReleaseClusterPublicConnection"
//NetAddressDeleting
request := map[string]interface{}{
"DBClusterId": d.Id(),
"RegionId": client.RegionId,
}
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError {
response, err = client.RpcPost("clickhouse", "2019-11-11", action, nil, request, false)
if err != nil {
if IsExpectedErrors(err, []string{"IncorrectDBInstanceState"}) || NeedRetry(err) {
wait()
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
addDebug(action, response, request)
if err != nil {
return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR)
}
clickhouseService := ClickhouseService{client}
stateConf := BuildStateConf([]string{"NetAddressDeleting"}, []string{"Running"}, d.Timeout(schema.TimeoutCreate), 5*time.Second, clickhouseService.ClickHouseDbClusterStateRefreshFunc(d.Id(), []string{}))
if _, err := stateConf.WaitForState(); err != nil {
return WrapErrorf(err, IdMsg, d.Id())
}
d.SetPartial("open_public_connection")
}
}

d.Partial(false)
return resourceAlicloudClickHouseDbClusterRead(d, meta)
Expand Down
78 changes: 78 additions & 0 deletions alicloud/resource_alicloud_click_house_db_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,84 @@ func TestAccAliCloudClickHouseDBCluster_multiZone(t *testing.T) {
})
}

func TestAccAliCloudClickHouseDBCluster_OpenPublicConnection(t *testing.T) {
checkoutSupportedRegions(t, true, connectivity.VbrSupportRegions)
var v map[string]interface{}
resourceId := "alicloud_click_house_db_cluster.default"
ra := resourceAttrInit(resourceId, AliCloudClickHouseDBClusterMap0)
rc := resourceCheckInitWithDescribeMethod(resourceId, &v, func() interface{} {
return &ClickhouseService{testAccProvider.Meta().(*connectivity.AliyunClient)}
}, "DescribeClickHouseDbCluster")
rac := resourceAttrCheckInit(rc, ra)
testAccCheck := rac.resourceAttrMapUpdateSet()
rand := acctest.RandIntRange(10000, 99999)
name := fmt.Sprintf("tf-testacc%sclickhousedbcluster%d", defaultRegionToTest, rand)
testAccConfig := resourceTestAccConfigFunc(resourceId, name, AliCloudClickHouseDBClusterBasicDependence0)
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
IDRefreshName: resourceId,
Providers: testAccProviders,
CheckDestroy: rac.checkResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testAccConfig(map[string]interface{}{
"db_cluster_version": "23.8",
"category": "Basic",
"db_cluster_class": "S8",
"db_cluster_network_type": "vpc",
"db_node_group_count": "1",
"payment_type": "PayAsYouGo",
"db_node_storage": "100",
"storage_type": "cloud_essd",
"vpc_id": "${alicloud_vswitch.default.vpc_id}",
"vswitch_id": "${alicloud_vswitch.default.id}",
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"db_cluster_version": "23.8",
"category": "Basic",
"db_cluster_class": "S8",
"db_cluster_network_type": "vpc",
"db_node_group_count": "1",
"payment_type": "PayAsYouGo",
"db_node_storage": "100",
"storage_type": "cloud_essd",
"vswitch_id": CHECKSET,
"vpc_id": CHECKSET,
}),
),
}, {
Config: testAccConfig(map[string]interface{}{
"open_public_connection": true,
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"open_public_connection": "true",
"public_connection_string": CHECKSET,
}),
),
}, {
Config: testAccConfig(map[string]interface{}{
"open_public_connection": false,
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"open_public_connection": "false",
"public_connection_string": "",
}),
),
},
{
ResourceName: resourceId,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

var AliCloudClickHouseDBClusterMap0 = map[string]string{
"db_cluster_version": CHECKSET,
"category": CHECKSET,
Expand Down
3 changes: 3 additions & 0 deletions website/docs/r/click_house_db_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ The following arguments are supported:
* `zone_id` - (Optional, ForceNew, Available since v1.185.0) The zone ID of the instance.
* `multi_zone_vswitch_list` - (Optional, ForceNew, Available since v1.228.0) The zone IDs and
corresponding vswitch IDs and zone IDs of multi-zone setup. if set, a multi-zone DBCluster will be created. Currently only support 2 available zones, primary zone not included. See [`multi_zone_vswitch_list`](#multi_zone_vswitch_list) below.
* `open_public_connection` - (Optional, Available since v1.244.0) Whether to enable public connection. Value options: `true`, `false`.
* `public_connection_string` - (Available since v1.244.0) The public connection string of the cluster. Only valid when `open_public_connection` is `true`.


### `db_cluster_access_white_list`

Expand Down
Loading