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

Adding update support for labels to google_container_node_pool #12773

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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