forecast

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Forecast looks at your account and tries to predict things that will go wrong when you attempt to CREATE, UPDATE, or DELETE a stack

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:   "forecast --experimental <template> [stackName]",
	Short: "Predict deployment failures",
	Long: `Outputs warnings about potential deployment failures due to constraints in 
the account or misconfigurations in the template related to dependencies in 
the account.

NOTE: This is an experimental feature!

To use this command, add --experimental or -x as an argument.

This command is not a linter! Use cfn-lint for that. The forecast command 
is concerned with things that could go wrong during deployment, after the 
template has been checked to make sure it has a valid syntax.

This command checks for some common issues across all resources:

- The resource already exists
- You do not have permissions to create/update/delete the resource
- (More to come.. service quotas, drift issues)

Resource-specific checks:

- S3 bucket is not empty
- S3 bucket policy has an invalid principal
- (Many more to come...)
`,
	Args:                  cobra.ExactArgs(2),
	DisableFlagsInUseLine: true,
	Run: func(cmd *cobra.Command, args []string) {
		fn := args[0]
		base := filepath.Base(fn)
		var suppliedStackName string

		if len(args) == 2 {
			suppliedStackName = args[1]
		} else {
			suppliedStackName = ""
		}

		if !Experimental {
			panic("Please add the --experimental arg to use this feature")
		}

		config.Debugf("Generating forecast for %v", fn)

		r, err := os.Open(fn)
		if err != nil {
			panic(ui.Errorf(err, "unable to read '%s'", fn))
		}

		input, err := io.ReadAll(r)
		if err != nil {
			panic(ui.Errorf(err, "unable to read input"))
		}

		source, err := parse.String(string(input))
		if err != nil {
			panic(ui.Errorf(err, "unable to parse input"))
		}

		stackName := dc.GetStackName(suppliedStackName, base)

		spinner.Push(fmt.Sprintf("Checking current status of stack '%s'", stackName))
		stack, stackExists := deploy.CheckStack(stackName)
		spinner.Pop()

		msg := ""
		if stackExists {
			msg = "exists"
		} else {
			msg = "does not exist"
		}
		config.Debugf("Stack %v %v", stackName, msg)

		dc, err := dc.GetDeployConfig(tags, params, configFilePath, base,
			source, stack, stackExists, true, false)
		if err != nil {
			panic(err)
		}

		if !predict(source, stackName, stack, stackExists, dc) {
			os.Exit(1)
		}

	},
}

Cmd is the forecast command's entrypoint

View Source
var Experimental bool

This is an experimental feature that might break between minor releases

View Source
var LineNumber int

The current line number in the template

View Source
var ResourceType string

The resource type to check (optional --type to limit checks to one type)

View Source
var RoleArn string

The role name to use for the IAM policy simulator (optional --role)

View Source
var SkipIAM bool

If true, don't perform permissions checks to save time

Functions

This section is empty.

Types

type Forecast

type Forecast struct {
	TypeName  string
	LogicalId string
	Passed    []string
	Failed    []string
}

Forecast represents predictions for a single resource in the template

func (*Forecast) Add

func (f *Forecast) Add(passed bool, message string)

Add adds a pass or fail message, formatting it to include the type name and logical id

func (*Forecast) Append

func (f *Forecast) Append(forecast Forecast)

func (*Forecast) GetNumChecked

func (f *Forecast) GetNumChecked() int

func (*Forecast) GetNumFailed

func (f *Forecast) GetNumFailed() int

func (*Forecast) GetNumPassed

func (f *Forecast) GetNumPassed() int

type PredictionInput

type PredictionInput struct {
	// contains filtered or unexported fields
}

Input to forecast prediction functions

Jump to

Keyboard shortcuts

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