Skip to content

Commit

Permalink
azurerm_storage_account - fix crash in multichannel checking (hashi…
Browse files Browse the repository at this point in the history
  • Loading branch information
jackofallops authored and leesutcliffe committed Nov 24, 2022
1 parent f87224e commit e8f922b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
18 changes: 12 additions & 6 deletions internal/services/storage/storage_account_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ func resourceStorageAccount() *pluginsdk.Resource {
"share_properties": {
Type: pluginsdk.TypeList,
Optional: true,
// (@jackofallops) TODO - This should not be computed, however, this would be a breaking change with unknown implications for user data so needs to be addressed for 4.0
Computed: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Expand Down Expand Up @@ -1344,17 +1345,22 @@ func resourceStorageAccountCreate(d *pluginsdk.ResourceData, meta interface{}) e
fileServiceClient := meta.(*clients.Client).Storage.FileServicesClient

shareProperties := expandShareProperties(val.([]interface{}))

// The API complains if any multichannel info is sent on non premium fileshares. Even if multichannel is set to false
if accountTier != string(storage.SkuTierPremium) {
if accountTier != string(storage.SkuTierPremium) && shareProperties.FileServicePropertiesProperties != nil && shareProperties.FileServicePropertiesProperties.ProtocolSettings != nil {

// Error if the user has tried to enable multichannel on a standard tier storage account
if shareProperties.FileServicePropertiesProperties.ProtocolSettings.Smb.Multichannel != nil && shareProperties.FileServicePropertiesProperties.ProtocolSettings.Smb.Multichannel.Enabled != nil {
if *shareProperties.FileServicePropertiesProperties.ProtocolSettings.Smb.Multichannel.Enabled {
return fmt.Errorf("`multichannel_enabled` isn't supported for Standard tier Storage accounts")
smb := shareProperties.FileServicePropertiesProperties.ProtocolSettings.Smb
if smb != nil && smb.Multichannel != nil {

if smb.Multichannel.Enabled != nil {
if *shareProperties.FileServicePropertiesProperties.ProtocolSettings.Smb.Multichannel.Enabled {
return fmt.Errorf("`multichannel_enabled` isn't supported for Standard tier Storage accounts")
}
}
}

shareProperties.FileServicePropertiesProperties.ProtocolSettings.Smb.Multichannel = nil
shareProperties.FileServicePropertiesProperties.ProtocolSettings.Smb.Multichannel = nil
}
}

if _, err = fileServiceClient.SetServiceProperties(ctx, id.ResourceGroup, id.Name, shareProperties); err != nil {
Expand Down
40 changes: 40 additions & 0 deletions internal/services/storage/storage_account_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1350,6 +1350,21 @@ func TestAccStorageAccount_sasPolicy(t *testing.T) {
})
}

func TestAccStorageAccount_emptyShareProperties(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_storage_account", "test")
r := StorageAccountResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.emptyShareProperties(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccStorageAccount_isSftpEnabled(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_storage_account", "test")
r := StorageAccountResource{}
Expand Down Expand Up @@ -4131,6 +4146,31 @@ resource "azurerm_storage_account" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomString)
}

func (r StorageAccountResource) emptyShareProperties(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-storage-%[1]d"
location = "%[2]s"
}
resource "azurerm_storage_account" "test" {
name = "unlikely23exst2acct%[3]s"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
account_tier = "Standard"
account_replication_type = "LRS"
account_kind = "StorageV2"
share_properties {}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString)
}

func (r StorageAccountResource) isSftpEnabledTrue(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down

0 comments on commit e8f922b

Please sign in to comment.