terraform-google-modules / terraform-google-gcloud

Executes Google Cloud CLI commands within Terraform
https://registry.terraform.io/modules/terraform-google-modules/gcloud/google
Apache License 2.0
138 stars 93 forks source link

Pipe character in destroy command incorrectly interpreted #106

Closed debakkerb closed 2 years ago

debakkerb commented 2 years ago

I'm using the kubectl-wrapper to install ECK (operator and CRDs). According to the documentation, the way to delete the operator is to run both of these commands:

kubectl get namespaces --no-headers -o custom-columns=:metadata.name | xargs -n1 kubectl delete elastic --all -n 

kubectl delete -f https://download.elastic.co/downloads/eck/1.8.0/operator.yaml

The problem is that when you introduce this as one command in kubectl_destroy_command, Terraform cuts off everything after the pipe character. Any recommendations on how to solve this?

module "deploy_eck_operator" {
  source  = "terraform-google-modules/gcloud/google//modules/kubectl-wrapper"

  project_id              = local.project.project_id
  cluster_name            = module.gke_cluster.name
  cluster_location        = var.region
  kubectl_create_command  = "kubectl apply -f https://download.elastic.co/downloads/eck/1.8.0/operator.yaml"
  kubectl_destroy_command = "kubectl get namespaces --no-headers -o custom-columns=:metadata.name | xargs -n1 kubectl delete elastic --all -n && kubectl delete -f https://download.elastic.co/downloads/eck/1.8.0/operator.yaml"
  skip_download           = true
  upgrade                 = false
}

When I run terraform destroy -auto-approve, it times out. When I look at the output for the kubectl-wrapper, I can see this:

module.deploy_eck_operator.module.gcloud_kubectl.null_resource.run_destroy_command[0] (local-exec): Fetching cluster endpoint and auth data.
module.deploy_eck_operator.module.gcloud_kubectl.null_resource.run_destroy_command[0] (local-exec): kubeconfig entry generated for elastic-search-cluster.
module.deploy_eck_operator.module.gcloud_kubectl.null_resource.run_destroy_command[0] (local-exec): + kubectl get namespaces --no-headers -o custom-columns=:metadata.name
module.deploy_eck_operator.module.gcloud_kubectl.null_resource.run_destroy_command[0]: Still destroying... [id=5726237551751552069, 10s elapsed]
bharathkkb commented 2 years ago

This may have something to do with the way we do expansion. Could you try putting that command in a script and running the script as kubectl_destroy_command?

debakkerb commented 2 years ago

Thanks, I changed our code and pushed everything into a shell script. When I run that, I can't see the same behaviour anymore.