Skip to content

Commit

Permalink
support enterprise_project_id in DLI, CSS, DWS,DIS
Browse files Browse the repository at this point in the history
support enterprise_project_id in  CSS, DWS,DIS
  • Loading branch information
hmbig2 committed Jul 25, 2021
1 parent 53a223e commit 3cb4b3e
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 30 deletions.
7 changes: 6 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,11 @@ The following arguments are supported:

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

* `enterprise_project_id` - (Optional, String, ForceNew) Enterprise project ID. When creating a cluster,
associate the enterprise project ID with the 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
29 changes: 17 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,38 @@ 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) Enterprise project ID. When creating a cluster,
associate the enterprise project ID with the cluster.
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
28 changes: 17 additions & 11 deletions docs/resources/dws_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
subcategory: "Data Warehouse Service (DWS)"
---

# huaweicloud\_dws\_cluster
# huaweicloud_dws_cluster

cluster management

Expand All @@ -17,16 +17,16 @@ resource "huaweicloud_networking_secgroup" "secgroup" {
}
resource "huaweicloud_dws_cluster" "cluster" {
node_type = "dws.m3.xlarge"
number_of_node = 3
network_id = "{{ network_id }}"
vpc_id = "{{ vpc_id }}"
security_group_id = huaweicloud_networking_secgroup.secgroup.id
availability_zone = "{{ availability_zone }}"
name = "terraform_dws_cluster_test"
user_name = "test_cluster_admin"
user_pwd = "cluster123@!"
node_type = "dws.m3.xlarge"
number_of_node = 3
network_id = "{{ network_id }}"
vpc_id = "{{ vpc_id }}"
security_group_id = huaweicloud_networking_secgroup.secgroup.id
availability_zone = "{{ availability_zone }}"
name = "terraform_dws_cluster_test"
user_name = "userNmae"
user_pwd = "password"
enterprise_project_id = "0"
timeouts {
create = "30m"
delete = "30m"
Expand Down Expand Up @@ -66,6 +66,12 @@ The following arguments are supported:
Lowercase letters Uppercase letters Digits Special characters
~!@#%^&*()-_=+|[{}];:,<.>/?

* `enterprise_project_id` - (Optional, String, ForceNew) Enterprise project ID. When creating a cluster,
associate the enterprise project ID with the 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
16 changes: 13 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
65 changes: 62 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 @@ -148,6 +157,7 @@ func ResourceDisStreamV2() *schema.Resource {
func resourceDisStreamV2UserInputParams(d *schema.ResourceData) map[string]interface{} {
return map[string]interface{}{
"terraform_resource_data": d,
"auto_scale_enabled": d.Get("auto_scale_enabled"),
"auto_scale_max_partition_count": d.Get("auto_scale_max_partition_count"),
"auto_scale_min_partition_count": d.Get("auto_scale_min_partition_count"),
"compression_format": d.Get("compression_format"),
Expand All @@ -171,7 +181,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 +264,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 +387,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 +630,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 +659,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 +809,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 +826,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
12 changes: 12 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

0 comments on commit 3cb4b3e

Please sign in to comment.