Skip to content

Commit

Permalink
Adding update support for labels to google_container_node_pool (#6599) (
Browse files Browse the repository at this point in the history
#12773)

Signed-off-by: Modular Magician <magic-modules@google.com>

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Oct 12, 2022
1 parent 60c7932 commit 6eb1805
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/6599.txt
@@ -0,0 +1,3 @@
```release-note:enhancement
container: added support for in-place update of `node_config.0.tags` for `google_container_node_pool` resource
```
1 change: 0 additions & 1 deletion google/node_config.go
Expand Up @@ -268,7 +268,6 @@ func schemaNodeConfig() *schema.Schema {
"tags": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: `The list of instance tags applied to all nodes.`,
},
Expand Down
55 changes: 55 additions & 0 deletions google/resource_container_node_pool.go
Expand Up @@ -910,6 +910,61 @@ func nodePoolUpdate(d *schema.ResourceData, meta interface{}, nodePoolInfo *Node
}

if d.HasChange(prefix + "node_config") {

if d.HasChange(prefix + "node_config.0.tags") {
req := &container.UpdateNodePoolRequest{
Name: name,
}
if v, ok := d.GetOk(prefix + "node_config.0.tags"); ok {
tagsList := v.([]interface{})
tags := []string{}
for _, v := range tagsList {
if v != nil {
tags = append(tags, v.(string))
}
}
ntags := &container.NetworkTags{
Tags: tags,
}
req.Tags = ntags
}

// sets tags to the empty list when user removes a previously defined list of tags entriely
// aka the node pool goes from having tags to no longer having any
if req.Tags == nil {
tags := []string{}
ntags := &container.NetworkTags{
Tags: tags,
}
req.Tags = ntags
}

updateF := func() error {
clusterNodePoolsUpdateCall := config.NewContainerClient(userAgent).Projects.Locations.Clusters.NodePools.Update(nodePoolInfo.fullyQualifiedName(name), req)
if config.UserProjectOverride {
clusterNodePoolsUpdateCall.Header().Add("X-Goog-User-Project", nodePoolInfo.project)
}
op, err := clusterNodePoolsUpdateCall.Do()
if err != nil {
return err
}

// Wait until it's updated
return containerOperationWait(config, op,
nodePoolInfo.project,
nodePoolInfo.location,
"updating GKE node pool tags", userAgent,
timeout)
}

// Call update serially.
if err := lockedCall(lockKey, updateF); err != nil {
return err
}

log.Printf("[INFO] Updated tags for node pool %s", name)
}

if d.HasChange(prefix + "node_config.0.image_type") {
req := &container.UpdateClusterRequest{
Update: &container.ClusterUpdate{
Expand Down
4 changes: 4 additions & 0 deletions google/resource_container_node_pool_test.go
Expand Up @@ -1349,6 +1349,8 @@ resource "google_container_node_pool" "np_with_node_config" {
]
preemptible = true
min_cpu_platform = "Intel Broadwell"
tags = ["ga"]
taint {
key = "taint_key"
Expand Down Expand Up @@ -1394,6 +1396,8 @@ resource "google_container_node_pool" "np_with_node_config" {
preemptible = true
min_cpu_platform = "Intel Broadwell"
tags = ["beta"]
taint {
key = "taint_key"
value = "taint_value"
Expand Down

0 comments on commit 6eb1805

Please sign in to comment.