Importing loadbalancer resource into terraform

#1

Hi,

I am using terraform to create a Kapsule cluster. The thing is, since we’re testing things these days, we do a lot of “apply” and “destroy”. However, when creating the loadbalancer via kubernetes, it doesn’t get deleted when the cluster is destroyed.

I thought about importing the loadbalancer so that it becomes a terraform resource, thus deleted after a destroy, but to import the loadbalancer, I need also to import the ip address, which I don’t want to destroy.

I know I can mark the ip reource’s lifecycle to prevent its destruction, but then I get prevented to destroy everything.

Any hint on a good way to keep the IP address but to delete everything so that I can reuse the IP address when I perform a terraform apply again?

Best,

Francis

PS - I created the load balancer following this tutorial: https://www.scaleway.com/en/docs/using-a-load-balancer-to-expose-your-kubernetes-kapsule-ingress-controller-service/

#2

Hey @francis ! The easiest way is to set the loadBalancerIP field on the service, and destroy the service before destroying your cluster.

Cheers,

Patrik

1 Like