Skip to content

Commit

Permalink
fix(dataarts/dataservice): fix some issues for api resource (#5333)
Browse files Browse the repository at this point in the history
* feat(dataarts/dataservice): hosts without structure definition for api

* chore(dataarts/dataservice): reviewer precheck using the new function

* test(dataarts/dataservice): using envs to manage resource

* fix(dataarts/dataservice): adjust the update logic and related ut
  • Loading branch information
Lance52259 authored Aug 2, 2024
1 parent 257b0e4 commit adcc5a6
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 71 deletions.
16 changes: 15 additions & 1 deletion docs/resources/dataarts_dataservice_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,21 @@ In addition to all arguments above, the following attributes are exported:

* `host` - The API host configuration, for shared type.

* `hosts` - The API host configuration, for exclusive type.
* `hosts` - The API host configuration, for exclusive type.
The [hosts](#dataservice_api_hosts_attr) structure is documented below.

<a name="dataservice_api_hosts_attr"></a>
The `hosts` block supports:

* `instance_id` - The cluster ID to which the API belongs.

* `instance_name` - The cluster name to which the API belongs.

* `intranet_host` - The intranet address.

* `external_host` - The exrernal address.

* `domains` - The list of gateway damains.

## Import

Expand Down
16 changes: 4 additions & 12 deletions huaweicloud/services/acceptance/acceptance.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,6 @@ var (
HW_DATAARTS_WORKSPACE_ID = os.Getenv("HW_DATAARTS_WORKSPACE_ID")
HW_DATAARTS_CDM_NAME = os.Getenv("HW_DATAARTS_CDM_NAME")
HW_DATAARTS_MANAGER_ID = os.Getenv("HW_DATAARTS_MANAGER_ID")
HW_DATAARTS_MANAGER_NAME = os.Getenv("HW_DATAARTS_MANAGER_NAME")
HW_DATAARTS_BIZ_CATALOG_ID = os.Getenv("HW_DATAARTS_BIZ_CATALOG_ID")
HW_DATAARTS_SECRECY_LEVEL_ID = os.Getenv("HW_DATAARTS_SECRECY_LEVEL_ID")
HW_DATAARTS_SECRECY_LEVEL_ID_UPDATE = os.Getenv("HW_DATAARTS_SECRECY_LEVEL_ID_UPDATE")
Expand All @@ -360,7 +359,7 @@ var (
HW_DATAARTS_CONNECTION_NAME = os.Getenv("HW_DATAARTS_CONNECTION_NAME")
// Data Service
HW_DATAARTS_REVIEWER_NAME = os.Getenv("HW_DATAARTS_REVIEWER_NAME")
HW_DATAARTS_LTS_QUEUE_NAME = os.Getenv("HW_DATAARTS_LTS_QUEUE_NAME")
HW_DATAARTS_DLI_QUEUE_NAME = os.Getenv("HW_DATAARTS_DLI_QUEUE_NAME")

HW_EVS_AVAILABILITY_ZONE_GPSSD2 = os.Getenv("HW_EVS_AVAILABILITY_ZONE_GPSSD2")
HW_EVS_AVAILABILITY_ZONE_ESSD2 = os.Getenv("HW_EVS_AVAILABILITY_ZONE_ESSD2")
Expand Down Expand Up @@ -1789,9 +1788,9 @@ func TestAccPreCheckDataArtsReviewerName(t *testing.T) {
}

// lintignore:AT003
func TestAccPreCheckDataArtsRelatedLtsQueueName(t *testing.T) {
if HW_DATAARTS_LTS_QUEUE_NAME == "" {
t.Skip("HW_DATAARTS_LTS_QUEUE_NAME must be set for the DataService tests")
func TestAccPreCheckDataArtsRelatedDliQueueName(t *testing.T) {
if HW_DATAARTS_DLI_QUEUE_NAME == "" {
t.Skip("HW_DATAARTS_DLI_QUEUE_NAME must be set for the DataService tests")
}
}

Expand All @@ -1802,13 +1801,6 @@ func TestAccPreCheckDataArtsManagerID(t *testing.T) {
}
}

// lintignore:AT003
func TestAccPreCheckDataArtsManagerName(t *testing.T) {
if HW_DATAARTS_MANAGER_NAME == "" {
t.Skip("HW_DATAARTS_MANAGER_NAME must be set for DataArts Studio DataService API acceptance tests")
}
}

// lintignore:AT003
func TestAccPreCheckDataArtsBizCatalogID(t *testing.T) {
if HW_DATAARTS_BIZ_CATALOG_ID == "" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestAccDataSourceDataServiceApis_basic(t *testing.T) {
PreCheck: func() {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckDataArtsWorkSpaceID(t)
acceptance.TestAccPreCheckDataArtsManagerName(t)
acceptance.TestAccPreCheckDataArtsReviewerName(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -207,7 +207,7 @@ resource "huaweicloud_dataarts_dataservice_api" "test" {
}
}
}
`, acceptance.HW_DATAARTS_WORKSPACE_ID, name, acceptance.HW_DATAARTS_MANAGER_NAME)
`, acceptance.HW_DATAARTS_WORKSPACE_ID, name, acceptance.HW_DATAARTS_REVIEWER_NAME)
}

func testAccDataSourceDataServiceApis_basic() string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestAccDataServiceApiDebug_basic(t *testing.T) {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckDataArtsWorkSpaceID(t)
acceptance.TestAccPreCheckDataArtsReviewerName(t)
acceptance.TestAccPreCheckDataArtsRelatedLtsQueueName(t)
acceptance.TestAccPreCheckDataArtsRelatedDliQueueName(t)
},

ProviderFactories: acceptance.TestAccProviderFactories,
Expand Down Expand Up @@ -118,7 +118,7 @@ resource "huaweicloud_dataarts_dataservice_api" "test" {
name,
acceptance.HW_DATAARTS_REVIEWER_NAME,
acceptance.HW_DATAARTS_CONNECTION_ID,
acceptance.HW_DATAARTS_LTS_QUEUE_NAME)
acceptance.HW_DATAARTS_DLI_QUEUE_NAME)
}

func testAccDataServiceApiDebug_basic() string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ func TestAccDataServiceApi_basic(t *testing.T) {
PreCheck: func() {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckDataArtsWorkSpaceID(t)
acceptance.TestAccPreCheckDataArtsManagerName(t)
acceptance.TestAccPreCheckDataArtsReviewerName(t)
acceptance.TestAccPreCheckDataArtsConnectionID(t)
acceptance.TestAccPreCheckDataArtsRelatedDliQueueName(t)
},

ProviderFactories: acceptance.TestAccProviderFactories,
Expand All @@ -56,20 +58,18 @@ func TestAccDataServiceApi_basic(t *testing.T) {
"huaweicloud_dataarts_dataservice_catalog.test.0", "id"),
resource.TestCheckResourceAttr(rName, "name", name),
resource.TestCheckResourceAttr(rName, "description", "Created by terraform script"),
resource.TestCheckResourceAttr(rName, "manager", acceptance.HW_DATAARTS_MANAGER_NAME),
resource.TestCheckResourceAttr(rName, "manager", acceptance.HW_DATAARTS_REVIEWER_NAME),
resource.TestCheckResourceAttr(rName, "path", "/terraform/auto/resource_create/{resource_type}/{resource_name}"),
resource.TestCheckResourceAttr(rName, "protocol", "PROTOCOL_TYPE_HTTPS"),
resource.TestCheckResourceAttr(rName, "request_type", "REQUEST_TYPE_POST"),
resource.TestCheckResourceAttr(rName, "request_params.#", "6"),
resource.TestCheckResourceAttr(rName, "datasource_config.0.type", "DLI"),
resource.TestCheckResourceAttrPair(rName, "datasource_config.0.connection_id",
"huaweicloud_dataarts_studio_data_connection.test", "id"),
resource.TestCheckResourceAttr(rName, "datasource_config.0.connection_id", acceptance.HW_DATAARTS_CONNECTION_ID),
resource.TestCheckResourceAttrPair(rName, "datasource_config.0.database",
"huaweicloud_dli_database.test", "name"),
resource.TestCheckResourceAttrPair(rName, "datasource_config.0.datatable",
"huaweicloud_dli_table.test", "name"),
resource.TestCheckResourceAttrPair(rName, "datasource_config.0.queue",
"huaweicloud_dli_queue.test", "name"),
resource.TestCheckResourceAttr(rName, "datasource_config.0.queue", acceptance.HW_DATAARTS_DLI_QUEUE_NAME),
resource.TestCheckResourceAttr(rName, "datasource_config.0.backend_params.#", "1"),
resource.TestCheckResourceAttr(rName, "datasource_config.0.backend_params.0.name", "configuration"),
resource.TestCheckResourceAttr(rName, "datasource_config.0.backend_params.0.mapping", "configuration"),
Expand Down Expand Up @@ -97,26 +97,23 @@ func TestAccDataServiceApi_basic(t *testing.T) {
"huaweicloud_dataarts_dataservice_catalog.test.1", "id"),
resource.TestCheckResourceAttr(rName, "name", updateName),
resource.TestCheckResourceAttr(rName, "description", "Updated by terraform script"),
resource.TestCheckResourceAttr(rName, "manager", acceptance.HW_DATAARTS_MANAGER_NAME),
resource.TestCheckResourceAttr(rName, "manager", acceptance.HW_DATAARTS_REVIEWER_NAME),
resource.TestCheckResourceAttr(rName, "path", "/terraform/auto/resource_query/{resource_type}/{resource_name}"),
resource.TestCheckResourceAttr(rName, "protocol", "PROTOCOL_TYPE_HTTP"),
resource.TestCheckResourceAttr(rName, "protocol", "PROTOCOL_TYPE_HTTPS"),
resource.TestCheckResourceAttr(rName, "request_type", "REQUEST_TYPE_GET"),
resource.TestCheckResourceAttr(rName, "request_params.#", "2"),
resource.TestCheckResourceAttr(rName, "datasource_config.0.type", "DLI"),
resource.TestCheckResourceAttrPair(rName, "datasource_config.0.connection_id",
"huaweicloud_dataarts_studio_data_connection.test", "id"),
resource.TestCheckResourceAttr(rName, "datasource_config.0.connection_id", acceptance.HW_DATAARTS_CONNECTION_ID),
resource.TestCheckResourceAttrPair(rName, "datasource_config.0.database",
"huaweicloud_dli_database.test", "name"),
resource.TestCheckResourceAttrPair(rName, "datasource_config.0.datatable",
"huaweicloud_dli_table.test", "name"),
resource.TestCheckResourceAttrPair(rName, "datasource_config.0.queue",
"huaweicloud_dli_queue.test", "name"),
resource.TestCheckResourceAttr(rName, "datasource_config.0.queue", acceptance.HW_DATAARTS_DLI_QUEUE_NAME),
resource.TestCheckResourceAttr(rName, "datasource_config.0.backend_params.#", "0"),
resource.TestCheckResourceAttr(rName, "datasource_config.0.response_params.#", "3"),
resource.TestCheckResourceAttr(rName, "datasource_config.0.order_params.#", "0"),
resource.TestCheckResourceAttrSet(rName, "create_user"),
resource.TestCheckResourceAttrSet(rName, "updated_at"),
waitForDeletionCooldownComplete(),
),
},
{
Expand Down Expand Up @@ -168,43 +165,12 @@ func testAccDataServiceApi_base() string {
name := acceptance.RandomAccResourceName()

return fmt.Sprintf(`
resource "huaweicloud_dataarts_studio_data_connection" "test" {
workspace_id = "%[1]s"
type = "DLI"
env_type = "0"
name = "%[2]s"
config = jsonencode({
"cdm_property_enable": "false"
})
}
resource "huaweicloud_vpc" "test" {
name = "%[2]s"
cidr = "192.168.0.0/16"
}
resource "huaweicloud_dli_elastic_resource_pool" "test" {
name = "%[2]s"
min_cu = 64
max_cu = 64
cidr = cidrsubnet(huaweicloud_vpc.test.cidr, 3, 1)
enterprise_project_id = "0"
}
resource "huaweicloud_dli_queue" "test" {
elastic_resource_pool_name = huaweicloud_dli_elastic_resource_pool.test.name
resource_mode = 1
# basic configuration
name = "%[2]s"
cu_count = 16
}
// Under root path.
resource "huaweicloud_dataarts_dataservice_catalog" "test" {
count = 2
workspace_id = "%[1]s"
dlm_type = "EXCLUSIVE"
name = format("%[2]s_%%d", count.index)
}
Expand Down Expand Up @@ -242,6 +208,8 @@ func testAccDataServiceApi_basic_step1(basicConfig, name string) string {
resource "huaweicloud_dataarts_dataservice_api" "test" {
workspace_id = "%[2]s"
dlm_type = "EXCLUSIVE"
type = "API_SPECIFIC_TYPE_CONFIGURATION"
catalog_id = huaweicloud_dataarts_dataservice_catalog.test[0].id
name = "%[3]s"
Expand Down Expand Up @@ -304,10 +272,10 @@ resource "huaweicloud_dataarts_dataservice_api" "test" {
datasource_config {
type = "DLI"
connection_id = huaweicloud_dataarts_studio_data_connection.test.id
connection_id = "%[5]s"
database = huaweicloud_dli_database.test.name
datatable = huaweicloud_dli_table.test.name
queue = huaweicloud_dli_queue.test.name
queue = "%[6]s"
access_mode = "SQL"
backend_params {
Expand All @@ -332,7 +300,12 @@ resource "huaweicloud_dataarts_dataservice_api" "test" {
}
}
}
`, basicConfig, acceptance.HW_DATAARTS_WORKSPACE_ID, name, acceptance.HW_DATAARTS_MANAGER_NAME)
`, basicConfig,
acceptance.HW_DATAARTS_WORKSPACE_ID,
name,
acceptance.HW_DATAARTS_REVIEWER_NAME,
acceptance.HW_DATAARTS_CONNECTION_ID,
acceptance.HW_DATAARTS_DLI_QUEUE_NAME)
}

func testAccDataServiceApi_basic_step2(basicConfig, name string) string {
Expand All @@ -341,14 +314,16 @@ func testAccDataServiceApi_basic_step2(basicConfig, name string) string {
resource "huaweicloud_dataarts_dataservice_api" "test" {
workspace_id = "%[2]s"
dlm_type = "EXCLUSIVE"
type = "API_SPECIFIC_TYPE_CONFIGURATION"
catalog_id = huaweicloud_dataarts_dataservice_catalog.test[1].id
name = "%[3]s"
description = "Updated by terraform script"
auth_type = "IAM"
manager = "%[4]s"
path = "/terraform/auto/resource_query/{resource_type}/{resource_name}"
protocol = "PROTOCOL_TYPE_HTTP"
protocol = "PROTOCOL_TYPE_HTTPS"
request_type = "REQUEST_TYPE_GET"
visibility = "PROJECT"
Expand All @@ -369,10 +344,10 @@ resource "huaweicloud_dataarts_dataservice_api" "test" {
datasource_config {
type = "DLI"
connection_id = huaweicloud_dataarts_studio_data_connection.test.id
connection_id = "%[5]s"
database = huaweicloud_dli_database.test.name
datatable = huaweicloud_dli_table.test.name
queue = huaweicloud_dli_queue.test.name
queue = "%[6]s"
response_params {
name = "configuration"
Expand All @@ -396,5 +371,10 @@ resource "huaweicloud_dataarts_dataservice_api" "test" {
}
}
}
`, basicConfig, acceptance.HW_DATAARTS_WORKSPACE_ID, name, acceptance.HW_DATAARTS_MANAGER_NAME)
`, basicConfig,
acceptance.HW_DATAARTS_WORKSPACE_ID,
name,
acceptance.HW_DATAARTS_REVIEWER_NAME,
acceptance.HW_DATAARTS_CONNECTION_ID,
acceptance.HW_DATAARTS_DLI_QUEUE_NAME)
}
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func ResourceDataServiceApi() *schema.Resource {
"hosts": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Elem: apiHostsSchema(),
Description: `The API host configuration, for exclusive type.`,
},
},
Expand Down Expand Up @@ -526,6 +526,40 @@ func apiBackendConfigConstantParamsElemSchema() *schema.Resource {
return &sc
}

func apiHostsSchema() *schema.Resource {
sc := schema.Resource{
Schema: map[string]*schema.Schema{
"instance_id": {
Type: schema.TypeString,
Computed: true,
Description: `The cluster ID to which the API belongs.`,
},
"instance_name": {
Type: schema.TypeString,
Computed: true,
Description: `The cluster name to which the API belongs.`,
},
"intranet_host": {
Type: schema.TypeString,
Computed: true,
Description: `The intranet address.`,
},
"external_host": {
Type: schema.TypeString,
Computed: true,
Description: `The exrernal address.`,
},
"domains": {
Type: schema.TypeList,
Computed: true,
Description: `The list of gateway damains.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
}
return &sc
}

func buildModifyDataServiceApiBodyParams(client *golangsdk.ServiceClient, d *schema.ResourceData, workspaceId string) map[string]interface{} {
bodyParams := map[string]interface{}{
"catalog_id": d.Get("catalog_id"),
Expand All @@ -540,7 +574,7 @@ func buildModifyDataServiceApiBodyParams(client *golangsdk.ServiceClient, d *sch
"visibility": d.Get("visibility"),
"request_paras": buildApiRequestParamsBodyParams(d.Get("request_params").(*schema.Set)),
"datasource_config": buildApiDataSourceConfigBodyParams(client, workspaceId, d.Get("datasource_config").([]interface{})),
"backend_config": buildApiBackendConfigBodyParams(d.Get("backend_config").([]interface{})),
"backend_config": utils.RemoveNil(buildApiBackendConfigBodyParams(d.Get("backend_config").([]interface{}))),
}
return bodyParams
}
Expand Down

0 comments on commit adcc5a6

Please sign in to comment.