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

support enterprise_project_id in CSS, DWS,DIS #1313

Merged
merged 3 commits into from
Jul 31, 2021
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
6 changes: 5 additions & 1 deletion docs/resources/css_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
subcategory: "Cloud Search Service (CSS)"
---

# huaweicloud\_css\_cluster
# huaweicloud_css_cluster

CSS cluster management
This is an alternative to `huaweicloud_css_cluster_v1`
Expand Down Expand Up @@ -72,6 +72,10 @@ The following arguments are supported:

* `tags` - (Optional, Map) The key/value pairs to associate with the cluster.

* `enterprise_project_id` - (Optional, String, ForceNew) Specifies the enterprise project id of the css cluster,
Value 0 indicates the default enterprise project.
Changing this parameter will create a new resource.

The `node_config` block supports:

* `availability_zone` - (Optional, String, ForceNew) Availability zone (AZ). Changing this parameter will create a new resource.
Expand Down
28 changes: 16 additions & 12 deletions docs/resources/dis_stream.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
subcategory: "Data Ingestion Service (DIS)"
---

# huaweicloud\_dis\_stream
# huaweicloud_dis_stream

DIS Stream management
This is an alternative to `huaweicloud_dis_stream_v2`
Expand Down Expand Up @@ -33,33 +33,37 @@ resource "huaweicloud_dis_stream" "stream" {

The following arguments are supported:

* `stream_name` - (Required, String) Name of the DIS stream to be created.

* `partition_count` - (Required, Int) Number of the expect partitions. NOTE: Each stream can be scaled up
and down a total of five times within one hour. After the stream is
successfully scaled up or down, it cannot be scaled up or down again
within the next one hour.

* `stream_name` - (Required, String) Name of the DIS stream to be created.
* `stream_type` - (Optional, String, ForceNew) Stream Type. The value is COMMON(means 1M bandwidth) or
ADVANCED(means 5M bandwidth). Changing this parameter will create a new resource.

* `region` - (Optional, String, ForceNew) The region in which to create the DIS stream resource. If omitted, the provider-level region will be used. Changing this creates a new DIS Stream resource.

* `auto_scale_max_partition_count` - (Optional, Int, ForceNew) Maximum number of partition for automatic scaling. Changing this parameter will create a new resource.
* `retention_period` - (Optional, Int, ForceNew) The number of hours for which data from the stream will be retained
in DIS. Value range: 24 to 72.Unit: hour. Changing this parameter will create a new resource.

* `auto_scale_min_partition_count` - (Optional, Int, ForceNew) Minimum number of partition for automatic scaling. Changing this parameter will create a new resource.
* `data_type` - (Optional, String, ForceNew) Data type of the data putting into the stream. The value is one of
BLOB, JSON and CSV. Changing this parameter will create a new resource.

* `compression_format` - (Optional, String, ForceNew) Data compression type. The value is one of snappy, gzip and zip. Changing this parameter will create a new resource.
* `auto_scale_max_partition_count` - (Optional, Int, ForceNew) Maximum number of partition for automatic scaling. Changing this parameter will create a new resource.

* `csv_delimiter` - (Optional, String, ForceNew) Field separator for CSV file. Changing this parameter will create a new resource.
* `auto_scale_min_partition_count` - (Optional, Int, ForceNew) Minimum number of partition for automatic scaling. Changing this parameter will create a new resource.

* `data_schema` - (Optional, String, ForceNew) User's JOSN, CSV format data schema, described with Avro schema. Changing this parameter will create a new resource.

* `data_type` - (Optional, String, ForceNew) Data type of the data putting into the stream. The value is one of
BLOB, JSON and CSV. Changing this parameter will create a new resource.
* `compression_format` - (Optional, String, ForceNew) Data compression type. The value is one of snappy, gzip and zip. Changing this parameter will create a new resource.

* `retention_period` - (Optional, Int, ForceNew) The number of hours for which data from the stream will be retained
in DIS. Changing this parameter will create a new resource.
* `csv_delimiter` - (Optional, String, ForceNew) Field separator for CSV file. Changing this parameter will create a new resource.

* `stream_type` - (Optional, String, ForceNew) Stream Type. The value is COMMON(means 1M bandwidth) or
ADVANCED(means 5M bandwidth). Changing this parameter will create a new resource.
* `enterprise_project_id` - (Optional, String, ForceNew) Specifies the enterprise project id of the dis stream,
Value 0 indicates the default enterprise project.
Changing this parameter will create a new resource.

* `tags` - (Optional, List, ForceNew) List of tags for the newly created DIS stream. Structure is documented below. Changing this parameter will create a new resource.

Expand Down
9 changes: 7 additions & 2 deletions docs/resources/dws_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
subcategory: "Data Warehouse Service (DWS)"
---

# huaweicloud\_dws\_cluster
# huaweicloud_dws_cluster

cluster management
Manages Cluster in the Data Warehouse Service.

## Example Usage

Expand Down Expand Up @@ -66,6 +66,11 @@ The following arguments are supported:
Lowercase letters Uppercase letters Digits Special characters
~!@#%^&*()-_=+|[{}];:,<.>/?

* `enterprise_project_id` - (Optional, String, ForceNew) Specifies the enterprise project id of the dws cluster,
Value 0 indicates the default enterprise project.
Changing this parameter will create a new resource.


- - -

* `availability_zone` - (Optional, String, ForceNew) AZ in a cluster
Expand Down
29 changes: 26 additions & 3 deletions huaweicloud/resource_huaweicloud_css_cluster_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ func ResourceCssClusterV1() *schema.Resource {
},
},
},
"enterprise_project_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},
},
}
}
Expand All @@ -226,15 +232,14 @@ func resourceCssClusterV1Create(d *schema.ResourceData, meta interface{}) error
if err != nil {
return fmtp.Errorf("Error creating sdk client, err=%s", err)
}

