<p>I successfully maintain a kubernetes cluster in digital ocean throught terraform. The core cluster configuration is the following:</p>
<pre><code>resource &quot;digitalocean_kubernetes_cluster&quot; &quot;cluster&quot; {
  name     = var.name
  region   = var.region
  version  = var.k8s_version
  vpc_uuid = digitalocean_vpc.network.id

  node_pool {
    name       = &quot;workers&quot;
    size       = var.k8s_worker_size
    node_count = var.k8s_worker_count
  }
}
</code></pre>
<p>The problem is, I now need to increase the node size (stored in the variable <code>k8s_worker_size</code>).</p>
<p>If I simply change the variable to a new string, the terraform plan results in a full replace of the kubernetes cluster:</p>
<pre><code>digitalocean_kubernetes_cluster.cluster must be replaced
</code></pre>
<p>This is not doable in our production environment.</p>
<p>The correct procedure to perform this operation inside digital ocean is to:</p>
<ul>
<li>Create a new node pool, with the required size</li>
<li>Use <code>kubectl drain</code> to remove our pods from the 'old' nodes</li>
<li>Remove the previous node pool.</li>
</ul>
<p>Of course, by doing this manually inside the digital ocean console, the terraform state is completely out-of-sync and is therefore unusable.</p>
<p>Is there a way to perform that operation through terraform?</p>
<p>As an alternative options, is it possible to &quot;manually&quot; update the terraform state in order to sync it with the real cluster state after I perform the migration manually?</p>

<blockquote>
<p>Is there a way to perform that operation through terraform?</p>
</blockquote>
<p>There might be some edge cases where there is a solution to this. Since I am not familiar with kubernetes inside DigitalOcean I can't share a specific solution.</p>
<blockquote>
<p>As an alternative options, is it possible to &quot;manually&quot; update the terraform state in order to sync it with the real cluster state after I perform the migration manually?</p>
</blockquote>
<p>Yes! Do as you proposed manually and then remove the out-of-sync cluster with</p>
<pre><code>terraform state rm digitalocean_kubernetes_cluster.cluster
</code></pre>
<p>from the state. Please visit the corresponding <a href="https://www.terraform.io/docs/cli/commands/state/rm.html" rel="nofollow noreferrer">documentation for state rm</a> and update the address if your cluster is in a module etc. Then use</p>
<pre><code>terraform import digitalocean_kubernetes_cluster.cluster &lt;id of your cluster&gt;
</code></pre>
<p>to reimport the cluster. Please consult the <a href="https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs/resources/kubernetes_cluster#import" rel="nofollow noreferrer">documentation for importing the cluster</a> for the details. The documentations mentions something around tagging the default node pool.</p>
