Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Datasource: azurerm_arc_machine #21796

Merged
merged 11 commits into from
Jun 2, 2023
13 changes: 13 additions & 0 deletions internal/sdk/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ type DataSource interface {
Read() ResourceFunc
}

// DataSourceWithDeprecationReplacedBy is an optional interface
//
// DataSource implementing this interface will be marked as Deprecated
// and output the DeprecationMessage during Terraform operations.
type DataSourceWithDeprecationReplacedBy interface {
DataSource

// nolint gocritic
// DeprecatedInFavourOfDataSource returns the name of the resource that this has been deprecated in favour of
// NOTE: this must return a non-empty string
DeprecatedInFavourOfDataSource() string
}

// A Resource is an object which can be provisioned and managed by Terraform
// that is, Created, Retrieved, Deleted, Imported (and optionally, Updated, by implementing
// the 'ResourceWithUpdate' interface)
Expand Down
13 changes: 13 additions & 0 deletions internal/sdk/wrapper_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ func (dw *DataSourceWrapper) DataSource() (*schema.Resource, error) {
},
}

if v, ok := dw.dataSource.(DataSourceWithDeprecationReplacedBy); ok {
replacementDataSourceType := v.DeprecatedInFavourOfDataSource()
if replacementDataSourceType == "" {
return nil, fmt.Errorf("datasource %q must return a non-empty DeprecatedInFavourOfDataSource if implementing DataSourceWithDeprecationReplacedBy", dw.dataSource.ResourceType())
}
resource.DeprecationMessage = fmt.Sprintf(`The %[1]q datasource has been deprecated and replaced by the %[2]q datasource.

The existing %[1]q datasource will remain available until the next
major version of the Azure Provider however the existing datasource is feature-frozen
and we recommend using the %[2]q datasource instead.
`, dw.dataSource.ResourceType(), replacementDataSourceType)
}

return &resource, nil
}

Expand Down
Loading