opts := resourceCssClusterV1UserInputParams(d)
arrayIndex := map[string]int{
"node_config.network_info": 0,
"node_config.volume": 0,
"node_config": 0,
}

params, err := buildCssClusterV1CreateParameters(opts, arrayIndex)
params, err := buildCssClusterV1CreateParameters(opts, arrayIndex, config)
if err != nil {
return fmtp.Errorf("Error building the request body of api(create), err=%s", err)
}
Expand Down Expand Up @@ -452,7 +457,7 @@ func resourceCssClusterV1Delete(d *schema.ResourceData, meta interface{}) error
return err
}

func buildCssClusterV1CreateParameters(opts map[string]interface{}, arrayIndex map[string]int) (interface{}, error) {
func buildCssClusterV1CreateParameters(opts map[string]interface{}, arrayIndex map[string]int, config *config.Config) (interface{}, error) {
params := make(map[string]interface{})

resourceData := opts["terraform_resource_data"].(*schema.ResourceData)
Expand Down Expand Up @@ -509,6 +514,11 @@ func buildCssClusterV1CreateParameters(opts map[string]interface{}, arrayIndex m
return params, nil
}

enterpriseProjectID := config.GetEnterpriseProjectID(resourceData)
if enterpriseProjectID != "" {
params["enterprise_project_id"] = enterpriseProjectID
}

params = map[string]interface{}{"cluster": params}

return params, nil
Expand Down Expand Up @@ -871,6 +881,12 @@ func fillCssClusterV1ReadRespBody(body interface{}) interface{} {
result["updated"] = nil
}

if v, ok := val["enterprise_project_id"]; ok {
result["enterprise_project_id"] = v
} else {
result["enterprise_project_id"] = nil
}

return result
}

Expand Down Expand Up @@ -1010,6 +1026,13 @@ func setCssClusterV1Properties(d *schema.ResourceData, response map[string]inter
return fmtp.Errorf("Error setting Cluster:expect_node_num, err: %s", err)
}

v, err = navigateValue(response, []string{"read", "enterprise_project_id"}, nil)
if err == nil {
if err = d.Set("enterprise_project_id", v); err != nil {
return fmtp.Errorf("Error setting Cluster:enterprise_project_id, err: %s", err)
}
}

return nil
}

Expand Down
64 changes: 61 additions & 3 deletions huaweicloud/resource_huaweicloud_dis_stream_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils/logp"
)

const DIS_SYS_TAG_KEY_ENTERPRISE_PROJECT_ID = "_sys_enterprise_project_id"

