diff --git a/flexibleengine/resource_flexibleengine_cce_node_v3.go b/flexibleengine/resource_flexibleengine_cce_node_v3.go index 7217dcf32..a4d301c99 100644 --- a/flexibleengine/resource_flexibleengine_cce_node_v3.go +++ b/flexibleengine/resource_flexibleengine_cce_node_v3.go @@ -14,6 +14,7 @@ import ( "github.com/huaweicloud/golangsdk" "github.com/huaweicloud/golangsdk/openstack/cce/v3/clusters" "github.com/huaweicloud/golangsdk/openstack/cce/v3/nodes" + "github.com/huaweicloud/golangsdk/openstack/common/tags" ) func resourceCCENodeV3() *schema.Resource { @@ -56,11 +57,19 @@ func resourceCCENodeV3() *schema.Resource { Optional: true, Computed: true, }, - "labels": { + "labels": { //(k8s_tags) Type: schema.TypeMap, Optional: true, ForceNew: true, }, + "tags": { + Type: schema.TypeMap, + Optional: true, + }, + "server_id": { + Type: schema.TypeString, + Computed: true, + }, "annotations": { Type: schema.TypeMap, Optional: true, @@ -245,13 +254,6 @@ func resourceCCENodeV3() *schema.Resource { } } -func resourceCCENodeLabelsV2(d *schema.ResourceData) map[string]string { - m := make(map[string]string) - for key, val := range d.Get("labels").(map[string]interface{}) { - m[key] = val.(string) - } - return m -} func resourceCCENodeAnnotationsV2(d *schema.ResourceData) map[string]string { m := make(map[string]string) for key, val := range d.Get("annotations").(map[string]interface{}) { @@ -290,6 +292,20 @@ func resourceCCEEipIDs(d *schema.ResourceData) []string { } return id } + +func resourceCCENodeK8sTags(d *schema.ResourceData) map[string]string { + m := make(map[string]string) + for key, val := range d.Get("labels").(map[string]interface{}) { + m[key] = val.(string) + } + return m +} + +func resourceCCENodeUserTags(d *schema.ResourceData) []tags.ResourceTag { + tagRaw := d.Get("tags").(map[string]interface{}) + return expandResourceTags(tagRaw) +} + func resourceCCENodeV3Create(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) nodeClient, err := config.cceV3Client(GetRegion(d, config)) @@ -310,7 +326,6 @@ func resourceCCENodeV3Create(d *schema.ResourceData, meta interface{}) error { ApiVersion: "v3", Metadata: nodes.CreateMetaData{ Name: d.Get("name").(string), - Labels: resourceCCENodeLabelsV2(d), Annotations: resourceCCENodeAnnotationsV2(d), }, Spec: nodes.Spec{ @@ -320,6 +335,8 @@ func resourceCCENodeV3Create(d *schema.ResourceData, meta interface{}) error { Login: nodes.LoginSpec{SshKey: d.Get("key_pair").(string)}, RootVolume: resourceCCERootVolume(d), DataVolumes: resourceCCEDataVolume(d), + UserTags: resourceCCENodeUserTags(d), + K8sTags: resourceCCENodeK8sTags(d), PublicIP: nodes.PublicIPSpec{ Ids: resourceCCEEipIDs(d), Count: d.Get("eip_count").(int), @@ -475,6 +492,27 @@ func resourceCCENodeV3Read(d *schema.ResourceData, meta interface{}) error { d.Set("private_ip", s.Status.PrivateIP) d.Set("public_ip", s.Status.PublicIP) + serverId := s.Status.ServerID + d.Set("server_id", serverId) + + // fetch tags from ECS instance + computeClient, err := config.loadECSV1Client(GetRegion(d, config)) + if err != nil { + return fmt.Errorf("Error creating Flexibleengine compute client: %s", err) + } + + resourceTags, err := tags.Get(computeClient, "servers", serverId).Extract() + if err != nil { + return fmt.Errorf("Error fetching Flexibleengine instance tags: %s", err) + } + + tagmap := tagsToMap(resourceTags.Tags) + //ignore "CCE-Dynamic-Provisioning-Node" + delete(tagmap, "CCE-Dynamic-Provisioning-Node") + if err := d.Set("tags", tagmap); err != nil { + return fmt.Errorf("Error saving tags of cce node: %s", err) + } + return nil } @@ -489,14 +527,27 @@ func resourceCCENodeV3Update(d *schema.ResourceData, meta interface{}) error { if d.HasChange("name") { updateOpts.Metadata.Name = d.Get("name").(string) - } - clusterid := d.Get("cluster_id").(string) - _, err = nodes.Update(nodeClient, clusterid, d.Id(), updateOpts).Extract() - if err != nil { - return fmt.Errorf("Error updating flexibleengine Node: %s", err) + clusterid := d.Get("cluster_id").(string) + _, err = nodes.Update(nodeClient, clusterid, d.Id(), updateOpts).Extract() + if err != nil { + return fmt.Errorf("Error updating flexibleengine Node: %s", err) + } } + // update tags + if d.HasChange("tags") { + computeClient, err := config.loadECSV1Client(GetRegion(d, config)) + if err != nil { + return fmt.Errorf("Error creating Flexibleengine compute client: %s", err) + } + + serverId := d.Get("server_id").(string) + tagErr := UpdateResourceTags(computeClient, d, "servers", serverId) + if tagErr != nil { + return fmt.Errorf("Error updateing tags of cce node %s: %s", d.Id(), tagErr) + } + } return resourceCCENodeV3Read(d, meta) } diff --git a/flexibleengine/resource_flexibleengine_css_cluster_v1.go b/flexibleengine/resource_flexibleengine_css_cluster_v1.go index 7c9e7eab9..f8ca1a1c9 100644 --- a/flexibleengine/resource_flexibleengine_css_cluster_v1.go +++ b/flexibleengine/resource_flexibleengine_css_cluster_v1.go @@ -392,7 +392,7 @@ func resourceCssClusterV1Update(d *schema.ResourceData, meta interface{}) error } if d.HasChange("tags") { - tagErr := UpdateResourceTags(client, d, "css-cluster") + tagErr := UpdateResourceTags(client, d, "css-cluster", d.Id()) if tagErr != nil { return fmt.Errorf("Error updating tags of CSS cluster:%s, err:%s", d.Id(), tagErr) } diff --git a/flexibleengine/tags.go b/flexibleengine/tags.go index 353dc0fb2..a40c05812 100644 --- a/flexibleengine/tags.go +++ b/flexibleengine/tags.go @@ -17,7 +17,7 @@ func tagsSchema() *schema.Schema { // UpdateResourceTags is a helper to update the tags for a resource. // It expects the tags field to be named "tags" -func UpdateResourceTags(conn *golangsdk.ServiceClient, d *schema.ResourceData, resourceType string) error { +func UpdateResourceTags(conn *golangsdk.ServiceClient, d *schema.ResourceData, resourceType, id string) error { if d.HasChange("tags") { oRaw, nRaw := d.GetChange("tags") oMap := oRaw.(map[string]interface{}) @@ -26,7 +26,7 @@ func UpdateResourceTags(conn *golangsdk.ServiceClient, d *schema.ResourceData, r // remove old tags if len(oMap) > 0 { taglist := expandResourceTags(oMap) - err := tags.Delete(conn, resourceType, d.Id(), taglist).ExtractErr() + err := tags.Delete(conn, resourceType, id, taglist).ExtractErr() if err != nil { return err } @@ -35,7 +35,7 @@ func UpdateResourceTags(conn *golangsdk.ServiceClient, d *schema.ResourceData, r // set new tags if len(nMap) > 0 { taglist := expandResourceTags(nMap) - err := tags.Create(conn, resourceType, d.Id(), taglist).ExtractErr() + err := tags.Create(conn, resourceType, id, taglist).ExtractErr() if err != nil { return err } diff --git a/go.mod b/go.mod index 5fe0ff6fc..0d2ba2f42 100644 --- a/go.mod +++ b/go.mod @@ -1,12 +1,14 @@ module github.com/terraform-providers/terraform-provider-flexibleengine +go 1.14 + require ( github.com/aws/aws-sdk-go v1.22.0 github.com/hashicorp/errwrap v1.0.0 github.com/hashicorp/go-cleanhttp v0.5.1 github.com/hashicorp/go-multierror v1.0.0 github.com/hashicorp/terraform-plugin-sdk v1.0.0 - github.com/huaweicloud/golangsdk v0.0.0-20200901024739-8d01f23cf75e + github.com/huaweicloud/golangsdk v0.0.0-20201013050319-683f75dc8263 github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a github.com/jtolds/gls v4.20.0+incompatible // indirect github.com/mitchellh/go-homedir v1.1.0 diff --git a/go.sum b/go.sum index d6df68656..90ccde21b 100644 --- a/go.sum +++ b/go.sum @@ -121,20 +121,8 @@ github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKe github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ= github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/huaweicloud/golangsdk v0.0.0-20200514023300-6a3455c8bf4f h1:CGRXQmJk5T7FMfKiJKQhRVRnxJvKCyQ2KZjoWfaN88s= -github.com/huaweicloud/golangsdk v0.0.0-20200514023300-6a3455c8bf4f/go.mod h1:WQBcHRNX9shz3928lWEvstQJtAtYI7ks6XlgtRT9Tcw= -github.com/huaweicloud/golangsdk v0.0.0-20200706081112-ca97f4502e33 h1:ZIk5YmC7v05x+HoQZksJI95PK6hs9t2VBta+8qPEu+A= -github.com/huaweicloud/golangsdk v0.0.0-20200706081112-ca97f4502e33/go.mod h1:WQBcHRNX9shz3928lWEvstQJtAtYI7ks6XlgtRT9Tcw= -github.com/huaweicloud/golangsdk v0.0.0-20200715023612-8da2d504ff78 h1:HF4ahjN+FUAmdBAVtCgQF2lQS7ClX6FUxKeMlSlIv1M= -github.com/huaweicloud/golangsdk v0.0.0-20200715023612-8da2d504ff78/go.mod h1:WQBcHRNX9shz3928lWEvstQJtAtYI7ks6XlgtRT9Tcw= -github.com/huaweicloud/golangsdk v0.0.0-20200725024337-bef093aea95e h1:v8VaVyyiDDRYiMYj/ywbGhaCv8UZwRQ3tabSGX8cit4= -github.com/huaweicloud/golangsdk v0.0.0-20200725024337-bef093aea95e/go.mod h1:WQBcHRNX9shz3928lWEvstQJtAtYI7ks6XlgtRT9Tcw= -github.com/huaweicloud/golangsdk v0.0.0-20200725094037-6532743262f0 h1:ZIG/cjRR5ir0JP1R88tKcW/QERqeIqJE5f8YSo38kPI= -github.com/huaweicloud/golangsdk v0.0.0-20200725094037-6532743262f0/go.mod h1:WQBcHRNX9shz3928lWEvstQJtAtYI7ks6XlgtRT9Tcw= -github.com/huaweicloud/golangsdk v0.0.0-20200818112044-35329fdf4d04 h1:mrqU5znCeRRcN4CInII8AOlDpqWd407Gaw3w1cu71Hs= -github.com/huaweicloud/golangsdk v0.0.0-20200818112044-35329fdf4d04/go.mod h1:WQBcHRNX9shz3928lWEvstQJtAtYI7ks6XlgtRT9Tcw= -github.com/huaweicloud/golangsdk v0.0.0-20200901024739-8d01f23cf75e h1:wvr6UKMzpbGlQfr+ua8rK1g2vCSbEKqF09+MoEHV3O4= -github.com/huaweicloud/golangsdk v0.0.0-20200901024739-8d01f23cf75e/go.mod h1:WQBcHRNX9shz3928lWEvstQJtAtYI7ks6XlgtRT9Tcw= +github.com/huaweicloud/golangsdk v0.0.0-20201013050319-683f75dc8263 h1:PaCpxjILNlQJkHqbETpTqjbcejjlphCeYMcxWAVnxKk= +github.com/huaweicloud/golangsdk v0.0.0-20201013050319-683f75dc8263/go.mod h1:WQBcHRNX9shz3928lWEvstQJtAtYI7ks6XlgtRT9Tcw= github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a h1:FyS/ubzBR5xJlnJGRTwe7GUHpJOR4ukYK3y+LFNffuA= github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a/go.mod h1:uoIMjNxUfXi48Ci40IXkPRbghZ1vbti6v9LCbNqRgHY= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/cce/v3/nodes/results.go b/vendor/github.com/huaweicloud/golangsdk/openstack/cce/v3/nodes/results.go index 6534e2caf..cd80ea839 100644 --- a/vendor/github.com/huaweicloud/golangsdk/openstack/cce/v3/nodes/results.go +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/cce/v3/nodes/results.go @@ -2,6 +2,7 @@ package nodes import ( "github.com/huaweicloud/golangsdk" + "github.com/huaweicloud/golangsdk/openstack/common/tags" ) //Describes the Node Structure of cluster @@ -40,7 +41,7 @@ type Metadata struct { Annotations map[string]string `json:"annotations,omitempty"` } -// Describes Nodes specification +// Spec describes Nodes specification type Spec struct { // Node specifications Flavor string `json:"flavor" required:"true"` @@ -48,6 +49,8 @@ type Spec struct { Az string `json:"az" required:"true"` // The OS of the node Os string `json:"os,omitempty"` + // ID of the dedicated host to which nodes will be scheduled + DedicatedHostID string `json:"dedicatedHostId,omitempty"` // Node login parameters Login LoginSpec `json:"login" required:"true"` // System disk parameter of the node @@ -60,8 +63,38 @@ type Spec struct { BillingMode int `json:"billingMode,omitempty"` // Number of nodes when creating in batch Count int `json:"count" required:"true"` + // The node nic spec + NodeNicSpec NodeNicSpec `json:"nodeNicSpec,omitempty"` // Extended parameter ExtendParam ExtendParam `json:"extendParam,omitempty"` + // UUID of an ECS group + EcsGroupID string `json:"ecsGroupId,omitempty"` + // Tag of a VM, key value pair format + UserTags []tags.ResourceTag `json:"userTags,omitempty"` + // Tag of a Kubernetes node, key value pair format + K8sTags map[string]string `json:"k8sTags,omitempty"` + // taints to created nodes to configure anti-affinity + Taints []TaintSpec `json:"taints,omitempty"` +} + +// Gives the Nic spec of the node +type NodeNicSpec struct { + // The primary Nic of the Node + PrimaryNic PrimaryNic `json:"primaryNic,omitempty"` +} + +// Gives the Primary Nic of the node +type PrimaryNic struct { + // The Subnet ID of the primary Nic + SubnetId string `json:"subnetId,omitempty"` +} + +// TaintSpec to created nodes to configure anti-affinity +type TaintSpec struct { + Key string `json:"key" required:"true"` + Value string `json:"value" required:"true"` + // Available options are NoSchedule, PreferNoSchedule, and NoExecute + Effect string `json:"effect" required:"true"` } // Gives the current status of the node diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/client.go b/vendor/github.com/huaweicloud/golangsdk/openstack/client.go index 203c799ec..e6440b02c 100644 --- a/vendor/github.com/huaweicloud/golangsdk/openstack/client.go +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/client.go @@ -792,6 +792,14 @@ func NewCCEV3(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*gol return sc, err } +func NewCCEAddonV3(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) { + sc, err := initClientOpts(client, eo, "network") + sc.Endpoint = strings.Replace(sc.Endpoint, "vpc", "cce", 1) + sc.Endpoint = strings.Replace(sc.Endpoint, "myhwclouds", "myhuaweicloud", 1) + sc.ResourceBase = sc.Endpoint + "api/v3/" + return sc, err +} + // NewDMSServiceV1 creates a ServiceClient that may be used to access the v1 Distributed Message Service. func NewDMSServiceV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) { sc, err := initClientOpts(client, eo, "network") diff --git a/vendor/modules.txt b/vendor/modules.txt index 303c04d8d..8d454315c 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -183,7 +183,7 @@ github.com/hashicorp/terraform-plugin-sdk/plugin github.com/hashicorp/terraform-plugin-sdk/terraform # github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d github.com/hashicorp/yamux -# github.com/huaweicloud/golangsdk v0.0.0-20200901024739-8d01f23cf75e +# github.com/huaweicloud/golangsdk v0.0.0-20201013050319-683f75dc8263 ## explicit github.com/huaweicloud/golangsdk github.com/huaweicloud/golangsdk/internal diff --git a/website/docs/r/cce_nodes_v3.html.md b/website/docs/r/cce_nodes_v3.html.md index eaf163473..c9f8e1e77 100644 --- a/website/docs/r/cce_nodes_v3.html.md +++ b/website/docs/r/cce_nodes_v3.html.md @@ -45,7 +45,9 @@ The following arguments are supported: * `name` - (Optional) Node Name. -* `labels` - (Optional) Node tag, key/value pair format. Changing this parameter will create a new resource. +* `labels` - (Optional) Tags of a Kubernetes node, key/value pair format. Changing this parameter will create a new resource. + +* `tags` - (Optional) VM tag, key/value pair format. * `annotations` - (Optional) Node annotation, key/value pair format. Changing this parameter will create a new resource.