Skip to content

Commit

Permalink
New Datasource: azurerm_arc_machine (#21796)
Browse files Browse the repository at this point in the history
Co-authored-by: Tom Harvey <tombuildsstuff@users.noreply.github.com>
  • Loading branch information
liuwuliuyun and tombuildsstuff authored Jun 2, 2023
1 parent 1af8e27 commit 6feb5af
Show file tree
Hide file tree
Showing 9 changed files with 1,435 additions and 137 deletions.
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

0 comments on commit 6feb5af

Please sign in to comment.