func ResourceDisStreamV2() *schema.Resource {
return &schema.Resource{
Create: resourceDisStreamV2Create,
Expand Down Expand Up @@ -104,6 +106,13 @@ func ResourceDisStreamV2() *schema.Resource {
ForceNew: true,
},

"enterprise_project_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},

"tags": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -171,7 +180,7 @@ func resourceDisStreamV2Create(d *schema.ResourceData, meta interface{}) error {

opts := resourceDisStreamV2UserInputParams(d)

params, err := buildDisStreamV2CreateParameters(opts, nil)
params, err := buildDisStreamV2CreateParameters(opts, nil, config)
if err != nil {
return fmtp.Errorf("Error building the request body of api(create), err=%s", err)
}
Expand Down Expand Up @@ -254,7 +263,7 @@ func resourceDisStreamV2Delete(d *schema.ResourceData, meta interface{}) error {
return nil
}

func buildDisStreamV2CreateParameters(opts map[string]interface{}, arrayIndex map[string]int) (interface{}, error) {
func buildDisStreamV2CreateParameters(opts map[string]interface{}, arrayIndex map[string]int, config *config.Config) (interface{}, error) {
params := make(map[string]interface{})

v, err := expandDisStreamV2CreateAutoCaleEnable(opts, arrayIndex)
Expand Down Expand Up @@ -377,6 +386,19 @@ func buildDisStreamV2CreateParameters(opts map[string]interface{}, arrayIndex ma
params["tags"] = v
}

resourceData := opts["terraform_resource_data"].(*schema.ResourceData)
if resourceData == nil {
return nil, fmtp.Errorf("failed to build parameters: Resource Data is null")
}

enterpriseProjectID := config.GetEnterpriseProjectID(resourceData)
if enterpriseProjectID != "" {
sysTag := make(map[string]string)
sysTag["key"] = DIS_SYS_TAG_KEY_ENTERPRISE_PROJECT_ID
sysTag["value"] = enterpriseProjectID
params["sys_tags"] = []map[string]string{sysTag}
}

return params, nil
}

Expand Down Expand Up @@ -607,6 +629,12 @@ func fillDisStreamV2ReadRespBody(body interface{}) interface{} {
result["writable_partition_count"] = nil
}

if v, ok := val["sys_tags"]; ok {
result["enterprise_project_id"] = parseDisStreamV2ReadRespSysTags(v)
} else {
result["enterprise_project_id"] = nil
}

return result
}

Expand All @@ -630,6 +658,31 @@ func fillDisStreamV2ReadRespCsvProperties(value interface{}) interface{} {
return result
}

func parseDisStreamV2ReadRespSysTags(value interface{}) (r string) {
if value == nil {
return
}

value1, ok := value.([]interface{})
if !ok || len(value1) == 0 {
return
}

n := len(value1)
for i := 0; i < n; i++ {
item := value1[i].(map[string]interface{})

if k, ok := item["key"]; ok && k == DIS_SYS_TAG_KEY_ENTERPRISE_PROJECT_ID {
if v, ok := item["value"]; ok {
return v.(string)
}
}

}

return
}

func fillDisStreamV2ReadRespTags(value interface{}) interface{} {
if value == nil {
return nil
Expand Down Expand Up @@ -755,7 +808,7 @@ func setDisStreamV2Properties(d *schema.ResourceData, response map[string]interf
return fmtp.Errorf("Error setting Stream:stream_type, err: %s", err)
}

v, _ = opts["tags"]
v = opts["tags"]
v, err = flattenDisStreamV2Tags(response, nil, v)
if err != nil {
return fmtp.Errorf("Error reading Stream:tags, err: %s", err)
Expand All @@ -772,6 +825,11 @@ func setDisStreamV2Properties(d *schema.ResourceData, response map[string]interf
return fmtp.Errorf("Error setting Stream:writable_partition_count, err: %s", err)
}

v, err = navigateValue(response, []string{"read", "enterprise_project_id"}, nil)
if err = d.Set("enterprise_project_id", v); err != nil {
return fmtp.Errorf("Error setting Stream:enterprise_project_id, err: %s", err)
}

return nil
}

Expand Down
18 changes: 18 additions & 0 deletions huaweicloud/resource_huaweicloud_dws_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ func ResourceDwsCluster() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"enterprise_project_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -317,6 +324,11 @@ func resourceDwsClusterCreate(d *schema.ResourceData, meta interface{}) error {
opts["vpc_id"] = vpcIDProp
}

enterpriseProjectID := config.GetEnterpriseProjectID(d)
if enterpriseProjectID != "" {
opts["enterprise_project_id"] = enterpriseProjectID
}

url, err := replaceVars(d, "clusters", nil)
if err != nil {
return err
Expand Down Expand Up @@ -506,6 +518,12 @@ func resourceDwsClusterRead(d *schema.ResourceData, meta interface{}) error {
}
}

if v, ok := res["enterprise_project_id"]; ok {
if err := d.Set("enterprise_project_id", v); err != nil {
return fmtp.Errorf("Error reading Cluster:enterprise_project_id, err: %s", err)
}
}

return nil
}

Expand Down