in deploystack.go [173:269]
func (m Meta) Suggest() (config.Config, error) {
out := m.DeployStack.Copy()
name := filepath.Base(m.Github.URL())
name = strings.ReplaceAll(name, "deploystack-", "")
title := strings.ReplaceAll(name, "-", " ")
caser := cases.Title(language.AmericanEnglish)
title = caser.String(title)
if m.DeployStack.Name == "" {
out.Name = name
}
if m.DeployStack.Title == "" {
out.Title = title
}
if len(m.Terraform) == 0 {
return out, errors.New("suggest: terraform was empty")
}
if m.DeployStack.PathTerraform == "" {
out.PathTerraform = filepath.Dir(m.Terraform[0].File)
}
resources, err := terraform.NewGCPResources()
if err != nil {
return out, fmt.Errorf("could not get terraform resource meta data: %w", err)
}
for _, v := range m.Terraform {
switch v.Kind {
case "variable":
// For now if there are default values, don't bother capturing
if !v.NoDefault() {
continue
}
switch v.Name {
case "project_id":
out.Project = true
case "project_number":
out.ProjectNumber = true
case "billing_account":
out.BillingAccount = true
case "region":
out.RegionDefault = "us-central1"
out.Region = true
out.RegionType = "compute"
if r := m.Terraform.Search("google_cloud_run", "type"); len(r) > 0 {
out.RegionType = "run"
}
if r := m.Terraform.Search("google_cloudfunctions", "type"); len(r) > 0 {
out.RegionType = "functions"
}
case "zone":
out.Zone = true
default:
checkCustom := out.CustomSettings.Get(v.Name)
checkAuthor := out.AuthorSettings.Find(v.Name)
if checkCustom.Name == "" && checkAuthor == nil {
cust := config.Custom{}
cust.Name = v.Name
cust.Type = v.Type
out.CustomSettings = append(out.CustomSettings, cust)
}
}
case "managed":
product := resources.GetProduct(v.Type)
if product == "" {
continue
}
add := true
for _, v := range out.Products {
if v.Product == product {
add = false
break
}
}
if add {
p := config.Product{Product: product}
out.Products = append(out.Products, p)
}
}
}
return out, nil
}