foundation

package
v1.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	FoundationCreate  = *FoundationCmd
	FoundationDestroy = *FoundationCmd //TODO no destroy equivalent for foundation
)

Set up pointers to support multiple distinct parents

View Source
var FoundationCmd = &cobra.Command{
	Use:   "foundation",
	Short: "Deploy a foundation-only pasture with no blueprints",
	Long: "Creates a foundation landing zone from the FAST framework.\n" +
		"Projects can optionally be deployed as features into the landing zone. " +
		"An example of how to use this pasture:\n\n\t" +
		"pasture create foundation",
	Args: cobra.NoArgs,
	Run: func(cmd *cobra.Command, args []string) {

		p, err := utils.ConfigPath()
		if err != nil {
			fmt.Println("Unable to set configuration path")
			cobra.CheckErr(err)
		}

		if _, err := google.AppDefaultCredentials(); err != nil {
			cobra.CheckErr(err)
		}

		dryRun, _ = cmd.Flags().GetBool("dry-run")
		verbose, _ = cmd.Flags().GetBool("verbose")

		varFile := fabric.LoadVarsFile(p, "")
		varData := fabric.NewFastConfig()

		if err := varData.ReadConfig(varFile.LocalPath); err != nil {
			fmt.Println(
				"Unable to read var file.",
				"Try running pasture configure --rehydrate",
			)
			cobra.CheckErr(err)
		}

		varFile.AddConfig(varData)
		varFile.SetBucket(
			varData.Prefix,
		)

		stages := fabric.InitializeFoundationStages(p, varData.Prefix, varFile)

		for _, s := range stages {
			var firstRun bool = false

			if cmd.Parent().Name() == "destroy" && s.Type == "foundation" {
				fmt.Println("Skipping foundation stage:", s.Name)
				continue
			}

			if dryRun && s.Name == "0-bootstrap" {
				fmt.Println(
					"Testing if foundation can be applied to GCP organization",
				)

				if err := s.Init(verbose); err != nil {
					fmt.Println("Cannot initialize stage for dry run")
					cobra.CheckErr(err)
				}

				if err := s.Plan(verbose); err != nil {
					fmt.Println(
						"Foundation cannot be applied to GCP organization",
					)
					cobra.CheckErr(err)
				}

				fmt.Println("Foundation can be applied to GCP organization")
				break
			}

			if cmd.Parent().Name() == "destroy" {
				fmt.Println("Destroying stage:", s.Name)
			} else {
				fmt.Println("Deploying stage:", s.Name)
			}

			if err := s.DiscoverFiles(); err != nil {
				fmt.Println(
					"Pastures first run detected - running with local state",
				)
				firstRun = true
			}

			fmt.Println("Initializing", s.Name)
			if err := s.Init(verbose); err != nil {
				fmt.Println("Failed to migrate state to remote backend")
				cobra.CheckErr(err)
			}

			fmt.Println("Configuration complete")

			if cmd.Parent().Name() == "destroy" {

				fmt.Println("Starting destroy:", s.Name)
				if err := s.Destroy(nil, verbose); err != nil {
					fmt.Println("Stage failed to destroy:", s.Name)
					cobra.CheckErr(err)
				}

				fmt.Println("Successfully destroyed stage:", s.Name)
			} else {

				fmt.Println("Starting apply:", s.Name)
				if err := s.Apply(nil, verbose); err != nil {
					fmt.Println("Stage failed to deploy:", s.Name)
					cobra.CheckErr(err)
				}

				fmt.Println("Successfully applied stage:", s.Name)

				if s.Name == "0-bootstrap" {
					fmt.Println("Uploading pasture vars to GCS bucket")

					if err := varFile.UploadFile(); err != nil {
						fmt.Println("Failed to upload pasture var file")
						cobra.CheckErr(err)
					}
				}

				if firstRun {

					if err := s.DiscoverFiles(); err != nil {
						fmt.Println(
							"Unable to retrieve stage dependencies for:",
							s.Name,
						)
						cobra.CheckErr(err)
					}

					if err := s.Init(verbose); err != nil {
						fmt.Println("Failed to migrate state to remote backend")
						cobra.CheckErr(err)
					}
				}
			}

			fmt.Println("Stage complete:", s.Name)
		}

		fmt.Println(
			"Navigate to the Google Cloud Console to deploy your first workload:",
			"https://console.cloud.google.com/welcome",
		)
	},
}

FoundationCmd represents the foundation command

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL