diff --git a/pkg/client/plural.go b/pkg/client/plural.go index 538405a0..d476e859 100644 --- a/pkg/client/plural.go +++ b/pkg/client/plural.go @@ -107,7 +107,7 @@ func (p *Plural) HandleInit(c *cli.Context) error { if err != nil { return err } - if proj.Network.PluralDns { + if proj.Network != nil && proj.Network.PluralDns { if err := p.Client.CreateDomain(proj.Network.Subdomain); err != nil { return err } diff --git a/pkg/up/deploy.go b/pkg/up/deploy.go index 7f85ba3c..58301301 100644 --- a/pkg/up/deploy.go +++ b/pkg/up/deploy.go @@ -80,6 +80,7 @@ func (ctx *Context) Deploy(commit func() error) error { utils.Highlight("\nSetting up gitops management...\n") if err := runAll([]terraformCmd{ + {dir: "./terraform/mgmt", cmd: "apply", args: []string{"-auto-approve"}}, {dir: "./terraform/apps", cmd: "init", args: []string{"-upgrade"}}, {dir: "./terraform/apps", cmd: "apply", args: []string{"-auto-approve"}, retries: 1}, }); err != nil { diff --git a/pkg/up/generate.go b/pkg/up/generate.go index 7ae2dff8..20d0eea2 100644 --- a/pkg/up/generate.go +++ b/pkg/up/generate.go @@ -64,6 +64,7 @@ func (ctx *Context) Generate() (dir string, err error) { copies := []templatePair{ {from: ctx.path("terraform/modules/clusters"), to: "terraform/modules/clusters"}, {from: ctx.path(fmt.Sprintf("terraform/clouds/%s", prov)), to: "terraform/mgmt/cluster"}, + {from: ctx.path(fmt.Sprintf("terraform/core-infra/%s", prov)), to: "terraform/core-infra"}, {from: ctx.path("setup"), to: "bootstrap"}, {from: ctx.path("templates"), to: "templates"}, {from: ctx.path("resources"), to: "resources"}, @@ -136,6 +137,28 @@ func (ctx *Context) afterSetup() error { } } + redacts := []templatePair{ + {from: "./terraform/mgmt/provider.tf"}, + } + + for _, redact := range redacts { + if err := ctx.redact(redact.from); err != nil { + return err + } + } + + uncomments := []templatePair{ + {from: "./terraform/mgmt/cluster/eks.tf"}, + } + + for _, uncomment := range uncomments { + if utils.Exists(uncomment.from) { + if err := ctx.uncomment(uncomment.from); err != nil { + return err + } + } + } + return nil } diff --git a/pkg/up/prune.go b/pkg/up/prune.go index 0ee52c07..27314b78 100644 --- a/pkg/up/prune.go +++ b/pkg/up/prune.go @@ -10,7 +10,7 @@ import ( func (ctx *Context) Prune() error { if ctx.Cloud { - return nil + return ctx.pruneCloud() } utils.Highlight("\nCleaning up unneeded resources...\n\n") @@ -42,6 +42,18 @@ func (ctx *Context) Prune() error { return git.Sync(repoRoot, "Post-setup resource cleanup", true) } +func (ctx *Context) pruneCloud() error { + utils.Highlight("\nCleaning up unneeded resources...\n\n") + repoRoot, err := git.Root() + if err != nil { + return err + } + + _ = os.RemoveAll("./terraform/apps") + + return git.Sync(repoRoot, "Post-setup resource cleanup", true) +} + func stateRm(dir, field string) error { cmd := exec.Command("terraform", "state", "rm", field) cmd.Dir = dir diff --git a/pkg/up/template.go b/pkg/up/template.go index 0beb2683..151f8e62 100644 --- a/pkg/up/template.go +++ b/pkg/up/template.go @@ -2,6 +2,7 @@ package up import ( "bytes" + "regexp" "text/template" "time" @@ -10,6 +11,24 @@ import ( "github.com/pluralsh/polly/retry" ) +func (ctx *Context) redact(file string) error { + buf, err := utils.ReadFile(file) + if err != nil { + return err + } + re := regexp.MustCompile(`(?msU)# BEGIN REMOVE(.*)# END REMOVE`) + return utils.WriteFile(file, []byte(re.ReplaceAllString(buf, ""))) +} + +func (ctx *Context) uncomment(file string) error { + buf, err := utils.ReadFile(file) + if err != nil { + return err + } + re := regexp.MustCompile(`# UNCOMMENT\s+`) + return utils.WriteFile(file, []byte(re.ReplaceAllString(buf, ""))) +} + func (ctx *Context) templateFrom(file, to string) error { buf, err := utils.ReadFile(file) if err != nil {