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 tags for sfs and mrs cluster resource #617

Merged
merged 2 commits into from
Oct 30, 2020
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
36 changes: 19 additions & 17 deletions docs/resources/mrs_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,23 @@ This is an alternative to `huaweicloud_mrs_cluster_v1`
```hcl
resource "huaweicloud_mrs_cluster" "cluster1" {
cluster_name = "mrs-cluster"
cluster_version = "MRS 1.8.10"
cluster_type = 0
region = "cn-north-1"
available_zone_id = "ae04cf9d61544df3806a3feeb401b204"
billing_type = 12
master_node_num = 2
core_node_num = 3
master_node_size = "c3.4xlarge.2.linux.bigdata"
core_node_size = "c3.xlarge.4.linux.bigdata"
available_zone_id = "ae04cf9d61544df3806a3feeb401b204"
vpc_id = "51edfb75-f9f0-4bbc-b4dc-21466b93f60d"
subnet_id = "1d7a8646-43ee-455a-a3ab-40da87a1304c"
cluster_version = "MRS 1.6.3"
volume_type = "SATA"
volume_size = 100
safe_mode = 0
cluster_type = 0
node_public_cert_name = "KeyPair-ci"
cluster_admin_secret = ""
cluster_admin_secret = var.admin_secret
node_public_cert_name = var.keypair
vpc_id = "51edfb75-f9f0-4bbc-b4dc-21466b93f60d"
subnet_id = "1d7a8646-43ee-455a-a3ab-40da87a1304c"

component_list {
component_name = "Hadoop"
}
Expand All @@ -49,6 +50,15 @@ The following arguments are supported:
* `region` - (Required) Cluster region information. Obtain the value from
Regions and Endpoints.

* `cluster_name` - (Required) Cluster name, which is globally unique and contains
only 1 to 64 letters, digits, hyphens (-), and underscores (_).

* `cluster_version` - (Optional) Version of the clusters. Currently, MRS 1.8.10, MRS 1.9.2
and MRS 2.1.0 are supported.

* `cluster_type` - (Optional) Type of clusters 0: analysis cluster 1: streaming
cluster The default value is 0.

* `master_node_num` - (Required) Number of Master nodes The value is 2.

* `master_node_size` - (Required) Best match based on several years of commissioning
Expand All @@ -75,9 +85,6 @@ The following arguments are supported:
South China AZ2(cn-south-2b): 043c7e39ecb347a08dc8fcb6c35a274e,
South China AZ3(cn-south-1c): af1687643e8c4ec1b34b688e4e3b8901,

* `cluster_name` - (Required) Cluster name, which is globally unique and contains
only 1 to 64 letters, digits, hyphens (-), and underscores (_).

* `vpc_id` - (Required) ID of the VPC where the subnet locates Obtain the VPC
ID from the management console as follows: Register an account and log in to
the management console. Click Virtual Private Cloud and select Virtual Private
Expand All @@ -89,13 +96,6 @@ The following arguments are supported:
Click Virtual Private Cloud and select Virtual Private Cloud from the left list.
On the Virtual Private Cloud page, obtain the subnet ID from the list.

* `cluster_version` - (Optional) Version of the clusters Currently, MRS 1.6.3, MRS 1.7.2
and MRS 1.8.1 are supported. The latest version of MRS is used by default. Currently,
the latest version is MRS 1.8.1.

* `cluster_type` - (Optional) Type of clusters 0: analysis cluster 1: streaming
cluster The default value is 0.

* `volume_type` - (Required) Type of disks SATA and SSD are supported. SATA:
common I/O SSD: super high-speed I/O

Expand Down Expand Up @@ -144,6 +144,7 @@ The following arguments are supported:
* `add_jobs` - (Optional) You can submit a job when you create a cluster to
save time and use MRS easily. Only one job can be added.

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

The `component_list` block supports:

Expand Down Expand Up @@ -228,6 +229,7 @@ The following attributes are exported:
* `log_collection` - See Argument Reference above.
* `component_list` - See Argument Reference below.
* `add_jobs` - See Argument Reference above.
* `tags` - See Argument Reference above.
* `order_id` - Order ID for creating clusters.
* `cluster_id` - Cluster ID.
* `available_zone_name` - Name of an availability zone.
Expand Down
12 changes: 9 additions & 3 deletions docs/resources/sfs_file_system.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ resource "huaweicloud_sfs_file_system" "share-file" {
access_level = "rw"
access_to = var.vpc_id
description = var.share_description

tags {
key = "value"
}
}
```

