Detail:"The condition expression must refer to at least one object from elsewhere in the configuration, or else its result would not be checking anything.",
Detail:"An empty string is not a valid nor useful error message.",
Subject:attr.Expr.Range().Ptr(),
})
case!looksLikeSentences(cr.ErrorMessage):
// Because we're going to include this string verbatim as part
// of a bigger error message written in our usual style in
// English, we'll require the given error message to conform
// to that. We might relax this in future if e.g. we start
// presenting these error messages in a different way, or if
// Terraform starts supporting producing error messages in
// other human languages, etc.
// For pragmatism we also allow sentences ending with
// exclamation points, but we don't mention it explicitly here
// because that's not really consistent with the Terraform UI
// writing style.
diags=diags.Append(&hcl.Diagnostic{
Severity:hcl.DiagError,
Summary:errSummary,
Detail:"The validation error message must be at least one full sentence starting with an uppercase letter and ending with a period or question mark.\n\nYour given message will be included as part of a larger Terraform error message, written as English prose. For broadly-shared modules we suggest using a similar writing style so that the overall result will be consistent.",
Subject:attr.Expr.Range().Ptr(),
})
}
}
}
returncr,diags
}
// looksLikeSentence is a simple heuristic that encourages writing error
// messages that will be presentable when included as part of a larger
// Terraform error diagnostic whose other text is written in the Terraform
// UI writing style.
//
// This is intentionally not a very strong validation since we're assuming
// that module authors want to write good messages and might just need a nudge
// about Terraform's specific style, rather than that they are going to try
// to work around these rules to write a lower-quality message.
funclooksLikeSentences(sstring)bool{
iflen(s)<1{
returnfalse
}
runes:=[]rune(s)// HCL guarantees that all strings are valid UTF-8
first:=runes[0]
last:=runes[len(runes)-1]
// If the first rune is a letter then it must be an uppercase letter.
// (This will only see the first rune in a multi-rune combining sequence,
// but the first rune is generally the letter if any are, and if not then
// we'll just ignore it because we're primarily expecting English messages
// right now anyway, for consistency with all of Terraform's other output.)