func downloadTerraformTemplate() string {
	client := getter.Client{
		Src:  templateURL,
		Dst:  "./" + tempDir,
		Mode: getter.ClientModeAny,
	}
	fmt.Println("downloading terraform template", templateURL)
	err := client.Get()
	check(err)
	debug("done")
	return tempDir
}
fetches and installs the tf template and returns the output directory
package cmd
import (
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"strings"
	getter "github.com/hashicorp/go-getter"
	yaml "gopkg.in/yaml.v2"
)
type scaffoldTemplate struct {
	Base templateDirectory
	Env  templateDirectory
}
type templateDirectory struct {
	Directory     string
	Configuration *templateConfig
	Installed     bool
}
const templateTypeService = "Service"
const templateTypeScheduledTask = "ScheduledTask"
const defaultTemplateType = templateTypeService
const baseDir = "base"
const envDir = "env"
const devDir = "dev"
type templateConfig struct {
	TemplateType string    `yaml:"templateType"`
	Prompts      []*prompt `yaml:"prompts"`
}
type prompt struct {
	Question          string   `yaml:"question"`
	Default           string   `yaml:"default"`
	FilesToDeleteIfNo []string `yaml:"filesToDeleteIfNo"`
}
func scaffold(context *scaffoldContext) {
	template := scaffoldInfrastructure(context)
	scaffoldApplication(context, template)
	applyTemplateConfiguration(template.Base)
	applyTemplateConfiguration(template.Env)
}
func applyTemplateConfiguration(t templateDirectory) {
	if t.Configuration != nil {
		for _, prompt := range t.Configuration.Prompts {
			response := prompt.Default
			if !yesUseDefaults {
				fmt.Println()
				q := fmt.Sprintf("%s (%s) ", prompt.Question, prompt.Default)
				response = promptAndGetResponse(q, prompt.Default)
			}
			yes := containsString(okayResponses, response)
			if !yes && prompt.FilesToDeleteIfNo != nil {
				for _, file := range prompt.FilesToDeleteIfNo {
					p := filepath.Join(t.Directory, file)
					fmt.Println("deleting ", p)
					err := os.Remove(p)
					check(err)
				}
			}
		}
	}
}
func scaffoldInfrastructure(context *scaffoldContext) *scaffoldTemplate {
	templateDir := downloadTerraformTemplate()
	debug("downloaded to:", templateDir)
	result := installTerraformTemplate(templateDir, context.Env)
	debug("environment installed to:", result.Env.Directory)
	if result.Base.Installed {
		debug(fmt.Sprintf("copying %s to %s", varFile, result.Base.Directory))
		targetFile := getTargetVarFile(context.Format)
		err := copyFile(varFile, filepath.Join(result.Base.Directory, targetFile))
		check(err)
	}
	debug(fmt.Sprintf("copying %s to %s", varFile, result.Env.Directory))
	targetFile := getTargetVarFile(context.Format)
	err := copyFile(varFile, filepath.Join(result.Env.Directory, targetFile))
	check(err)
	transformMainTFToContext(result.Env.Directory, context.Profile, context.App, context.Env, context.Region)
	return result
}
func transformMainTFToContext(dir string, profile string, app string, env string, region string) {
	mainTfFile := filepath.Join(dir, "main.tf")
	fileBits, err := ioutil.ReadFile(mainTfFile)
	check(err)
	maintf := updateTerraformBackend(string(fileBits), profile, app, env, region)
	err = ioutil.WriteFile(mainTfFile, []byte(maintf), 0644)
	check(err)
}