func()

in astro/execution.go [139:182]


func (e *unboundExecution) bind(userVars map[string]string) (*boundExecution, error) {
	// boundVars is the map of execution variables bound to the values provided by user
	boundVars := make(map[string]string)

	for key, val := range e.Variables() {
		boundVars[key] = val
		if userVal, ok := userVars[key]; ok {
			boundVars[key] = userVal
		}
	}

	missingVars := []string{}
	// Check that the user provided variables replace everything that
	// needs to be replaced.
	for _, val := range boundVars {
		if err := assertAllVarsReplaced(val); err != nil {
			missingVars = append(missingVars, extractMissingVarNames(val)...)
		}
	}

	if len(missingVars) > 0 {
		return nil, MissingRequiredVarsError{missing: missingVars}
	}

	// Create a copy of the config and search attributes for placeholders
	// to replace with values from the bound vars.
	boundConfig := e.ModuleConfig()

	// TODO: Loop over all module configuration using reflection

	boundBackendConfig, err := replaceAllVarsInMapValues(boundConfig.Remote.BackendConfig, boundVars)
	if err != nil {
		return nil, fmt.Errorf("unable to bind execution: %v; %v", e.ID(), err)
	}
	boundConfig.Remote.BackendConfig = boundBackendConfig

	return &boundExecution{
		&execution{
			moduleConf:          &boundConfig,
			variables:           boundVars,
			terraformParameters: e.TerraformParameters(),
		},
	}, nil
}