@@ -11,6 +11,7 @@ import (
11
11
12
12
"github.com/coder/terraform-provider-coder/provider"
13
13
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
14
+ "golang.org/x/xerrors"
14
15
)
15
16
16
17
// This script patches Markdown docs generated by `terraform-plugin-docs` to expose the original deprecation message.
@@ -35,7 +36,7 @@ func exposeDeprecationMessage(p *schema.Provider) error {
35
36
36
37
err := adjustDocFile (docFile , dataSource .Schema )
37
38
if err != nil {
38
- return err
39
+ return xerrors . Errorf ( "unable to adjust data-source doc file (data-source: %s): %w" , dataSourceName , err )
39
40
}
40
41
}
41
42
@@ -45,30 +46,30 @@ func exposeDeprecationMessage(p *schema.Provider) error {
45
46
46
47
err := adjustDocFile (docFile , resource .Schema )
47
48
if err != nil {
48
- return err
49
+ return xerrors . Errorf ( "unable to adjust resource doc file (resource: %s): %w" , resourceName , err )
49
50
}
50
51
}
51
52
52
53
// Patch index
53
54
docFile := filepath .Join ("docs" , "index.md" )
54
55
err := adjustDocFile (docFile , p .Schema )
55
56
if err != nil {
56
- return err
57
+ return xerrors . Errorf ( "unable to adjust index doc file: %w" , err )
57
58
}
58
59
return nil
59
60
}
60
61
61
62
func adjustDocFile (docPath string , schemas map [string ]* schema.Schema ) error {
62
63
doc , err := os .ReadFile (docPath )
63
64
if err != nil {
64
- return err
65
+ return xerrors . Errorf ( "can't read the source doc file: %w" , err )
65
66
}
66
67
67
68
result := writeDeprecationMessage (doc , schemas )
68
69
69
70
err = os .WriteFile (docPath , result , 0644 )
70
71
if err != nil {
71
- return err
72
+ return xerrors . Errorf ( "can't write modified doc file: %w" , err )
72
73
}
73
74
return nil
74
75
}
@@ -81,7 +82,8 @@ func writeDeprecationMessage(doc []byte, schemas map[string]*schema.Schema) []by
81
82
82
83
sch := schemas [string (propertyName )]
83
84
if string (description ) != sch .Description {
84
- return m // same property name but description does not match, most likely a different property
85
+ log .Printf ("warn: same property name `%s` but description does not match, most likely a different property" , propertyName )
86
+ return m
85
87
}
86
88
return bytes .Replace (m , []byte ("Deprecated" ), []byte (fmt .Sprintf ("Deprecated: %s" , sch .Deprecated )), 1 )
87
89
})
0 commit comments