Skip to content

Commit

Permalink
azurerm_storage_account - support for the multichannel_enabled prop…
Browse files Browse the repository at this point in the history
…erty (#17999)

Co-authored-by: Alex Wilcox <[email protected]>
  • Loading branch information
alexwilcox9 and alexwilcox9 authored Sep 28, 2022
1 parent c14cba9 commit ea1087e
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 3 deletions.
48 changes: 45 additions & 3 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` isn'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` isn'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 @@ -2495,6 +2528,9 @@ func expandSharePropertiesSMB(input []interface{}) *storage.SmbSetting {
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)),
},
}
}

Expand Down Expand Up @@ -3105,7 +3141,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 +3156,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 ea1087e

Please sign in to comment.