kubernetesterraform

Using same terraform Project to create the Kubernetes infrastructure and deploy apps


I want to have a terraform project that has 2 modules Infrastructure and App. Is it possible to use the Infrstructure module to create the instances and install Kubernetes and retrieve kube-config file and pass it to the second module to deploy apps?

Is this a good approach ? or do I need to move it to 2 different projects?


Solution

  • While it's technically possible to use a single Terraform project with two modules (Infrastructure and App), this approach may not be ideal. A better approach is to use Terraform to set up the Kubernetes cluster, with the output of this module being a kubeconfig file. You could then use this kubeconfig file with tools that are better suited for application deployment, such as Helm charts, Kustomize, or Argo CD.

    Using Terraform for application deployment leads to complexity in managing resource states. Terraform treats resources as immutable, but Kubernetes resources often require updates (for example rolling deployments), which can conflict with Terraform's model.

    Furthermore, separating your code into two independent workflows will improve security and help you dissociate the application lifecycle from the infrastructure lifecycle, which should have different rhythms in their evolutions.