-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feat] New resource opentelekomcloud_css_configuration_v1 (#2792)
[Feat] New resource opentelekomcloud_css_configuration_v1 Summary of the Pull Request Resource for changing cluster configurations PR Checklist Refers to: #2789 Tests added/passed. Documentation updated. Schema updated. Release notes added. Acceptance Steps Performed === RUN TestAccCssConfiguration_basic === PAUSE TestAccCssConfiguration_basic === CONT TestAccCssConfiguration_basic --- PASS: TestAccCssConfiguration_basic (210.78s) PASS Process finished with the exit code 0 Reviewed-by: Muneeb H. Jan <[email protected]>
- Loading branch information
1 parent
45c9b00
commit c25c896
Showing
10 changed files
with
552 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
--- | ||
subcategory: "Cloud Search Service (CSS)" | ||
layout: "opentelekomcloud" | ||
page_title: "OpenTelekomCloud: opentelekomcloud_css_configuration_v1" | ||
sidebar_current: "docs-opentelekomcloud-resource-css-configuration-v1" | ||
description: |- | ||
Manage CSS cluster configurations in OpenTelekomCloud. | ||
--- | ||
|
||
Up-to-date reference for API arguments and details can be found at the [documentation portal](https://docs.otc.t-systems.com/cloud-search-service/api-ref/parameter_configuration/index.html). | ||
|
||
# opentelekomcloud_css_configuration_v1 | ||
|
||
Manage the configuration settings of a CSS cluster in OpenTelekomCloud. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
resource "opentelekomcloud_css_configuration_v1" "example" { | ||
cluster_id = "your-cluster-id" | ||
http_cors_allow_credentials = "true" | ||
http_cors_allow_origin = "122.122.122.122:9200" | ||
indices_queries_cache_size = "50" | ||
auto_create_index = "true" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `cluster_id` - (Required, String, ForceNew) The CSS cluster ID. | ||
|
||
Changing this parameter will create a new resource. | ||
|
||
* `http_cors_allow_credetials` - (Optional, String) Whether to return the Access-Control-Allow-Credentials of | ||
the header during cross-domain access. | ||
The value can be `true` or `false`. Default value: `false`. | ||
|
||
* `http_cors_allow_origin` - (Optional, String) Origin IP address allowed for cross-domain access, for example, `122.122.122.122:9200`. | ||
|
||
* `http_cors_max_age` - (Optional, String) Cache duration of the browser. The cache is automatically cleared | ||
after the time range you specify. | ||
Unit: s, Default value: `1,728,000`. | ||
|
||
* `http_cors_allow_headers` - (Optional, String) Headers allowed for cross-domain access. | ||
Including `X-Requested-With`, `Content-Type`, and `Content-Length`. | ||
Use commas (,) and spaces to separate headers. | ||
|
||
* `http_cors_enabled` - (Optional, String) Whether to allow cross-domain access. | ||
The value can be `true` or `false`. Default value: `false`. | ||
|
||
* `http_cors_allow_methods` - (Optional, String) Methods allowed for cross-domain access. | ||
Including `OPTIONS`, `HEAD`, `GET`, `POST`, `PUT`, and `DELETE`. | ||
Use commas (,) and spaces to separate methods. | ||
|
||
* `reindex_remote_whitelist` - (Optional, String) Configured for migrating data from the current cluster to | ||
the target cluster through the reindex API. | ||
The example value is `122.122.122.122:9200`. | ||
|
||
* `indices_queries_cache_size` - (Optional, String) Cache size in the query phase. Value range: `1%` to `100%`. | ||
Unit: %, Default value: `10%`. | ||
|
||
* `thread_pool_force_merge_size` - (Optional, String) Queue size in the force merge thread pool. | ||
Default value: `1`. | ||
|
||
* `auto_create_index` - (Optional, String) Whether to auto-create an index. | ||
The value can be `true` or `false`. | ||
|
||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - The resource ID which equals the `cluster_id`. | ||
|
||
* `region` - The region where the CSS cluster is deployed. | ||
|
||
|
||
## Timeouts | ||
|
||
This resource provides the following timeouts configuration options: | ||
|
||
* `create` - Default is 20 minutes. | ||
* `delete` - Default is 20 minutes. | ||
|
||
## Import | ||
|
||
The CSS configuration can be imported using the `id` which equals the `cluster_id`, e.g. | ||
|
||
```bash | ||
$ terraform import opentelekomcloud_css_configuration_v1.test <id> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
opentelekomcloud/acceptance/css/resource_opentelekomcloud_css_configuration_v1_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package acceptance | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
golangsdk "github.com/opentelekomcloud/gophertelekomcloud" | ||
pc "github.com/opentelekomcloud/gophertelekomcloud/openstack/css/v1/parameter-configuration" | ||
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/acceptance/common" | ||
|
||
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/acceptance/env" | ||
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/common/cfg" | ||
) | ||
|
||
func getCssConfigurationV1ResourceFunc(cfg *cfg.Config, state *terraform.ResourceState) (interface{}, error) { | ||
c, err := cfg.CssV1Client(env.OS_REGION_NAME) | ||
if err != nil { | ||
return nil, fmt.Errorf("error creating APIG v2 client: %s", err) | ||
} | ||
configurations, err := pc.List(c, state.Primary.ID) | ||
if err != nil { | ||
return nil, fmt.Errorf("error retrieving OpenTelekomCloud CSS configuration: %s", err) | ||
} | ||
for _, template := range configurations.Templates { | ||
if template.Value != template.DefaultValue { | ||
return configurations, nil | ||
} | ||
} | ||
return nil, golangsdk.ErrDefault404{} | ||
} | ||
|
||
func TestAccCssConfiguration_basic(t *testing.T) { | ||
clusterID := os.Getenv("OS_CSS_CLUSTER_ID") | ||
if clusterID == "" { | ||
t.Skip("OS_CSS_CLUSTER_ID env var is not set") | ||
} | ||
|
||
var obj pc.Configurations | ||
rName := "opentelekomcloud_css_configuration_v1.config" | ||
rc := common.InitResourceCheck( | ||
rName, | ||
&obj, | ||
getCssConfigurationV1ResourceFunc, | ||
) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { common.TestAccPreCheck(t) }, | ||
ProviderFactories: common.TestAccProviderFactories, | ||
CheckDestroy: rc.CheckResourceDestroy(), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testCssConfigurationV1_basic(clusterID), | ||
Check: resource.ComposeTestCheckFunc( | ||
rc.CheckResourceExists(), | ||
resource.TestCheckResourceAttr(rName, "thread_pool_force_merge_size", "3"), | ||
resource.TestCheckResourceAttr(rName, "http_cors_allow_credentials", "true"), | ||
), | ||
}, | ||
{ | ||
Config: testCssConfigurationV1_update(clusterID), | ||
Check: resource.ComposeTestCheckFunc( | ||
rc.CheckResourceExists(), | ||
resource.TestCheckResourceAttr(rName, "thread_pool_force_merge_size", "4"), | ||
resource.TestCheckResourceAttr(rName, "http_cors_allow_credentials", "true"), | ||
resource.TestCheckResourceAttr(rName, "http_cors_allow_headers", "X-Requested-With, Content-Type"), | ||
), | ||
}, | ||
{ | ||
ResourceName: rName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testCssConfigurationV1_basic(clusterID string) string { | ||
return fmt.Sprintf(` | ||
resource "opentelekomcloud_css_configuration_v1" "config" { | ||
cluster_id = "%s" | ||
thread_pool_force_merge_size = "3" | ||
http_cors_allow_credentials = true | ||
} | ||
`, clusterID) | ||
} | ||
|
||
func testCssConfigurationV1_update(clusterID string) string { | ||
return fmt.Sprintf(` | ||
resource "opentelekomcloud_css_configuration_v1" "config" { | ||
cluster_id = "%s" | ||
thread_pool_force_merge_size = "4" | ||
http_cors_allow_credentials = true | ||
http_cors_allow_headers = "X-Requested-With, Content-Type" | ||
auto_create_index = true | ||
} | ||
`, clusterID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package common | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"log" | ||
"reflect" | ||
|
||
golangsdk "github.com/opentelekomcloud/gophertelekomcloud" | ||
) | ||
|
||
// ConvertExpected403ErrInto404Err is a method used to parsing 403 error and try to convert it to 404 error according | ||
// to the right error code. | ||
// Arguments: | ||
// + err: The error response obtained through HTTP/HTTPS request. | ||
// + errCodeKey: The key name of the error code in the error response body, e.g. 'error_code', 'err_code'. | ||
// + specErrCodes: One or more error codes that you wish to match against the current error, e.g. 'APIGW.0001'. | ||
// Notes: If you missing specErrCodes input, this function will convert all 403 errors into 404 errors. | ||
// How to use it: | ||
// + For the general cases, their error code key is 'error_code', and we should call as follows: | ||
// - utils.ConvertExpected403ErrInto404Err(err, "error_code") | ||
// - utils.ConvertExpected403ErrInto404Err(err, "error_code", "DWS.0001") | ||
// - utils.ConvertExpected403ErrInto404Err(err, "error_code", []string{"DWS.0001", "DLM.3028"}...) | ||
func ConvertExpected403ErrInto404Err(err error, errCodeKey string, specErrCodes ...string) error { | ||
var err403 golangsdk.ErrDefault403 | ||
if !errors.As(err, &err403) { | ||
log.Printf("[WARN] Unable to recognize expected error type, want 'golangsdk.ErrDefault403', but got '%s'", | ||
reflect.TypeOf(err).String()) | ||
return err | ||
} | ||
var apiError interface{} | ||
if jsonErr := json.Unmarshal(err403.Body, &apiError); jsonErr != nil { | ||
return err | ||
} | ||
|
||
errCode := PathSearch(errCodeKey, apiError, nil) | ||
if errCode == nil { | ||
// 4xx means the client parsing was failed. | ||
return golangsdk.ErrDefault400{ | ||
ErrUnexpectedResponseCode: golangsdk.ErrUnexpectedResponseCode{ | ||
Body: []byte(fmt.Sprintf("Unable to find the error code from the error body using given error code key (%s), the error is: %#v", | ||
errCodeKey, apiError)), | ||
}, | ||
} | ||
} | ||
|
||
if len(specErrCodes) < 1 { | ||
log.Printf("[INFO] Identified 403 error parsed it as 404 error (without the error code control)") | ||
return golangsdk.ErrDefault404{} | ||
} | ||
if StrSliceContains(specErrCodes, fmt.Sprint(errCode)) { | ||
log.Printf("[INFO] Identified 403 error with code '%v' and parsed it as 404 error", errCode) | ||
return golangsdk.ErrDefault404{} | ||
} | ||
log.Printf("[WARN] Unable to recognize expected error code (%v), want %v", errCode, specErrCodes) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.