Skip to content

Commit

Permalink
azurerm_storage_management_policy - move to hashicorp/go-azure-sdk (
Browse files Browse the repository at this point in the history
  • Loading branch information
magodo authored Aug 22, 2023
1 parent 92a83ff commit bb54436
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 237 deletions.
5 changes: 0 additions & 5 deletions internal/services/storage/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ type Client struct {
AccountsClient *storage.AccountsClient
FileSystemsClient *filesystems.Client
ADLSGen2PathsClient *paths.Client
ManagementPoliciesClient *storage.ManagementPoliciesClient
BlobServicesClient *storage.BlobServicesClient
BlobInventoryPoliciesClient *storage.BlobInventoryPoliciesClient
EncryptionScopesClient *storage.EncryptionScopesClient
Expand All @@ -60,9 +59,6 @@ func NewClient(options *common.ClientOptions) (*Client, error) {
adlsGen2PathsClient := paths.NewWithEnvironment(options.AzureEnvironment)
options.ConfigureClient(&adlsGen2PathsClient.Client, options.StorageAuthorizer)

managementPoliciesClient := storage.NewManagementPoliciesClientWithBaseURI(options.ResourceManagerEndpoint, options.SubscriptionId)
options.ConfigureClient(&managementPoliciesClient.Client, options.ResourceManagerAuthorizer)

blobServicesClient := storage.NewBlobServicesClientWithBaseURI(options.ResourceManagerEndpoint, options.SubscriptionId)
options.ConfigureClient(&blobServicesClient.Client, options.ResourceManagerAuthorizer)

Expand Down Expand Up @@ -103,7 +99,6 @@ func NewClient(options *common.ClientOptions) (*Client, error) {
AccountsClient: &accountsClient,
FileSystemsClient: &fileSystemsClient,
ADLSGen2PathsClient: &adlsGen2PathsClient,
ManagementPoliciesClient: &managementPoliciesClient,
BlobServicesClient: &blobServicesClient,
BlobInventoryPoliciesClient: &blobInventoryPoliciesClient,
EncryptionScopesClient: &encryptionScopesClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
"fmt"
"time"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonids"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
"github.com/hashicorp/terraform-provider-azurerm/utils"
)

func dataSourceStorageManagementPolicy() *pluginsdk.Resource {
Expand Down Expand Up @@ -200,7 +200,7 @@ func dataSourceStorageManagementPolicy() *pluginsdk.Resource {
}

func dataSourceStorageManagementPolicyRead(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).Storage.ManagementPoliciesClient
client := meta.(*clients.Client).Storage.ResourceManager.ManagementPolicies
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

Expand All @@ -210,9 +210,9 @@ func dataSourceStorageManagementPolicyRead(d *pluginsdk.ResourceData, meta inter
}

id := parse.NewStorageAccountManagementPolicyID(storageAccountId.SubscriptionId, storageAccountId.ResourceGroupName, storageAccountId.StorageAccountName, "default")
resp, err := client.Get(ctx, id.ResourceGroup, id.StorageAccountName)
resp, err := client.Get(ctx, *storageAccountId)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
if response.WasNotFound(resp.HttpResponse) {
return fmt.Errorf("%s was not found", id)
}

Expand All @@ -221,9 +221,9 @@ func dataSourceStorageManagementPolicyRead(d *pluginsdk.ResourceData, meta inter

d.SetId(id.ID())

if props := resp.ManagementPolicyProperties; props != nil {
if policy := props.Policy; policy != nil {
if err := d.Set("rule", flattenStorageManagementPolicyRules(policy.Rules)); err != nil {
if model := resp.Model; model != nil {
if props := model.Properties; props != nil {
if err := d.Set("rule", flattenStorageManagementPolicyRules(props.Policy.Rules)); err != nil {
return fmt.Errorf("flattening `rule`: %+v", err)
}
}
Expand Down
Loading

0 comments on commit bb54436

Please sign in to comment.