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

chore(dsc): modify the code style and document description #5853

Merged
merged 1 commit into from
Nov 14, 2024
Merged
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
15 changes: 8 additions & 7 deletions docs/resources/dsc_asset_obs.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
subcategory: "Data Security Center (DSC)"
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_dsc_asset_obs"
description: ""
description: |-
Manages an OBS asset resource of DSC within HuaweiCloud.
---

# huaweicloud_dsc_asset_obs

Manages an OBS asset resource of DSC within HuaweiCloud.
Manages an OBS asset resource of DSC within HuaweiCloud.

## Example Usage

Expand All @@ -29,13 +30,13 @@ The following arguments are supported:
* `region` - (Optional, String, ForceNew) Specifies the region in which to create the resource.
If omitted, the provider-level region will be used. Changing this parameter will create a new resource.

* `name` - (Required, String) The name of asset.
* `name` - (Required, String) Specifies the name of asset.

* `bucket_name` - (Required, String, ForceNew) The bucket name.
* `bucket_name` - (Required, String, ForceNew) Specifies the bucket name.

Changing this parameter will create a new resource.

* `bucket_policy` - (Required, String, ForceNew) The bucket policy.
* `bucket_policy` - (Required, String, ForceNew) Specifies the bucket policy.

Changing this parameter will create a new resource.

Expand All @@ -47,8 +48,8 @@ In addition to all arguments above, the following attributes are exported:

## Import

The obs asset can be imported using the `id`, e.g.
The OBS asset resource can be imported using the `id`, e.g.

```bash
$ terraform import huaweicloud_dsc_asset_obs.test 0ce123456a00f2591fabc00385ff1234
$ terraform import huaweicloud_dsc_asset_obs.test <id>
```
42 changes: 21 additions & 21 deletions docs/resources/dsc_instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
subcategory: "Data Security Center (DSC)"
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_dsc_instance"
description: ""
description: |-
Manages a DSC instance resource within HuaweiCloud.
---

# huaweicloud_dsc_instance

Manages a DSC instance resource within HuaweiCloud.
Manages a DSC instance resource within HuaweiCloud.

## Example Usage

Expand All @@ -30,46 +31,45 @@ The following arguments are supported:
* `region` - (Optional, String, ForceNew) Specifies the region in which to create the resource.
If omitted, the provider-level region will be used. Changing this parameter will create a new resource.

* `charging_mode` - (Required, String, ForceNew) Billing mode.
The options are as follows:
+ **prePaid**: the yearly/monthly billing mode.
* `charging_mode` - (Required, String, ForceNew) Specifies the billing mode.
Valid value is **prePaid** (the yearly/monthly billing mode).

Changing this parameter will create a new resource.

* `period_unit` - (Required, String, ForceNew) The charging period unit.
* `period_unit` - (Required, String, ForceNew) Specifies the charging period unit.
Valid values are **month** and **year**. This parameter is mandatory if `charging_mode` is set to **prePaid**.

Changing this parameter will create a new resource.

* `period` - (Required, Int, ForceNew) The charging period.
* `period` - (Required, Int, ForceNew) Specifies the charging period.
If `period_unit` is set to **month**, the value ranges from `1` to `9`.
If `period_unit` is set to **year**, the value ranges from `1` to `3`.
This parameter is mandatory if `charging_mode` is set to **prePaid**.

Changing this parameter will create a new resource.

* `edition` - (Required, String, ForceNew) The edition of DSC.
By default, it supports 2 databases and 100GB of OBS storage
* `edition` - (Required, String, ForceNew) Specifies the edition of DSC.
By default, it supports `2` databases and `100`GB of OBS storage.
The options are as follows:
+ **base_standard**: Standard Edition.
It supports **Overview**, **Sensitive Data Identification** and **Data Usage Audit**.
+ **base_professional**: Professional Edition.
It supports **Overview**, **Sensitive Data Identification**, **Data Usage Audit**, **Data Masking**,
and **Watermark injection/extraction**
+ **base_standard**: Standard Edition.
It supports **Overview**, **Sensitive Data Identification** and **Data Usage Audit**.
+ **base_professional**: Professional Edition.
It supports **Overview**, **Sensitive Data Identification**, **Data Usage Audit**, **Data Masking**,
and **Watermark injection/extraction**.

Changing this parameter will create a new resource.

