@@ -41,6 +41,7 @@ type customError struct {
4141 RequestTarget string
4242 Suggestion string
4343 VersionError string
44+ ResourceDocs string
4445}
4546
4647// Create new error format for Terraform output
@@ -59,6 +60,7 @@ func newCustomError(sync interface{}, err error) error {
5960 OperationName : failure .GetOperationName (),
6061 RequestTarget : failure .GetRequestTarget (),
6162 Service : getServiceName (sync ),
63+ ResourceDocs : getResourceDocsURL (sync ),
6264 }
6365 } else if strings .Contains (errorMessage , "timeout while waiting for state" ) {
6466 // Timeout error
@@ -98,15 +100,16 @@ func newCustomError(sync interface{}, err error) error {
98100func (tfE customError ) Error () error {
99101 switch tfE .TypeOfError {
100102 case ServiceError :
101- return fmt .Errorf ("%d-%s \n " +
103+ return fmt .Errorf ("%d-%s, %s \n " +
104+ "Suggestion: %s\n " +
105+ "Documentation: %s \n " +
106+ "Request Target: %s \n " +
102107 "%s \n " +
103108 "Service: %s \n " +
104109 "Operation Name: %s \n " +
105- "Request Target: %s \n " +
106- "Error Message: %s \n " +
107- "OPC request ID: %s \n " +
108- "Suggestion: %s\n " ,
109- tfE .ErrorCode , tfE .ErrorCodeName , tfE .VersionError , tfE .Service , tfE .OperationName , tfE .RequestTarget , tfE .Message , tfE .OpcRequestID , tfE .Suggestion )
110+ "OPC request ID: %s \n " ,
111+ tfE .ErrorCode , tfE .ErrorCodeName , tfE .Message , tfE .Suggestion , tfE .ResourceDocs , tfE .RequestTarget ,
112+ tfE .VersionError , tfE .Service , tfE .OperationName , tfE .OpcRequestID )
110113 case TimeoutError :
111114 return fmt .Errorf ("%s \n " +
112115 "%s \n " +
@@ -183,6 +186,42 @@ func getServiceName(sync interface{}) string {
183186 return ""
184187}
185188
189+ // Return the Terraform document for the resource/datasource
190+ func getResourceDocsURL (sync interface {}) string {
191+ baseURL := globalvar .TerraformDocumentLink
192+ var result = baseURL
193+ syncTypeName := reflect .TypeOf (sync ).String ()
194+ if strings .Contains (syncTypeName , "ResourceCrud" ) {
195+ result += "resources/"
196+ resourceName := syncTypeName [strings .Index (syncTypeName , "." )+ 1 : strings .Index (syncTypeName , "ResourceCrud" )]
197+ result += toSnakeCase (resourceName )
198+ return result
199+ }
200+ if strings .Contains (syncTypeName , "DataSourcesCrud" ) {
201+ result += "data-sources/"
202+ datasourceName := syncTypeName [strings .Index (syncTypeName , "." )+ 1 : strings .Index (syncTypeName , "DataSourcesCrud" )]
203+ result += toSnakeCase (datasourceName )
204+ return result
205+ }
206+ if strings .Contains (syncTypeName , "DataSourceCrud" ) {
207+ result += "data-sources/"
208+ datasourceName := syncTypeName [strings .Index (syncTypeName , "." )+ 1 : strings .Index (syncTypeName , "DataSourceCrud" )]
209+ result += toSnakeCase (datasourceName )
210+ return result
211+ }
212+ log .Printf ("[DEBUG] Can't get the resource name for: %v" , syncTypeName )
213+ return ""
214+ }
215+
216+ // CoreBootVolume -> core_boot_volume
217+ func toSnakeCase (name string ) string {
218+ var matchFirstCap = regexp .MustCompile ("(.)([A-Z][a-z]+)" )
219+ var matchAllCap = regexp .MustCompile ("([a-z0-9])([A-Z])" )
220+ snake := matchFirstCap .ReplaceAllString (name , "${1}_${2}" )
221+ snake = matchAllCap .ReplaceAllString (snake , "${1}_${2}" )
222+ return strings .ToLower (snake )
223+ }
224+
186225func removeDuplicate (name string ) string {
187226 re := regexp .MustCompile (`[A-Z][^A-Z]*` )
188227 subMatchAll := re .FindAllString (name , - 1 )
0 commit comments