fmt.Sprintf("The given hostname %q does not allow creating Terraform authorization tokens.",dispHostname),
))
// This is also fine! We'll try the manual token creation process.
case*disco.ErrVersionNotSupported:
diags=diags.Append(tfdiags.Sourceless(
tfdiags.Error,
tfdiags.Warning,
"Host does not support Terraform login",
fmt.Sprintf("The given hostname %q allows creating Terraform authorization tokens, but requires a newer version of Terraform CLI to do so.",dispHostname),
))
default:
diags=diags.Append(tfdiags.Sourceless(
tfdiags.Error,
tfdiags.Warning,
"Host does not support Terraform login",
fmt.Sprintf("The given hostname %q cannot support \"terraform login\": %s.",dispHostname,err),
))
}
// If login service is unavailable, check for a TFE v2 API as fallback
varservice*url.URL
ifclientConfig==nil{
service,err=host.ServiceURL("tfe.v2")
switcherr.(type){
casenil:
// Success!
case*disco.ErrServiceNotProvided:
diags=diags.Append(tfdiags.Sourceless(
tfdiags.Error,
"Host does not support Terraform tokens API",
fmt.Sprintf("The given hostname %q does not support creating Terraform authorization tokens.",dispHostname),
))
case*disco.ErrVersionNotSupported:
diags=diags.Append(tfdiags.Sourceless(
tfdiags.Error,
"Host does not support Terraform tokens API",
fmt.Sprintf("The given hostname %q allows creating Terraform authorization tokens, but requires a newer version of Terraform CLI to do so.",dispHostname),
))
default:
diags=diags.Append(tfdiags.Sourceless(
tfdiags.Error,
"Host does not support Terraform tokens API",
fmt.Sprintf("The given hostname %q cannot support \"terraform login\": %s.",dispHostname,err),
c.Ui.Output("Generate a token using your browser, and copy-paste it into this prompt.\n")
// credsCtx might not be set if we're using a mock credentials source
// in a test, but it should always be set in normal use.
ifcredsCtx!=nil{
switchcredsCtx.Location{
casecliconfig.CredentialsViaHelper:
c.Ui.Output(fmt.Sprintf("Terraform will store the token in the configured %q credentials helper\nfor use by subsequent commands.\n",credsCtx.HelperType))
c.Ui.Output(fmt.Sprintf("Terraform will store the token in plain text in the following file\nfor use by subsequent commands:\n %s\n",credsCtx.LocalFilename))
}
}
token,err:=c.Ui.AskSecret(fmt.Sprintf("Token for %s:",hostname.ForDisplay()))
iferr!=nil{
diags:=diags.Append(fmt.Errorf("Failed to retrieve token: %s",err))