* `auto_renew` - (Optional, String, ForceNew) Whether auto renew is enabled. Valid values are **true** and **false**.
Defaults to **false**.
* `auto_renew` - (Optional, String, ForceNew) Specifies whether auto-renew is enabled. Valid values are **true** and **false**.
Defaults to **false**.

Changing this parameter will create a new resource.

* `obs_expansion_package` - (Optional, Int, ForceNew) The size of OBS expansion packages.
One expansion package offers 1 TB of OBS storage.
* `obs_expansion_package` - (Optional, Int, ForceNew) Specifies the size of OBS expansion packages.
One expansion package offers `1` TB of OBS storage.

Changing this parameter will create a new resource.

* `database_expansion_package` - (Optional, Int, ForceNew) The size of database expansion packages.
* `database_expansion_package` - (Optional, Int, ForceNew) Specifies the size of database expansion packages.
One expansion package offers one database.

Changing this parameter will create a new resource.
Expand All @@ -82,8 +82,8 @@ In addition to all arguments above, the following attributes are exported:

## Import

The dsc instance can be imported using the `id`, e.g.
The DSC instance resource can be imported using the `id`, e.g.

```bash
$ terraform import huaweicloud_dsc_instance.test 0ce123456a00f2591fabc00385ff1234
$ terraform import huaweicloud_dsc_instance.test <id>
```
9 changes: 9 additions & 0 deletions huaweicloud/services/acceptance/acceptance.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ var (
HW_DC_VIRTUAL_INTERFACE_ID = os.Getenv("HW_DC_VIRTUAL_INTERFACE_ID")
HW_DC_ENABLE_FLAG = os.Getenv("HW_DC_ENABLE_FLAG")

HW_DSC_INSTANCE_ID = os.Getenv("HW_DSC_INSTANCE_ID")

HW_CES_START_TIME = os.Getenv("HW_CES_START_TIME")
HW_CES_END_TIME = os.Getenv("HW_CES_END_TIME")

Expand Down Expand Up @@ -2534,6 +2536,13 @@ func TestAccPrecheckDcFlag(t *testing.T) {
}
}

// lintignore:AT003
func TestAccPrecheckDscInstance(t *testing.T) {
if HW_DSC_INSTANCE_ID == "" {
t.Skip("HW_DSC_INSTANCE_ID must be set for the acceptance test")
}
}