Expand All @@ -41,14 +45,16 @@ The following arguments are supported:

* `availability_zone` - (Optional) The availability zone name. Changing this parameter will create a new resource.

* `enterprise_project_id` - (Optional) The enterprise project id of the shared file system. Changing this creates a new resource.

* `tags` - (Optional) The key/value pairs to associate with the shared file system.

* `access_level` - (Optional) Specifies the access level of the shared file system. Possible values are *ro* (read-only)
and *rw* (read-write). The default value is *rw* (read/write). Changing this will create a new access rule.

* `access_type` - (Optional) Specifies the type of the share access rule. The default value is *cert*.
Changing this will create a new access rule.

* `enterprise_project_id` - (Optional) The enterprise project id of the SFS. Changing this creates a new SFS.

* `access_to` - (Optional) Specifies the value that defines the access rule. The value contains 1 to 255 characters.
Changing this will create a new access rule. The value varies according to the scenario:
- Set the VPC ID in VPC authorization scenarios.
Expand All @@ -60,7 +66,7 @@ The following arguments are supported:
For a CIFS shared file system, the value in the format of *VPC_ID#IP_address#priority*.
For example, 0157b53f-4974-4e80-91c9-098532bcaf00#2.2.2.2/16#0.

-> **NOTE:** If you want to create more access rules, please using [huaweicloud_sfs_access_rule_v2](https://www.terraform.io/docs/providers/huaweicloud/r/sfs_access_rule_v2.html).
-> **NOTE:** If you want to create more access rules, please using [huaweicloud_sfs_access_rule](https://www.terraform.io/docs/providers/huaweicloud/r/sfs_access_rule.html).


## Attributes Reference
Expand Down
49 changes: 46 additions & 3 deletions huaweicloud/resource_huaweicloud_mrs_cluster_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/huaweicloud/golangsdk"
"github.com/huaweicloud/golangsdk/openstack/common/tags"
"github.com/huaweicloud/golangsdk/openstack/mrs/v1/cluster"
"github.com/huaweicloud/golangsdk/openstack/networking/v1/subnets"
"github.com/huaweicloud/golangsdk/openstack/networking/v1/vpcs"
Expand All @@ -19,14 +20,15 @@ func resourceMRSClusterV1() *schema.Resource {
return &schema.Resource{
Create: resourceClusterV1Create,
Read: resourceClusterV1Read,
Update: resourceClusterV1Update,
Delete: resourceClusterV1Delete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(20 * time.Minute),
Delete: schema.DefaultTimeout(5 * time.Minute),
Create: schema.DefaultTimeout(60 * time.Minute),
Delete: schema.DefaultTimeout(10 * time.Minute),
},

Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -234,6 +236,7 @@ func resourceMRSClusterV1() *schema.Resource {
},
},
},
"tags": tagsSchema(),
"order_id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -478,6 +481,15 @@ func resourceClusterV1Create(d *schema.ResourceData, meta interface{}) error {
clusterCreate.ClusterID, err)
}

// create tags
tagRaw := d.Get("tags").(map[string]interface{})
if len(tagRaw) > 0 {
taglist := expandResourceTags(tagRaw)
if tagErr := tags.Create(client, "clusters", d.Id(), taglist).ExtractErr(); tagErr != nil {
return fmt.Errorf("Error setting tags of MRS cluster %s: %s", d.Id(), tagErr)
}
}

