func loadFields()

in internal/tfimport/importer/resources.go [106:132]


func loadFields(fields []string, interactive bool, configValues ...ConfigMap) (fieldsMap map[string]interface{}, err error) {
	fieldsMap = make(map[string]interface{})
	var missingFields []string
	for _, field := range fields {
		val, err := fromConfigValues(field, configValues...)
		// If interactive is set, try to get the field interactively.
		if err != nil && interactive {
			prompt := fmt.Sprintf("Please enter the exact value for %v", field)
			val, err = fromUser(os.Stdin, field, prompt)
		}

		// If err is still not nil, then user didn't provide value, treat this as a missing field.
		if err != nil {
			missingFields = append(missingFields, field)
		}

		// Leave the value as-is, to allow arbitrary nesting in the template, if it happens to not be a string.
		// For example, in the google_container_node_pool resource, `node_config` is a map but has potentially useful sub-fields.
		fieldsMap[field] = val
	}

	if len(missingFields) > 0 {
		return nil, &InsufficientInfoErr{missingFields, ""}
	}

	return fieldsMap, nil
}