Skip to content

Go R1 Day 35

progress🔗

  • Worked with Taskflow a bit more.
  • Need to identify better error handling pattern on when to resolve vs handle internal to a function, as it feels like I'm doing needless error checking.
  • Wrote func to run terraform init, plan, and apply.
  • This takes dynamical inputs for vars and backend file.
  • Also dynamically switches terraform versions by running tfswitch.

Definitely more verbose code than powershell, but it's a good way to get used to Go while achieving some useful automation tasks I need to do.

Example of some code for checking terraform path.

func terraformPath(tf *taskflow.TF) (terraformPath string, err error) {
    terraformPath = path.Join(toolsDir, "terraform")
    if _, err := os.Stat(terraformPath); os.IsNotExist(err) {
        tf.Errorf("❗ cannot find terraform at: [%s] -> [%v]", terraformPath, err)
        return "", err
    }
    tf.Logf("✅ found terraform at: [%s]", terraformPath)
    return terraformPath, nil
}
terraformPath, err := terraformPath(tf)
if err != nil {
  tf.Errorf("❗ unable to proceed due to not finding terraform installed [%v]", err)
  return
}

However, once I call this, I'm see more effort in handling, which feels like I'm double double work at times.