in internal/tfimport/importer/random_id.go [32:58]
func (c *RandomID) ImportID(rc terraform.ResourceChange, pcv ConfigMap, interactive bool) (string, error) {
if !interactive {
return "", &InsufficientInfoErr{MissingFields: []string{"b64_url"}}
}
// Ask the user for the random_id.
prompt := "Please enter the previously-generated random_id, in *hex* form. See https://www.terraform.io/docs/providers/random/r/id.html#attributes-reference."
idHex, err := fromUser(os.Stdin, "b64_url", prompt)
if err != nil {
return "", err
}
// Convert to base64.
// Important: no padding, the import doesn't accept it with padding.
b, err := hex.DecodeString(idHex)
if err != nil {
return "", err
}
b64 := base64.StdEncoding.WithPadding(base64.NoPadding).EncodeToString(b)
// Need to import with prefix if present, otherwise without.
prefix, err := fromConfigValues("prefix", rc.Change.After, pcv)
if err == nil && prefix != nil {
return fmt.Sprintf("%v,%v", prefix, b64), nil
}
return fmt.Sprintf("%v", b64), nil
}