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 }