github.com/pluralsh/plural-cli@v0.9.5/cmd/plural/up.go (about)

     1  package plural
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/urfave/cli"
     7  
     8  	"github.com/pluralsh/plural-cli/pkg/up"
     9  	"github.com/pluralsh/plural-cli/pkg/utils"
    10  	"github.com/pluralsh/plural-cli/pkg/utils/git"
    11  )
    12  
    13  const (
    14  	affirmUp   = "Are you ready to set up your initial management cluster?  You can check the generated terraform/helm to confirm everything looks good first"
    15  	affirmDown = "Are you ready to destroy your plural infrastructure?  This will destroy all k8s clusters and any data stored within"
    16  )
    17  
    18  func (p *Plural) handleUp(c *cli.Context) error {
    19  	// provider.IgnoreProviders([]string{"GENERIC", "KIND"})
    20  	if err := p.handleInit(c); err != nil {
    21  		return err
    22  	}
    23  	p.InitPluralClient()
    24  
    25  	repoRoot, err := git.Root()
    26  	if err != nil {
    27  		return err
    28  	}
    29  
    30  	ctx, err := up.Build()
    31  	if err != nil {
    32  		return err
    33  	}
    34  
    35  	if err := ctx.Backfill(); err != nil {
    36  		return err
    37  	}
    38  
    39  	if err := ctx.Generate(); err != nil {
    40  		return err
    41  	}
    42  
    43  	if !affirm(affirmUp, "PLURAL_UP_AFFIRM_DEPLOY") {
    44  		return fmt.Errorf("cancelled deploy")
    45  	}
    46  
    47  	if err := ctx.Deploy(func() error {
    48  		utils.Highlight("\n==> Commit and push your configuration\n\n")
    49  		if commit := commitMsg(c); commit != "" {
    50  			utils.Highlight("Pushing upstream...\n")
    51  			return git.Sync(repoRoot, commit, c.Bool("force"))
    52  		}
    53  		return nil
    54  	}); err != nil {
    55  		return err
    56  	}
    57  
    58  	return nil
    59  }
    60  
    61  func (p *Plural) handleDown(c *cli.Context) error {
    62  	if !affirm(affirmDown, "PLURAL_DOWN_AFFIRM_DESTROY") {
    63  		return fmt.Errorf("cancelled destroy")
    64  	}
    65  
    66  	ctx, err := up.Build()
    67  	if err != nil {
    68  		return err
    69  	}
    70  
    71  	return ctx.Destroy()
    72  }