0

We have three services that we are trying to deploy to a k8s cluster with Terraform helm_release. Each service has something similar to

release.tf

resource "helm_release" "someService" {
  count = var.deploy_apps ? 1 : 0
  name = "someService"
  version = "2.1.3"
  namespace = "app"
  timeout = 600
  values = [yamlencode({
    image = {
      tag = var.terraform_version
    }

    envVars = {
      k8env = local.environment
    }
  })]
}

variables.tf

variable "deploy_apps" {
  type = bool
  default = true
  description = "deploy someService"
}

With the only difference being the service name. Each service is in its own Git repo, each repo has its own variables.tf file which contains its own deploy_apps variable, and they are all deployed to the same namespace.

When any of the services is deployed, it destroys the other two.

How can we prevent that from happening?

Bagaboo
  • 343
  • 3
  • 17
  • That is the only `helm_release` resource you have in your code? Are the other two also relying on the value of the `deploy_apps` variable? – Marko E Aug 02 '22 at 11:13
  • @MarkoE Yes that is correct. In each repo, this is the only helm_release resource. They all have their own deploy_apps variable in their own variables.tf. – Bagaboo Aug 02 '22 at 11:20
  • Can you add that as well to the question? – Marko E Aug 02 '22 at 11:21
  • Sorry, I meant can you add the relevant code to the question. – Marko E Aug 02 '22 at 11:24
  • 1
    My suspicion is that all 3 of your terraform configs/repos are using the same backend for storing state, maybe due to copy-paste? That would cause this issue. – user31601 Aug 02 '22 at 11:34
  • If all repos are using the same variable and value then changing it in one place will have the same effect in other places as well. – Marko E Aug 02 '22 at 11:38
  • Also, I have a feeling that you left out a rather important piece of information and that is how are you using these resources, are they inside of the same file, is a module call required etc. If all the services have the same logical name it could also be an issue with the terraform state as mentioned by the @user31601. – Marko E Aug 02 '22 at 11:42
  • 1
    @user31601 Spot on. I went through the terraform code the it is a copy-paste issue no doubt. Will rectify it. Thank you! – Bagaboo Aug 02 '22 at 13:23

0 Answers0