Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_storage_account - support for the multichannel_enabled property #17999

Merged
merged 1 commit into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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