Export resource deprecation.

We already had the functionality to make resources deprecated, which was
used when migrating resources to data sources, but the functionality was
unexported, so only the schema package could do it. Now it's exported,
meaning providers can mark entire resources as deprecated. I also added
a test in hopefully-the-right place?
This commit is contained in:
Paddy Carver 2018-06-19 12:02:55 -07:00
parent b95f74956a
commit 0dd2408d65
3 changed files with 18 additions and 6 deletions

View File

@ -32,7 +32,7 @@ func DataSourceResourceShim(name string, dataSource *Resource) *Resource {
// FIXME: Link to some further docs either on the website or in the
// changelog, once such a thing exists.
dataSource.deprecationMessage = fmt.Sprintf(
dataSource.Deprecated = fmt.Sprintf(
"using %s as a resource is deprecated; consider using the data source instead",
name,
)

View File

@ -124,9 +124,7 @@ type Resource struct {
Importer *ResourceImporter
// If non-empty, this string is emitted as a warning during Validate.
// This is a private interface for now, for use by DataSourceResourceShim,
// and not for general use. (But maybe later...)
deprecationMessage string
Deprecated string
// Timeouts allow users to specify specific time durations in which an
// operation should time out, to allow them to extend an action to suit their
@ -269,8 +267,8 @@ func (r *Resource) Diff(
func (r *Resource) Validate(c *terraform.ResourceConfig) ([]string, []error) {
warns, errs := schemaMap(r.Schema).Validate(c)
if r.deprecationMessage != "" {
warns = append(warns, r.deprecationMessage)
if r.Deprecated != "" {
warns = append(warns, r.Deprecated)
}
return warns, errs

View File

@ -850,6 +850,20 @@ func TestResourceInternalValidate(t *testing.T) {
false,
true,
},
14: { // Deprecated resource
&Resource{
Read: func(d *ResourceData, meta interface{}) error { return nil },
Schema: map[string]*Schema{
"goo": &Schema{
Type: TypeInt,
Optional: true,
},
},
Deprecated: "This resource has been deprecated.",
},
true,
true,
},
}
for i, tc := range cases {