<p>I deployed k8s cluster on bare metal using terraform following <a href="https://github.com/packet-labs/kubernetes-bgp/blob/master/nodes.tf" rel="nofollow noreferrer">this repository on github</a></p>

<p>Now I have three nodes: </p>

<p><strong><em>ewr1-controller, ewr1-worker-0, ewr1-worker-1</em></strong></p>

<p>Next, I would like to run terraform apply and increment the worker nodes (<strong>*ewr1-worker-3, ewr1-worker-4 ... *</strong>) while keeping the existing controller and worker nodes.
I tried incrementing the count.index to start from 3, however it still overwrites the existing workers.</p>

<pre><code>resource "packet_device" "k8s_workers" {
  project_id       = "${packet_project.kubenet.id}"
  facilities       = "${var.facilities}"
  count            = "${var.worker_count}"
  plan             = "${var.worker_plan}"
  operating_system = "ubuntu_16_04"
  hostname         = "${format("%s-%s-%d", "${var.facilities[0]}", "worker", count.index+3)}"
  billing_cycle    = "hourly"
  tags             = ["kubernetes", "k8s", "worker"]
} 
</code></pre>

<p>I havent tried this but if I do  </p>

<pre><code>terraform state rm 'packet_device.k8s_workers'
</code></pre>

<p>I am assuming these worker nodes will not be managed by the kubernetes master. I don't want to create all the nodes at beginning because the worker nodes that I am adding will have different specs(instance types).</p>

<p>The entire script I used is available here on <a href="https://github.com/packet-labs/kubernetes-bgp" rel="nofollow noreferrer">this github repository</a>.
I appreciate it if someone could tell what I am missing here and how to achieve this. </p>

<p>Thanks!</p>

<p>Node resizing is best addressed using an autoscaler. Using Terraform to scale a nodepool might not be the optimal approach as the tool is meant to declare the state of the system rather than dynamically change it.  The best approach for this is to use a cloud auto scaler.
In bare metal, you can implement a <code>CloudProvider interface</code> (like the one provided by cloud such as AWS, GCP, Azure)  as described <a href="https://github.com/kubernetes/autoscaler/issues/953" rel="nofollow noreferrer">here</a></p>

<p>After implementing that, you need to determine if your K8s implementation can be <a href="https://stackoverflow.com/a/45803656/10892354">operated as a provider by Terraform</a>, and if that's the case, find the nodepool <code>autoscaler</code> resource that allows the <code>autoscaling</code>.</p>

<p>Wrapping up, Terraform is not meant to be used as an <code>autoscaler</code> given its natures as a declarative language that describes the infrastructure.</p>

<p>The <a href="https://github.com/kubernetes/autoscaler/tree/master/cluster-autoscaler#introduction" rel="nofollow noreferrer">autoscaling features</a> in K8s are meant to tackle this kind of requirements.</p>
