in internal/tfimport/importer/google_resource_manager_lien.go [32:78]
func (i *ResourceManagerLien) ImportID(rc terraform.ResourceChange, pcv ConfigMap, interactive bool) (string, error) {
// Can't import if not interactive, since lien names are system-generated and will never be in the plan.
if !interactive {
return "", &InsufficientInfoErr{[]string{"name"}, "Lien name is system-generated and will never be in the plan"}
}
parentI, err := fromConfigValues("parent", rc.Change.After, pcv)
if err != nil {
return "", err
}
parentFull := fmt.Sprintf("%s", parentI)
// Parent is in the form "project/1234567890", but we need to drop the prefix.
parts := strings.Split(parentFull, "/")
parent := parts[len(parts)-1]
// The name is not set, it is autogenerated by the system.
// Try to find existing liens for this parent to offer as choices.
liens, err := i.getLiens(parentFull)
if err != nil {
return "", err
}
if len(liens) <= 0 {
// There are no liens, just return that it doesn't exist so it can be created.
return "", &DoesNotExistErr{rc.Address}
}
// Present the choices, if any
// Format the liens more nicely.
liensLines := []string{"Name|Origin|Reason|Restrictions"}
for _, lien := range liens {
// The name is always "liens/<id for import>".
lienID := strings.Split(lien.Name, "/")[1]
liensLines = append(liensLines, fmt.Sprintf("%v|%v|%v|%v", lienID, lien.Origin, lien.Reason, strings.Join(lien.Restrictions, ", ")))
}
prompt := fmt.Sprintf("Found the following liens in %v:\n%s", parentFull, columnize.SimpleFormat(liensLines))
// Get the value from the user
name, err := fromUser(os.Stdin, "name", prompt)
if err != nil {
return "", err
}
return fmt.Sprintf("%v/%v", parent, name), nil
}