'How can I migrate an ingress from an helm chart to terraform without deleting the resource during deployment

I have a custom application helm chart with an ingress object which is deployed in production. Now I need to migrate the ingress source code object from the helm chart to terraform to give control over the object to another team. Technically no problem with accepting a downtime. But I want to keep the ingress object from being undeployed by the helm chart during deployment as there is a letsencrypt certificate attached to it.

So is there a possibility to tell helm to keep the ingress object when I remove the ingress in the source of the helm chart during helm upgrade?



Solution 1:[1]

found the answer myself in the helm anntotations. https://helm.sh/docs/howto/charts_tips_and_tricks/#tell-helm-not-to-uninstall-a-resource

That mean's you deploy the ingress again via helm chart with the annotation "helm.sh/resource-policy": keep. Then you remove the ingress from the helm chart and redeploy it. Now the ingress is still deployed in kubernetes but not anymore under control of the helm release. Next step is to model/code the ingress in terraform and import the resource via terraform import. Last step is to test with terraform plan if the imported resource corresponds completely with the coded ingress in terraform

That's it.

Solution 2:[2]

You can just keep the helm chart as it is and add details into the terraform, I think it will work.

Terraform will run the plan and apply the helm release and if you set helm config to roll out, in that case, if No changes there no update will get applied to resources like ingress, deployment etc.

With terraform, you can use the Helm provider: https://registry.terraform.io/providers/hashicorp/helm/latest/docs

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Harsh Manvar