Skip to content

Go R1 Day 30

progress🔗

  • Built some go functions for build tasks work with terraform and setup of projects using taskflow.

Learned one one to pass in arguments using slices. I'm pretty sure you can use some stringbuilder type functionality to get similar behavior, but this worked fine for my use case.

cmdParams := []string{}
cmdParams = append(cmdParams, "-chdir="+tfdir)
cmdParams = append(cmdParams, "init")
cmdParams = append(cmdParams, "-input=false")
cmdParams = append(cmdParams, "-backend=true")
cmdParams = append(cmdParams, "-backend-config="+tfconfig)
terraformCmd := tf.Cmd(terraformPath, cmdParams...)
if err := terraformCmd.Run(); err != nil {
  tf.Errorf("â­• terraform init failed: [%v]", err)
  return
}