Coder.comC
Coder.com3y ago
11 replies
Sharp

null_resource/local-exec provisioning

Hey folks, I am trying to get Coder to run a workspace through a slurm job.

This is what I have so far.

resource "null_resource" "coder_slurm_job" {
  provisioner "local-exec" {
    command = <<EOT
      # SSH into the Slurm cluster's head node
      # Save the private key to a temporary file
      echo "${var.encoded_ssh_private_key}" | base64 -d > /tmp/temp_ssh_key
      chmod 600 /tmp/temp_ssh_key

      # SSH into the Slurm cluster's head node using the private key
      ssh -o StrictHostKeyChecking=no -i /tmp/temp_ssh_key amcarth1@narval.alliancecan.ca <<'ENDSSH'

        echo DIR=~/projects/def-jjaremko/amcarth1/test/
        cd $DIR

        export BINARY_NAME=coder
        export BINARY_URL=https://coder.mcaq.me/bin/coder-linux-amd64
        curl -fsSL --compressed $BINARY_URL -o $BINARY_NAME

        chmod u+x coder.sh
        chmod u+x $BINARY_NAME

        # Create a temporary Slurm job script
        cat > $DIR/coder_slurm_job.sh <<'ENDSCRIPT'
          #!/usr/bin/env sh
          set -eux
          export CODER_AGENT_AUTH=\"token\"
          export CODER_AGENT_URL=\"https://coder.mcaq.me/\"
          exec ~/projects/def-jjaremko/amcarth1/test/coder agent
        ENDSCRIPT

        # Make the script executable
        chmod u+x $DIR/coder_slurm_job.sh

        salloc --time=1:0:0 --mem=3G --ntasks=1 --cpus-per-task=2 --account=def-jjaremko srun $DIR/coder_slurm_job.sh
      ENDSSH

      # Clean up the temporary private key
      rm -f /tmp/temp_ssh_key
    EOT
  }
}


My problem is I cannot debug why its not working from here, as I get no logs: https://photos.app.goo.gl/9y8oTpZHCQjL63w57

I think I know its logging in, before adding -o StrictHostKeyChecking=no I did get an error. Any advice would be great :))
Google Photos
New item · Album by Adam Mcarthur
msedge_hCoatkJDWh.jpg
Was this page helpful?