// lintignore:AT003
func TestAccPrecheckTimeStamp(t *testing.T) {
if HW_CDN_TIMESTAMP == "" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,37 @@ import (
)

func getAssetObsResourceFunc(cfg *config.Config, state *terraform.ResourceState) (interface{}, error) {
region := acceptance.HW_REGION_NAME
// getAssetObs: Query the asset OBS
var (
getAssetObsHttpUrl = "v1/{project_id}/sdg/asset/obs/buckets"
getAssetObsProduct = "dsc"
region = acceptance.HW_REGION_NAME
httpUrl = "v1/{project_id}/sdg/asset/obs/buckets"
product = "dsc"
)
getAssetObsClient, err := cfg.NewServiceClient(getAssetObsProduct, region)
client, err := cfg.NewServiceClient(product, region)
if err != nil {
return nil, fmt.Errorf("error creating AssetObs Client: %s", err)
return nil, fmt.Errorf("error creating DSC client: %s", err)
}

getAssetObsPath := getAssetObsClient.Endpoint + getAssetObsHttpUrl
getAssetObsPath = strings.ReplaceAll(getAssetObsPath, "{project_id}", getAssetObsClient.ProjectID)
getAssetObsPath += "?added=true"

getAssetObsOpt := golangsdk.RequestOpts{
requestPath := client.Endpoint + httpUrl
requestPath = strings.ReplaceAll(requestPath, "{project_id}", client.ProjectID)
requestPath += "?added=true"
requestOpt := golangsdk.RequestOpts{
KeepResponseBody: true,
OkCodes: []int{
200,
},
}
getAssetObsResp, err := getAssetObsClient.Request("GET", getAssetObsPath, &getAssetObsOpt)

resp, err := client.Request("GET", requestPath, &requestOpt)
if err != nil {
return nil, fmt.Errorf("error retrieving AssetObs: %s", err)
return nil, fmt.Errorf("error retrieving DSC asset OBS buckets: %s", err)
}

getAssetObsRespBody, err := utils.FlattenResponse(getAssetObsResp)
respBody, err := utils.FlattenResponse(resp)
if err != nil {
return nil, fmt.Errorf("error retrieving AssetObs: %s", err)
return nil, err
}

assetObs := utils.PathSearch(fmt.Sprintf("buckets[?id=='%s']|[0]", state.Primary.ID), getAssetObsRespBody, nil)
expression := fmt.Sprintf("buckets[?id=='%s']|[0]", state.Primary.ID)
assetObs := utils.PathSearch(expression, respBody, nil)
if assetObs == nil {
return nil, fmt.Errorf("error retrieving AssetObs: %s", err)
return nil, golangsdk.ErrDefault404{}
}
return assetObs, nil
}
Expand All @@ -68,7 +65,11 @@ func TestAccAssetObs_basic(t *testing.T) {
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
PreCheck: func() {
acceptance.TestAccPreCheck(t)
// Configure a DSC instance with OBS authorization enabled.
acceptance.TestAccPrecheckDscInstance(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
CheckDestroy: rc.CheckResourceDestroy(),
Steps: []resource.TestStep{
Expand Down Expand Up @@ -101,26 +102,16 @@ func TestAccAssetObs_basic(t *testing.T) {

func testAssetObs_basic(name, obsName string) string {
return fmt.Sprintf(`
%s
resource "huaweicloud_obs_bucket" "test" {
bucket = "%s"
acl = "private"
force_destroy = true
lifecycle {
ignore_changes = [
logging,
]
}
}
resource "huaweicloud_dsc_asset_obs" "test" {
name = "%s"
bucket_name = huaweicloud_obs_bucket.test.bucket
bucket_policy = "private"
depends_on = [huaweicloud_dsc_instance.test]
}
`, testDscInstance_basic(), obsName, name)
`, obsName, name)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,36 @@ import (
)

func getDscInstanceResourceFunc(cfg *config.Config, _ *terraform.ResourceState) (interface{}, error) {
region := acceptance.HW_REGION_NAME
// getDscInstance: Query the DSC instance
var (
getDscInstanceHttpUrl = "v1/{project_id}/period/product/specification"
getDscInstanceProduct = "dsc"
region = acceptance.HW_REGION_NAME
httpUrl = "v1/{project_id}/period/product/specification"
product = "dsc"
)
getDscInstanceClient, err := cfg.NewServiceClient(getDscInstanceProduct, region)
client, err := cfg.NewServiceClient(product, region)
if err != nil {
return nil, fmt.Errorf("error creating DscInstance Client: %s", err)
}

getDscInstancePath := getDscInstanceClient.Endpoint + getDscInstanceHttpUrl
getDscInstancePath = strings.ReplaceAll(getDscInstancePath, "{project_id}", getDscInstanceClient.ProjectID)

getDscInstanceOpt := golangsdk.RequestOpts{
requestPath := client.Endpoint + httpUrl
requestPath = strings.ReplaceAll(requestPath, "{project_id}", client.ProjectID)
requestOpt := golangsdk.RequestOpts{
KeepResponseBody: true,
OkCodes: []int{
200,
},
}
getDscInstanceResp, err := getDscInstanceClient.Request("GET", getDscInstancePath, &getDscInstanceOpt)
resp, err := client.Request("GET", requestPath, &requestOpt)
if err != nil {
return nil, fmt.Errorf("error retrieving DscInstance: %s", err)
return nil, fmt.Errorf("error retrieving DSC instance: %s", err)
}

getDscInstanceRespBody, err := utils.FlattenResponse(getDscInstanceResp)
respBody, err := utils.FlattenResponse(resp)
if err != nil {
return nil, fmt.Errorf("error retrieving DscInstance: %s", err)
return nil, err
}

orderInfo := utils.PathSearch("orderInfo", getDscInstanceRespBody, []interface{}{})
orders := orderInfo.([]interface{})
orders := utils.PathSearch("orderInfo", respBody, make([]interface{}, 0)).([]interface{})
if len(orders) == 0 {
return nil, fmt.Errorf("error retrieving DscInstance: %s", err)
return nil, fmt.Errorf("error retrieving DSC instance: %s", err)
}
return orderInfo, nil
return orders, nil
}

func TestAccDscInstance_basic(t *testing.T) {
Expand Down
Loading
Loading