Skip to content

Commit

Permalink
Add SMB multichannel
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwilcox9 committed Sep 15, 2022
1 parent 38d7ce5 commit 98ebdc8
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 4 deletions.
52 changes: 48 additions & 4 deletions internal/services/storage/storage_account_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,11 @@ func resourceStorageAccount() *pluginsdk.Resource {
}, false),
},
},
"multichannel_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},
},
},
},
Expand Down Expand Up @@ -1239,7 +1244,21 @@ func resourceStorageAccountCreate(d *pluginsdk.ResourceData, meta interface{}) e
if accountKind == string(storage.KindFileStorage) || accountKind != string(storage.KindBlobStorage) && accountKind != string(storage.KindBlockBlobStorage) && accountTier != string(storage.SkuTierPremium) {
fileServiceClient := meta.(*clients.Client).Storage.FileServicesClient

if _, err = fileServiceClient.SetServiceProperties(ctx, id.ResourceGroup, id.Name, expandShareProperties(val.([]interface{}))); err != nil {
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) {

// 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` aren't supported for Standard tier Storage accounts")
}
}

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

if _, err = fileServiceClient.SetServiceProperties(ctx, id.ResourceGroup, id.Name, shareProperties); err != nil {
return fmt.Errorf("updating Azure Storage Account `share_properties` %q: %+v", id.Name, err)
}
} else {
Expand Down Expand Up @@ -1658,7 +1677,21 @@ func resourceStorageAccountUpdate(d *pluginsdk.ResourceData, meta interface{}) e
if accountKind == string(storage.KindFileStorage) || accountKind != string(storage.KindBlobStorage) && accountKind != string(storage.KindBlockBlobStorage) && accountTier != string(storage.SkuTierPremium) {
fileServiceClient := meta.(*clients.Client).Storage.FileServicesClient

if _, err = fileServiceClient.SetServiceProperties(ctx, id.ResourceGroup, id.Name, expandShareProperties(d.Get("share_properties").([]interface{}))); err != nil {
shareProperties := expandShareProperties(d.Get("share_properties").([]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) {

// 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` aren't supported for Standard tier Storage accounts")
}
}

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

if _, err = fileServiceClient.SetServiceProperties(ctx, id.ResourceGroup, id.Name, shareProperties); err != nil {
return fmt.Errorf("updating Azure Storage Account `file share_properties` %q: %+v", id.Name, err)
}
} else {
Expand Down Expand Up @@ -2490,12 +2523,17 @@ func expandSharePropertiesSMB(input []interface{}) *storage.SmbSetting {

v := input[0].(map[string]interface{})

return &storage.SmbSetting{
smbSetting := storage.SmbSetting{
Versions: utils.ExpandStringSliceWithDelimiter(v["versions"].(*pluginsdk.Set).List(), ";"),
AuthenticationMethods: utils.ExpandStringSliceWithDelimiter(v["authentication_types"].(*pluginsdk.Set).List(), ";"),
KerberosTicketEncryption: utils.ExpandStringSliceWithDelimiter(v["kerberos_ticket_encryption_type"].(*pluginsdk.Set).List(), ";"),
ChannelEncryption: utils.ExpandStringSliceWithDelimiter(v["channel_encryption_type"].(*pluginsdk.Set).List(), ";"),
Multichannel: &storage.Multichannel{
Enabled: utils.Bool(v["multichannel_enabled"].(bool)),
},
}

return &smbSetting
}

func expandQueueProperties(input []interface{}) (queues.StorageServiceProperties, error) {
Expand Down Expand Up @@ -3105,7 +3143,12 @@ func flattenedSharePropertiesSMB(input *storage.SmbSetting) []interface{} {
channelEncryption = utils.FlattenStringSliceWithDelimiter(input.ChannelEncryption, ";")
}

if len(versions) == 0 && len(authenticationMethods) == 0 && len(kerberosTicketEncryption) == 0 && len(channelEncryption) == 0 {
multichannelEnabled := false
if input.Multichannel != nil && input.Multichannel.Enabled != nil {
multichannelEnabled = *input.Multichannel.Enabled
}

if len(versions) == 0 && len(authenticationMethods) == 0 && len(kerberosTicketEncryption) == 0 && len(channelEncryption) == 0 && input.Multichannel == nil {
return []interface{}{}
}

Expand All @@ -3115,6 +3158,7 @@ func flattenedSharePropertiesSMB(input *storage.SmbSetting) []interface{} {
"authentication_types": authenticationMethods,
"kerberos_ticket_encryption_type": kerberosTicketEncryption,
"channel_encryption_type": channelEncryption,
"multichannel_enabled": multichannelEnabled,
},
}
}
Expand Down
48 changes: 48 additions & 0 deletions internal/services/storage/storage_account_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,28 @@ func TestAccStorageAccount_edgeZone(t *testing.T) {
})
}

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

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

func (r StorageAccountResource) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := parse.StorageAccountID(state.ID)
if err != nil {
Expand Down Expand Up @@ -3834,3 +3856,29 @@ resource "azurerm_storage_account" "test" {
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString)
}

func (r StorageAccountResource) smbMultichannel(data acceptance.TestData, enabled bool) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-storage-%d"
location = "%s"
}
resource "azurerm_storage_account" "test" {
name = "unlikely23exst2acct%s"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
account_tier = "Premium"
account_kind = "FileStorage"
account_replication_type = "ZRS"
share_properties {
smb {
multichannel_enabled = %t
}
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString, enabled)
}
2 changes: 2 additions & 0 deletions website/docs/r/storage_account.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ A `smb` block supports the following:

* `channel_encryption_type` - (Optional) A set of SMB channel encryption. Possible values are `AES-128-CCM`, `AES-128-GCM`, and `AES-256-GCM`.

* `multichannel_enabled` - (Optional) Indicates whether multichannel is enabled. Defaults to `false`. This is only supported on Premium storage accounts.

---

## Attributes Reference
Expand Down

0 comments on commit 98ebdc8

Please sign in to comment.