From dc4352117c129f2de5e6f7cafad5654a1765b868 Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Wed, 25 Nov 2020 16:54:59 +0000 Subject: [PATCH] added cluster state check before proceeding on the node pool activities (#4256) * added cluster state check before proceeding on the node pool actitivies * cluster wait calls added to node pool update, delete and import methods Signed-off-by: Modular Magician --- .changelog/4256.txt | 4 +++ google/resource_container_node_pool.go | 34 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 .changelog/4256.txt diff --git a/.changelog/4256.txt b/.changelog/4256.txt new file mode 100644 index 00000000000..707cce28248 --- /dev/null +++ b/.changelog/4256.txt @@ -0,0 +1,4 @@ +```release-note:enhancement +container : added cluster state check in `resource_container_node_pool` + +``` diff --git a/google/resource_container_node_pool.go b/google/resource_container_node_pool.go index 109d0ddf04f..8d1d1ed1513 100644 --- a/google/resource_container_node_pool.go +++ b/google/resource_container_node_pool.go @@ -324,6 +324,12 @@ func resourceContainerNodePoolCreate(d *schema.ResourceData, meta interface{}) e return err } + //Check cluster is in running state + _, err = containerClusterAwaitRestingState(config, nodePoolInfo.project, nodePoolInfo.location, nodePoolInfo.cluster, userAgent, d.Timeout(schema.TimeoutCreate)) + if err != nil { + return err + } + state, err := containerNodePoolAwaitRestingState(config, d.Id(), nodePoolInfo.project, userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { return err @@ -393,6 +399,12 @@ func resourceContainerNodePoolUpdate(d *schema.ResourceData, meta interface{}) e } name := getNodePoolName(d.Id()) + //Check cluster is in running state + _, err = containerClusterAwaitRestingState(config, nodePoolInfo.project, nodePoolInfo.location, nodePoolInfo.cluster, userAgent, d.Timeout(schema.TimeoutCreate)) + if err != nil { + return err + } + _, err = containerNodePoolAwaitRestingState(config, nodePoolInfo.fullyQualifiedName(name), nodePoolInfo.project, userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err @@ -404,6 +416,11 @@ func resourceContainerNodePoolUpdate(d *schema.ResourceData, meta interface{}) e } d.Partial(false) + //Check cluster is in running state + _, err = containerClusterAwaitRestingState(config, nodePoolInfo.project, nodePoolInfo.location, nodePoolInfo.cluster, userAgent, d.Timeout(schema.TimeoutCreate)) + if err != nil { + return err + } _, err = containerNodePoolAwaitRestingState(config, nodePoolInfo.fullyQualifiedName(name), nodePoolInfo.project, userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err @@ -426,6 +443,12 @@ func resourceContainerNodePoolDelete(d *schema.ResourceData, meta interface{}) e name := getNodePoolName(d.Id()) + //Check cluster is in running state + _, err = containerClusterAwaitRestingState(config, nodePoolInfo.project, nodePoolInfo.location, nodePoolInfo.cluster, userAgent, d.Timeout(schema.TimeoutCreate)) + if err != nil { + return err + } + _, err = containerNodePoolAwaitRestingState(config, nodePoolInfo.fullyQualifiedName(name), nodePoolInfo.project, userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { // If the node pool doesn't get created and then we try to delete it, we get an error, @@ -536,6 +559,17 @@ func resourceContainerNodePoolStateImporter(d *schema.ResourceData, meta interfa return nil, err } + nodePoolInfo, err := extractNodePoolInformation(d, config) + if err != nil { + return nil, err + } + + //Check cluster is in running state + _, err = containerClusterAwaitRestingState(config, nodePoolInfo.project, nodePoolInfo.location, nodePoolInfo.cluster, userAgent, d.Timeout(schema.TimeoutCreate)) + if err != nil { + return nil, err + } + if _, err := containerNodePoolAwaitRestingState(config, d.Id(), project, userAgent, d.Timeout(schema.TimeoutCreate)); err != nil { return nil, err }