From adcc5a6c840c293dc1726789dcaf686c4c483451 Mon Sep 17 00:00:00 2001 From: Lance Date: Fri, 2 Aug 2024 11:32:40 +0800 Subject: [PATCH] fix(dataarts/dataservice): fix some issues for api resource (#5333) * 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 --- docs/resources/dataarts_dataservice_api.md | 16 +++- huaweicloud/services/acceptance/acceptance.go | 16 +--- ...weicloud_dataarts_dataservice_apis_test.go | 4 +- ...oud_dataarts_dataservice_api_debug_test.go | 4 +- ...aweicloud_dataarts_dataservice_api_test.go | 84 +++++++------------ ...ce_huaweicloud_dataarts_dataservice_api.go | 38 ++++++++- 6 files changed, 91 insertions(+), 71 deletions(-) diff --git a/docs/resources/dataarts_dataservice_api.md b/docs/resources/dataarts_dataservice_api.md index 6c20d93daf..2810dcc0b3 100644 --- a/docs/resources/dataarts_dataservice_api.md +++ b/docs/resources/dataarts_dataservice_api.md @@ -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. + + +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 diff --git a/huaweicloud/services/acceptance/acceptance.go b/huaweicloud/services/acceptance/acceptance.go index d638e55909..37c8021f4e 100644 --- a/huaweicloud/services/acceptance/acceptance.go +++ b/huaweicloud/services/acceptance/acceptance.go @@ -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") @@ -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") @@ -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") } } @@ -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 == "" { diff --git a/huaweicloud/services/acceptance/dataarts/data_source_huaweicloud_dataarts_dataservice_apis_test.go b/huaweicloud/services/acceptance/dataarts/data_source_huaweicloud_dataarts_dataservice_apis_test.go index 3967c0c15b..19f82a90b7 100644 --- a/huaweicloud/services/acceptance/dataarts/data_source_huaweicloud_dataarts_dataservice_apis_test.go +++ b/huaweicloud/services/acceptance/dataarts/data_source_huaweicloud_dataarts_dataservice_apis_test.go @@ -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{ @@ -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 { diff --git a/huaweicloud/services/acceptance/dataarts/resource_huaweicloud_dataarts_dataservice_api_debug_test.go b/huaweicloud/services/acceptance/dataarts/resource_huaweicloud_dataarts_dataservice_api_debug_test.go index d9c3f82842..f667cb862f 100644 --- a/huaweicloud/services/acceptance/dataarts/resource_huaweicloud_dataarts_dataservice_api_debug_test.go +++ b/huaweicloud/services/acceptance/dataarts/resource_huaweicloud_dataarts_dataservice_api_debug_test.go @@ -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, @@ -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 { diff --git a/huaweicloud/services/acceptance/dataarts/resource_huaweicloud_dataarts_dataservice_api_test.go b/huaweicloud/services/acceptance/dataarts/resource_huaweicloud_dataarts_dataservice_api_test.go index 1b42ece9a3..a722abcda4 100644 --- a/huaweicloud/services/acceptance/dataarts/resource_huaweicloud_dataarts_dataservice_api_test.go +++ b/huaweicloud/services/acceptance/dataarts/resource_huaweicloud_dataarts_dataservice_api_test.go @@ -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, @@ -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"), @@ -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(), ), }, { @@ -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) } @@ -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" @@ -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 { @@ -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 { @@ -341,6 +314,8 @@ 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" @@ -348,7 +323,7 @@ resource "huaweicloud_dataarts_dataservice_api" "test" { 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" @@ -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" @@ -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) } diff --git a/huaweicloud/services/dataarts/resource_huaweicloud_dataarts_dataservice_api.go b/huaweicloud/services/dataarts/resource_huaweicloud_dataarts_dataservice_api.go index b6c6bc2750..259da80775 100644 --- a/huaweicloud/services/dataarts/resource_huaweicloud_dataarts_dataservice_api.go +++ b/huaweicloud/services/dataarts/resource_huaweicloud_dataarts_dataservice_api.go @@ -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.`, }, }, @@ -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"), @@ -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 }