Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to update or destroy a terraform when utilizing execution_cmd. #252

Open
jeffellin opened this issue Aug 31, 2023 · 9 comments
Open
Labels
bug Bug

Comments

@jeffellin
Copy link

Describe the bug

 Error: Missing map element
│
│   on main.tf line 4, in module "ubuntu_node":
│    4:   execution_cmd=tanzu-mission-control_cluster.attach_cluster_without_apply.status.execution_cmd
│     ├────────────────
│     │ tanzu-mission-control_cluster.attach_cluster_without_apply.status is map of string with 9 elements
│
│ This map does not have an element with the key "execution_cmd".
This is what I got, thats producing that error.
module "ubuntu_node" {
  source = "../ubuntu_node"
  hostname="tap-run-1"
  execution_cmd=tanzu-mission-control_cluster.attach_cluster_without_apply.status.execution_cmd
}
and in the module
  provisioner "remote-exec" {
      inline = [
        "/bin/bash -c \"timeout 300 sed '/finished-user-data/q' <(tail -f /var/log/cloud-init-output.log)\"",
        "export KUBECONFIG=/home/ubuntu/.kube/config",
        "${var.execution_cmd}"
      ]
}

Reproduction steps

  1. Create a terraform script that provisions an attached cluster
  2. output the execution_cmd to the remote exec provisioner.
  3. Works first time,
  4. Terraform UPDATE or DELETE does not work.
    ...

Expected behavior

rerunning terraform should not result in an error due to missing execution_cmd.

the status map that is returned when looking up the resource does not return this value after the cluster is attached.

workaround for me was to use

lookup(tanzu-mission-control_cluster.attach_cluster_without_apply.status,"execution_cmd","unkown")

If this is working as designed please provide working example of attaching a cluster after provisioning it.

Additional context

No response

@jeffellin jeffellin added the bug Bug label Aug 31, 2023
@vmw-vjn
Copy link

vmw-vjn commented Sep 1, 2023

Hi @jeffellin ,
Could you please share TF script or the portion where-in you're using resource "tanzu-mission-control_cluster" "attach_cluster_without_apply" - for us to be able to debug.

Also, as in docs:

you must have cluster.admin permissions on the cluster and clustergroup.edit permissions in Tanzu Mission Control.

So kindly confirm if the permissions requirements are being met, as well.

@jeffellin
Copy link
Author

@vmw-vjn Here you go.

resource "tanzu-mission-control_cluster" "attach_cluster_without_apply" {
  management_cluster_name = "attached"         # Default: attached
  provisioner_name        = "attached"         # Default: attached
  name                    = "tap-run-1" # Required

  meta {
    description = "create attach cluster from terraform"
    labels      = { "key" : "value" }
  }

  spec {
    cluster_group = "homelab" # Default: default
  }
}

@vmw-vjn
Copy link

vmw-vjn commented Sep 4, 2023

Is the cluster being attached, a Tanzu Kubernetes Grid cluster?
Looking at the error shared, seems to suggest, like the provisioner code is getting triggered and failing as the output isn't as expected. But looking at the shared Terraform snippet, seems like you're following example of attaching existing conformant Kubernetes cluster and for attaching TKG clusters the terraform code would be different.

FYI/FYR: @ramya-bangera

@ramya-bangera
Copy link
Contributor

@jeffellin - I performed the steps in my dev environment and update/destroy worked as expected.

I see that via terraform you trying to attach cluster without applying the manifest. Can you elaborate on what is the UPDATE operation you tried on this resource? Also by delete did you perform terraform destroy ?

@ramya-bangera
Copy link
Contributor

@jeffellin - Any update on the previous comment?

@jeffellin
Copy link
Author

This use case is attaching a conformant cluster. I use the execution_cmd to run a remote exec command on the cluster and apply the appropriate yaml to attach the cluster. The issue I am having is if I use terraform update to change something not related to the attachment. e.g. the cluster node size I get the error. And yes delete means terraform destroy

@jeffellin
Copy link
Author

provisioner "remote-exec" { inline = [ "/bin/bash -c \"timeout 300 sed '/finished-user-data/q' <(tail -f /var/log/cloud-init-output.log)\"", "export KUBECONFIG=/home/ubuntu/.kube/config", "${var.execution_cmd}" ] }

This is how I am onboarding the cluster, using this within the creation of the control plane node.

@ramya-bangera ramya-bangera self-assigned this Oct 16, 2023
@ramya-bangera
Copy link
Contributor

@jeffellin - While we look into this, your usecase is to attach the cluster and to apply the execution_cmd on that cluster. So can you use the same resource by providing the kubeconfig so that provider takes care of attaching the cluster?

Is there a specific reason why you are trying to attach without apply?

@jeffellin
Copy link
Author

I'm not sure I follow is there another action that can attach and apply in the same pass? I think I was working with a sample from the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug
Projects
None yet
Development

No branches or pull requests

4 participants