Skip to content

Commit

Permalink
Fix imported node pool's scaling issue (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
zulh-civo committed Aug 13, 2021
1 parent 40fc215 commit 8a12399
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
40 changes: 29 additions & 11 deletions civo/resource_kubernetes_cluster_nodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,26 +212,44 @@ func resourceKubernetesClusterNodePoolDelete(d *schema.ResourceData, m interface
// custom import to able to add a node pool to the terraform
func resourceKubernetesClusterNodePoolImport(d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) {
apiClient := m.(*civogo.Client)
regions, err := apiClient.ListRegions()
if err != nil {
return nil, err
}

clusterID, nodePoolID, err := utils.ResourceCommonParseID(d.Id())
if err != nil {
return nil, err
}

log.Printf("[INFO] retriving the node pool %s", nodePoolID)
resp, err := apiClient.GetKubernetesCluster(clusterID)
if err != nil {
if resp != nil {
return nil, err
poolFound := false
for _, region := range regions {
if poolFound {
break
}
}

d.Set("cluster_id", resp.ID)
for _, v := range resp.Pools {
if v.ID == nodePoolID {
d.Set("num_target_nodes", v.Count)
d.Set("target_nodes_size", v.Size)
currentRegionCode := region.Code
apiClient.Region = currentRegionCode
log.Printf("[INFO] Retriving the node pool %s from region %s", nodePoolID, currentRegionCode)
resp, err := apiClient.GetKubernetesCluster(clusterID)
if err != nil {
continue // move on and find in another region
}

for _, v := range resp.Pools {
if v.ID == nodePoolID {
poolFound = true
d.SetId(v.ID)
d.Set("cluster_id", resp.ID)
d.Set("region", currentRegionCode)
d.Set("num_target_nodes", v.Count)
d.Set("target_nodes_size", v.Size)
}
}
}

if !poolFound {
return nil, fmt.Errorf("[ERR] Node pool %s not found", nodePoolID)
}

return []*schema.ResourceData{d}, nil
Expand Down
3 changes: 2 additions & 1 deletion docs/resources/kubernetes_node_pool.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ In addition to the arguments listed above, the following additional attributes a
Then the Kubernetes cluster node pool can be imported using the cluster's and pool id `cluster_id:node_pool_id`, e.g.

```
terraform import civo_kubernetes_node_pool.my-pool 1b8b2100-0e9f-4e8f-ad78-9eb578c2a0af:502c1130-cb9b-4a88-b6d2-307bd96d946a
terraform import civo_kubernetes_node_pool.my-pool 1b8b2100-0e9f-4e8f-ad78-9eb578c2a0af:502c1130-cb9b-4a88-b6d2-307bd96d946a
```

0 comments on commit 8a12399

Please sign in to comment.