return resourceClusterV1Read(d, meta)
}

Expand All @@ -490,8 +502,14 @@ func resourceClusterV1Read(d *schema.ResourceData, meta interface{}) error {

clusterGet, err := cluster.Get(client, d.Id()).Extract()
if err != nil {
return CheckDeleted(d, err, "Cluster")
return CheckDeleted(d, err, "MRS Cluster")
}
if clusterGet.Clusterstate == "terminated" {
log.Printf("[WARN] The Cluster %s has been terminated.", d.Id())
d.SetId("")
return nil
}

log.Printf("[DEBUG] Retrieved Cluster %s: %#v", d.Id(), clusterGet)
d.SetId(clusterGet.Clusterid)
d.Set("region", GetRegion(d, config))
Expand Down Expand Up @@ -581,9 +599,34 @@ func resourceClusterV1Read(d *schema.ResourceData, meta interface{}) error {
}

d.Set("component_list", components)

// set tags
resourceTags, err := tags.Get(client, "clusters", d.Id()).Extract()
if err != nil {
return fmt.Errorf("Error fetching tags of MRS cluster: %s", err)
}
tagmap := tagsToMap(resourceTags.Tags)
d.Set("tags", tagmap)

return nil
}

func resourceClusterV1Update(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
client, err := config.MrsV1Client(GetRegion(d, config))
if err != nil {
return fmt.Errorf("Error creating HuaweiCloud MRS client: %s", err)
}

// update tags
tagErr := UpdateResourceTags(client, d, "clusters", d.Id())
if tagErr != nil {
return fmt.Errorf("Error updating tags of MRS cluster:%s, err:%s", d.Id(), tagErr)
}

return resourceClusterV1Read(d, meta)
}

func resourceClusterV1Delete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
client, err := config.MrsV1Client(GetRegion(d, config))
Expand Down
27 changes: 27 additions & 0 deletions huaweicloud/resource_huaweicloud_sfs_file_system_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/huaweicloud/golangsdk"
"github.com/huaweicloud/golangsdk/openstack/common/tags"
"github.com/huaweicloud/golangsdk/openstack/sfs/v2/shares"
)

Expand Down Expand Up @@ -83,6 +84,7 @@ func resourceSFSFileSystemV2() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"tags": tagsSchema(),
"enterprise_project_id": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -198,6 +200,15 @@ func resourceSFSFileSystemV2Create(d *schema.ResourceData, meta interface{}) err
d.Set("share_access_id", grant.ID)
}

// create tags
tagRaw := d.Get("tags").(map[string]interface{})
if len(tagRaw) > 0 {
taglist := expandResourceTags(tagRaw)
if tagErr := tags.Create(sfsClient, "sfs", d.Id(), taglist).ExtractErr(); tagErr != nil {
return fmt.Errorf("Error setting tags of sfs %s: %s", d.Id(), tagErr)
}
}

return resourceSFSFileSystemV2Read(d, meta)
}

Expand Down Expand Up @@ -295,6 +306,14 @@ OUTER:
d.Set("status", "unavailable")
}

// set tags
resourceTags, err := tags.Get(sfsClient, "sfs", d.Id()).Extract()
if err != nil {
return fmt.Errorf("Error fetching tags of sfs: %s", err)
}
tagmap := tagsToMap(resourceTags.Tags)
d.Set("tags", tagmap)

return nil
}

Expand Down Expand Up @@ -360,6 +379,14 @@ func resourceSFSFileSystemV2Update(d *schema.ResourceData, meta interface{}) err
}
}

// update tags
if d.HasChange("tags") {
tagErr := UpdateResourceTags(sfsClient, d, "sfs", d.Id())
if tagErr != nil {
return fmt.Errorf("Error updating tags of sfs:%s, err:%s", d.Id(), tagErr)
}
}

return resourceSFSFileSystemV2Read(d, meta)
}

Expand Down
Loading