Skip to content

Commit

Permalink
fix permissions for azurerm_storage_account (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricleal-fugue committed Jan 13, 2023
1 parent c474dfc commit 9b4d2fc
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 39 deletions.
31 changes: 30 additions & 1 deletion cmd/debug/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
To debug the provider
## VSCODE

create debug config:
create debug config in VSCODE:


```json
Expand Down Expand Up @@ -50,5 +50,34 @@ provider_installation {

```sh
export TF_CLI_CONFIG_FILE=/Users/ricardol/git/terraform-provider-azurerm/tmp/ex1/terraformrc
# In terminal 1 there's the value this variable should have
export TF_REATTACH_PROVIDERS=....
```


In a new folder, create a `provider.tf` with:
```
terraform {
required_providers {
azurerm = {
source = "snyk/azurerm"
# version = "=3.0.0"
}
}
}
provider "azurerm" {
features {}
}
```

Create a `main.tf` with:
```
resource "azurerm_storage_account" "mysa" {
}
```

Run in the shell:
```
terraform import azurerm_storage_account.mysa "/subscriptions/ec86c868-4762-493c-ae65-411f88b2ffab/resourceGroups/rleal-resources/providers/Microsoft.Storage/storageAccounts/rlealstoraccount"
```
78 changes: 40 additions & 38 deletions internal/services/storage/storage_account_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -2117,21 +2117,22 @@ func resourceStorageAccountRead(d *pluginsdk.ResourceData, meta interface{}) err
}
}

if supportLevel.supportQueue {
queueClient, err := storageClient.QueuesClient(ctx, *account)
if err != nil {
return fmt.Errorf("building Queues Client: %s", err)
}

queueProps, err := queueClient.GetServiceProperties(ctx, account.ResourceGroup, id.Name)
if err != nil {
return fmt.Errorf("reading queue properties for AzureRM Storage Account %q: %+v", id.Name, err)
}

if err := d.Set("queue_properties", flattenQueueProperties(queueProps)); err != nil {
return fmt.Errorf("setting `queue_properties`: %+v", err)
}
}
// We need access to keys to create a storageClient.QueuesClient
// if supportLevel.supportQueue {
// queueClient, err := storageClient.QueuesClient(ctx, *account)
// if err != nil {
// return fmt.Errorf("building Queues Client: %s", err)
// }

// queueProps, err := queueClient.GetServiceProperties(ctx, account.ResourceGroup, id.Name)
// if err != nil {
// return fmt.Errorf("reading queue properties for AzureRM Storage Account %q: %+v", id.Name, err)
// }

// if err := d.Set("queue_properties", flattenQueueProperties(queueProps)); err != nil {
// return fmt.Errorf("setting `queue_properties`: %+v", err)
// }
// }

if supportLevel.supportShare {
fileServiceClient := storageClient.FileServicesClient
Expand All @@ -2147,29 +2148,30 @@ func resourceStorageAccountRead(d *pluginsdk.ResourceData, meta interface{}) err
}
}

if supportLevel.supportStaticWebsite {
storageClient := meta.(*clients.Client).Storage
account, err := storageClient.FindAccount(ctx, id.Name)
if err != nil {
return fmt.Errorf("retrieving Account %q: %s", id.Name, err)
}

accountsClient, err := storageClient.AccountsDataPlaneClient(ctx, *account)
if err != nil {
return fmt.Errorf("building Accounts Data Plane Client: %s", err)
}

staticWebsiteProps, err := accountsClient.GetServiceProperties(ctx, id.Name)
if err != nil {
if staticWebsiteProps.Response.Response != nil && !utils.ResponseWasNotFound(staticWebsiteProps.Response) {
return fmt.Errorf("reading static website for AzureRM Storage Account %q: %+v", id.Name, err)
}
}
staticWebsite := flattenStaticWebsiteProperties(staticWebsiteProps)
if err := d.Set("static_website", staticWebsite); err != nil {
return fmt.Errorf("setting `static_website `for AzureRM Storage Account %q: %+v", id.Name, err)
}
}
// We need access to keys to create a storageClient.AccountsDataPlaneClient
// if supportLevel.supportStaticWebsite {
// storageClient := meta.(*clients.Client).Storage
// account, err := storageClient.FindAccount(ctx, id.Name)
// if err != nil {
// return fmt.Errorf("retrieving Account %q: %s", id.Name, err)
// }

// accountsClient, err := storageClient.AccountsDataPlaneClient(ctx, *account)
// if err != nil {
// return fmt.Errorf("building Accounts Data Plane Client: %s", err)
// }

// staticWebsiteProps, err := accountsClient.GetServiceProperties(ctx, id.Name)
// if err != nil {
// if staticWebsiteProps.Response.Response != nil && !utils.ResponseWasNotFound(staticWebsiteProps.Response) {
// return fmt.Errorf("reading static website for AzureRM Storage Account %q: %+v", id.Name, err)
// }
// }
// staticWebsite := flattenStaticWebsiteProperties(staticWebsiteProps)
// if err := d.Set("static_website", staticWebsite); err != nil {
// return fmt.Errorf("setting `static_website `for AzureRM Storage Account %q: %+v", id.Name, err)
// }
// }

return tags.FlattenAndSet(d, resp.Tags)
}
Expand Down

0 comments on commit 9b4d2fc

Please sign in to comment.