Пример #1
0
// Discover plugins located on disk, and fall back on plugins baked into the
// Terraform binary.
//
// We look in the following places for plugins:
//
// 1. Terraform configuration path
// 2. Path where Terraform is installed
// 3. Path where Terraform is invoked
//
// Whichever file is discoverd LAST wins.
//
// Finally, we look at the list of plugins compiled into Terraform. If any of
// them has not been found on disk we use the internal version. This allows
// users to add / replace plugins without recompiling the main binary.
func (c *Config) Discover(ui cli.Ui) error {
	// Look in ~/.terraform.d/plugins/
	dir, err := ConfigDir()
	if err != nil {
		log.Printf("[ERR] Error loading config directory: %s", err)
	} else {
		if err := c.discover(filepath.Join(dir, "plugins")); err != nil {
			return err
		}
	}

	// Next, look in the same directory as the Terraform executable, usually
	// /usr/local/bin. If found, this replaces what we found in the config path.
	exePath, err := osext.Executable()
	if err != nil {
		log.Printf("[ERR] Error loading exe directory: %s", err)
	} else {
		if err := c.discover(filepath.Dir(exePath)); err != nil {
			return err
		}
	}

	// Finally look in the cwd (where we are invoke Terraform). If found, this
	// replaces anything we found in the config / install paths.
	if err := c.discover("."); err != nil {
		return err
	}

	// Finally, if we have a plugin compiled into Terraform and we didn't find
	// a replacement on disk, we'll just use the internal version.
	for name, _ := range command.InternalProviders {
		if path, found := c.Providers[name]; found {
			ui.Warn(fmt.Sprintf("[WARN] %s overrides an internal plugin for %s-provider.\n"+
				"  If you did not expect to see this message you will need to remove the old plugin.\n"+
				"  See https://www.terraform.io/docs/internals/internal-plugins.html", path, name))
		} else {

			cmd, err := command.BuildPluginCommandString("provider", name)
			if err != nil {
				return err
			}
			c.Providers[name] = cmd
		}
	}
	for name, _ := range command.InternalProvisioners {
		if path, found := c.Provisioners[name]; found {
			ui.Warn(fmt.Sprintf("[WARN] %s overrides an internal plugin for %s-provisioner.\n"+
				"  If you did not expect to see this message you will need to remove the old plugin.\n"+
				"  See https://www.terraform.io/docs/internals/internal-plugins.html", path, name))
		} else {
			cmd, err := command.BuildPluginCommandString("provisioner", name)
			if err != nil {
				return err
			}
			c.Provisioners[name] = cmd
		}
	}

	return nil
}
Пример #2
0
// directOutput -
func directOutput(ui cli.Ui, channel, prefix, line string) {

	channelType := strings.ToUpper(channel)
	if ui == nil {
		fmt.Printf("%s%s", prefix, line)
	} else {
		switch channelType {
		case "ERROR":
			ui.Error(fmt.Sprintf("%s%s", prefix, line))
		case "INFO":
			ui.Info(fmt.Sprintf("%s%s", prefix, line))
		case "WARN":
			ui.Warn(fmt.Sprintf("%s%s", prefix, line))
		default:
			ui.Output(fmt.Sprintf("%s%s", prefix, line))
		}
	}
}
Пример #3
0
func validateContext(ctx *terraform.Context, ui cli.Ui) bool {
	if ws, es := ctx.Validate(); len(ws) > 0 || len(es) > 0 {
		ui.Output(
			"There are warnings and/or errors related to your configuration. Please\n" +
				"fix these before continuing.\n")

		if len(ws) > 0 {
			ui.Warn("Warnings:\n")
			for _, w := range ws {
				ui.Warn(fmt.Sprintf("  * %s", w))
			}

			if len(es) > 0 {
				ui.Output("")
			}
		}

		if len(es) > 0 {
			ui.Error("Errors:\n")
			for _, e := range es {
				ui.Error(fmt.Sprintf("  * %s", e))
			}
			return false
		} else {
			ui.Warn(fmt.Sprintf("\n"+
				"No errors found. Continuing with %d warning(s).\n", len(ws)))
			return true
		}
	}

	return true
}