func runCmdValidate(cmd *cobra.Command, args []string) error {
	cfg, err := config.ClusterFromFile(configPath)
	if err != nil {
		return fmt.Errorf("Unable to load cluster config: %v", err)
	}

	fmt.Printf("Validating UserData...\n")
	if err := cfg.ValidateUserData(stackTemplateOptions); err != nil {
		return err
	}
	fmt.Printf("UserData is valid.\n\n")

	fmt.Printf("Validating stack template...\n")
	data, err := cfg.RenderStackTemplate(stackTemplateOptions)
	if err != nil {
		return fmt.Errorf("Failed to render stack template: %v", err)
	}

	cluster := cluster.New(cfg, validateOpts.awsDebug)
	report, err := cluster.ValidateStack(string(data))
	if report != "" {
		fmt.Fprintf(os.Stderr, "Validation Report: %s\n", report)
	}

	if err != nil {
		return err
	}
	fmt.Printf("stack template is valid.\n\n")

	fmt.Printf("Validation OK!\n")
	return nil
}
Ejemplo n.º 2
0
func runCmdValidate(cmd *cobra.Command, args []string) {
	cfg, err := config.NewConfigFromFile(ConfigPath)
	if err != nil {
		stderr("Unable to load cluster config: %v", err)
		os.Exit(1)
	}

	if err := cfg.ReadAssetsFromFiles(); err != nil {
		stderr("Error reading assets from files: %v", err)
		os.Exit(1)
	}

	if err := cfg.TemplateAndEncodeAssets(); err != nil {
		stderr("template/encode error: %v", err)
		os.Exit(1)
	}

	cluster := cluster.New(cfg, upOpts.awsDebug)

	report, err := cluster.ValidateStack()

	if report != "" {
		fmt.Printf("Validation Report: %s\n", report)
	}

	if err != nil {
		stderr("Error creating cluster: %v", err)
		os.Exit(1)
	} else {
		fmt.Printf("Validation OK!\n")
	}
}