@@ -3,7 +3,8 @@ package superschema
3
3
import "fmt"
4
4
5
5
const (
6
- warningDeprecated = "\n \n ~> **Attribute deprecated** "
6
+ warningAttributeDeprecated = "\n \n ~> **Attribute deprecated** "
7
+ warningResourceDeprecated = "\n \n !> **Resource deprecated** "
7
8
)
8
9
9
10
// Deprecated is a struct to describe a deprecated attribute.
@@ -64,7 +65,7 @@ func (d *Deprecated) computeDeprecatedDocumentation() string {
64
65
return d .MarkdownDeprecationMessage
65
66
}
66
67
67
- message := warningDeprecated
68
+ message := warningAttributeDeprecated
68
69
69
70
switch {
70
71
case d .Renamed :
@@ -108,3 +109,110 @@ func (d *Deprecated) GetDeprecationMessage() string {
108
109
func (d * Deprecated ) GetMarkdownDeprecationMessage () string {
109
110
return d .computeDeprecatedDocumentation ()
110
111
}
112
+
113
+ // DeprecatedResource is a struct to describe a deprecated resource or data source.
114
+ type DeprecatedResource struct {
115
+ // DeprecationMessage is the message to display in the CLI when the user
116
+ // attempts to use the deprecated resource.
117
+ // This field is required.
118
+ DeprecationMessage string
119
+
120
+ // MarkdownDeprecationMessage is the message to display in the Documentation portal
121
+ // when the user attempts to use the deprecated attribute.
122
+ // This field is required if ComputeMarkdownDeprecationMessage is false.
123
+ MarkdownDeprecationMessage string
124
+
125
+ // ComputeMarkdownDeprecationMessage is a flag to indicate whether the MarkdownDeprecationMessage
126
+ // should be computed from the parameters of the Deprecated struct.
127
+ ComputeMarkdownDeprecationMessage bool
128
+
129
+ // Renamed is a flag to indicate whether the resource or datasource has been renamed.
130
+ // Removed is a flag to indicate whether the resource or datasource has been removed.
131
+ // One of these fields must be true.
132
+ Renamed , Removed bool
133
+
134
+ // TargetResourceName is the name of the resource that replaces the deprecated resource or data source.
135
+ // These fields are required if the resource or data source has been renamed and computeMarkdownDeprecationMessage is true.
136
+ TargetResourceName string
137
+
138
+ // TargetRelease is the release version in which the resource or datasource was deprecated. (e.g. v1.0.0).
139
+ // This field is Required.
140
+ TargetRelease string
141
+ // LinkToIssue is the link to the GitHub issue that describes the deprecation.
142
+ // This field is optional.
143
+ LinkToIssue string
144
+ // LinkToMigrationGuide is the link to the actual resource documentation.
145
+ // This field is optional.
146
+ LinkToMigrationGuide string
147
+ // LinkToNewResourceDoc is the link to the terraform documentation for the resource that replaces the deprecated attribute.
148
+ // This field is optional.
149
+ LinkToNewResourceDoc string
150
+ // LinkToMilestone is the link to the GitHub milestone that describes the release in which the attribute was deprecated.
151
+ // This field is optional.
152
+ LinkToMilestone string
153
+ }
154
+
155
+ func (d * DeprecatedResource ) computeDeprecatedDocumentation (isResource bool ) string {
156
+
157
+ if (! d .ComputeMarkdownDeprecationMessage && d .MarkdownDeprecationMessage == "" ) || (d .Renamed && d .TargetResourceName == "" && d .ComputeMarkdownDeprecationMessage ) || d .TargetRelease == "" {
158
+ return ""
159
+ }
160
+
161
+ if d .Removed && d .Renamed {
162
+ return ""
163
+ }
164
+
165
+ ressOrData := func () string {
166
+ if isResource {
167
+ return "resource"
168
+ }
169
+ return "data source"
170
+ }()
171
+
172
+ message := warningResourceDeprecated + d .MarkdownDeprecationMessage
173
+
174
+ if d .ComputeMarkdownDeprecationMessage {
175
+ switch {
176
+ case d .Renamed :
177
+ if d .TargetResourceName == "" {
178
+ return ""
179
+ }
180
+ if d .LinkToNewResourceDoc != "" {
181
+ message += fmt .Sprintf ("The %s has renamed to [`%s`](%s)" , ressOrData , d .TargetResourceName , d .LinkToNewResourceDoc )
182
+ } else {
183
+ message += fmt .Sprintf ("The %s has renamed to `%s`" , ressOrData , d .TargetResourceName )
184
+ }
185
+ case d .Removed :
186
+ message += fmt .Sprintf ("The %s has been removed" , ressOrData )
187
+ default :
188
+ return ""
189
+ }
190
+ }
191
+
192
+ if d .LinkToMilestone != "" {
193
+ message += fmt .Sprintf (", it will be removed in the version [`%s`](%s) of the provider" , d .TargetRelease , d .LinkToMilestone )
194
+ } else {
195
+ message += fmt .Sprintf (", it will be removed in the version `%s` of the provider" , d .TargetRelease )
196
+ }
197
+
198
+ if d .LinkToIssue != "" {
199
+ message += fmt .Sprintf (". See the [GitHub issue](%s) for more information." , d .LinkToIssue )
200
+ }
201
+
202
+ return addEndDot (message )
203
+ }
204
+
205
+ // GetDeprecationMessage returns the deprecation message for the attribute.
206
+ func (d * DeprecatedResource ) GetDeprecationMessage () string {
207
+
208
+ if d .LinkToMigrationGuide != "" {
209
+ return fmt .Sprintf ("%s. See the migration guide(%s) for more information." , d .DeprecationMessage , d .LinkToMigrationGuide )
210
+ }
211
+
212
+ return d .DeprecationMessage
213
+ }
214
+
215
+ // GetMarkdownDeprecationMessage returns the markdown deprecation message for the attribute.
216
+ func (d * DeprecatedResource ) GetMarkdownDeprecationMessage (isResource bool ) string {
217
+ return d .computeDeprecatedDocumentation (isResource )
218
+ }
0 commit comments