func TfApply()

in internal/terraform/tf.go [123:163]


func TfApply(
	dir string,
	varFiles []string,
	vars []*Vars,
	targets []string,
	verbose bool,
) error {
	var tfApplyOptions []tfexec.ApplyOption

	// find the binary and setup the client
	ctx := context.Background()

	tf, _ := initializeTerraformClient(dir, verbose)

	// include a var files if they're provided
	for _, v := range varFiles {
		tfApplyOptions = append(tfApplyOptions, tfexec.VarFile(v))
	}

	// load up vars if they're provided
	for _, v := range vars {
		assignment := v.Key + "=" + v.Value
		tfApplyOptions = append(tfApplyOptions, tfexec.Var(assignment))
	}

	// an edge case, but account for specific targets if they're supplied
	for _, t := range targets {
		tfApplyOptions = append(tfApplyOptions, tfexec.Target(t))
	}

	// do what we came here to do
	err := tf.Apply(ctx, tfApplyOptions...) // TODO: tf validate before

	if err != nil {
		return err
	}

	// TODO: return output in case the caller is interested

	return nil
}