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 min_tls_version #7879

Merged
merged 13 commits into from
Aug 6, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ func dataSourceArmStorageAccount() *schema.Resource {
Computed: true,
},

"min_tls_version": {
Type: schema.TypeString,
Optional: true,
},

"allow_blob_public_access": {
Type: schema.TypeBool,
Computed: true,
Expand Down Expand Up @@ -311,6 +316,7 @@ func dataSourceArmStorageAccountRead(d *schema.ResourceData, meta interface{}) e
if props := resp.AccountProperties; props != nil {
d.Set("access_tier", props.AccessTier)
d.Set("enable_https_traffic_only", props.EnableHTTPSTrafficOnly)
d.Set("min_tls_version", string(props.MinimumTLSVersion))
d.Set("is_hns_enabled", props.IsHnsEnabled)
d.Set("allow_blob_public_access", props.AllowBlobPublicAccess)

Expand Down
28 changes: 28 additions & 0 deletions azurerm/internal/services/storage/resource_arm_storage_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,17 @@ func resourceArmStorageAccount() *schema.Resource {
Default: true,
},

"min_tls_version": {
Type: schema.TypeString,
Optional: true,
Default: string(storage.TLS10),
ValidateFunc: validation.StringInSlice([]string{
string(storage.TLS10),
string(storage.TLS11),
string(storage.TLS12),
}, false),
},

"is_hns_enabled": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -620,6 +631,7 @@ func resourceArmStorageAccountCreate(d *schema.ResourceData, meta interface{}) e
location := azure.NormalizeLocation(d.Get("location").(string))
t := d.Get("tags").(map[string]interface{})
enableHTTPSTrafficOnly := d.Get("enable_https_traffic_only").(bool)
minimumTLSVersion := d.Get("min_tls_version").(string)
isHnsEnabled := d.Get("is_hns_enabled").(bool)
allowBlobPublicAccess := d.Get("allow_blob_public_access").(bool)

Expand All @@ -636,6 +648,7 @@ func resourceArmStorageAccountCreate(d *schema.ResourceData, meta interface{}) e
Kind: storage.Kind(accountKind),
AccountPropertiesCreateParameters: &storage.AccountPropertiesCreateParameters{
EnableHTTPSTrafficOnly: &enableHTTPSTrafficOnly,
MinimumTLSVersion: storage.MinimumTLSVersion(minimumTLSVersion),
NetworkRuleSet: expandStorageAccountNetworkRules(d),
IsHnsEnabled: &isHnsEnabled,
AllowBlobPublicAccess: &allowBlobPublicAccess,
Expand Down Expand Up @@ -872,6 +885,20 @@ func resourceArmStorageAccountUpdate(d *schema.ResourceData, meta interface{}) e
}
}

if d.HasChange("min_tls_version") {
minimumTLSVersion := d.Get("min_tls_version").(string)

opts := storage.AccountUpdateParameters{
AccountPropertiesUpdateParameters: &storage.AccountPropertiesUpdateParameters{
MinimumTLSVersion: storage.MinimumTLSVersion(minimumTLSVersion),
},
}

if _, err := client.Update(ctx, resourceGroupName, storageAccountName, opts); err != nil {
return fmt.Errorf("Error updating Azure Storage Account min_tls_version %q: %+v", storageAccountName, err)
}
}

if d.HasChange("allow_blob_public_access") {
allowBlobPublicAccess := d.Get("allow_blob_public_access").(bool)

Expand Down Expand Up @@ -1039,6 +1066,7 @@ func resourceArmStorageAccountRead(d *schema.ResourceData, meta interface{}) err
if props := resp.AccountProperties; props != nil {
d.Set("access_tier", props.AccessTier)
d.Set("enable_https_traffic_only", props.EnableHTTPSTrafficOnly)
d.Set("min_tls_version", string(props.MinimumTLSVersion))
d.Set("is_hns_enabled", props.IsHnsEnabled)
d.Set("allow_blob_public_access", props.AllowBlobPublicAccess)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,52 @@ func TestAccAzureRMStorageAccount_enableHttpsTrafficOnly(t *testing.T) {
})
}

func TestAccAzureRMStorageAccount_minTLSVersion(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_storage_account", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMStorageAccountDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMStorageAccount_basic(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMStorageAccountExists(data.ResourceName),
),
},
data.ImportStep(),
{
Config: testAccAzureRMStorageAccount_minTLSVersion(data, "TLS1_0"),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMStorageAccountExists(data.ResourceName),
),
},
data.ImportStep(),
{
Config: testAccAzureRMStorageAccount_minTLSVersion(data, "TLS1_1"),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMStorageAccountExists(data.ResourceName),
),
},
data.ImportStep(),
{
Config: testAccAzureRMStorageAccount_minTLSVersion(data, "TLS1_2"),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMStorageAccountExists(data.ResourceName),
),
},
data.ImportStep(),
{
Config: testAccAzureRMStorageAccount_minTLSVersion(data, "TLS1_1"),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMStorageAccountExists(data.ResourceName),
),
magodo marked this conversation as resolved.
Show resolved Hide resolved
},
},
})
}

func TestAccAzureRMStorageAccount_allowBlobPublicAccess(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_storage_account", "test")

Expand Down Expand Up @@ -977,6 +1023,35 @@ resource "azurerm_storage_account" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomString)
}

func testAccAzureRMStorageAccount_minTLSVersion(data acceptance.TestData, tlsVersion string) 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 = "Standard"
account_replication_type = "LRS"
min_tls_version = "%s"

tags = {
environment = "production"
}
}

`, data.RandomInteger, data.Locations.Primary, data.RandomString, tlsVersion)
}

func testAccAzureRMStorageAccount_allowBlobPublicAccess(data acceptance.TestData) string {
return fmt.Sprintf(`

Expand Down
2 changes: 2 additions & 0 deletions website/docs/d/storage_account.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ output "storage_account_tier" {
* `enable_https_traffic_only` - Is traffic only allowed via HTTPS? See [here](https://docs.microsoft.com/en-us/azure/storage/storage-require-secure-transfer/)
for more information.

* `min_tls_version` - The minimum supported TLS version for this storage account.

* `allow_blob_public_access` - Is public access allowed to all blobs or containers in the storage account?

* `is_hns_enabled` - Is Hierarchical Namespace enabled?
Expand Down
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 @@ -97,6 +97,8 @@ The following arguments are supported:
* `enable_https_traffic_only` - (Optional) Boolean flag which forces HTTPS if enabled, see [here](https://docs.microsoft.com/en-us/azure/storage/storage-require-secure-transfer/)
for more information. Defaults to `true`.

* `min_tls_version` - (Optional) The minimum supported TLS version for the storage account. Possible values are `TLS1_0`, `TLS1_1`, and `TLS1_2`. Defaults to `TLS1_0` for new storage accounts.

* `allow_blob_public_access` - Allow or disallow public access to all blobs or containers in the storage account. Defaults to `false`.

* `is_hns_enabled` - (Optional) Is Hierarchical Namespace enabled? This can be used with Azure Data Lake Storage Gen 2 ([see here for more information](https://docs.microsoft.com/en-us/azure/storage/blobs/data-lake-storage-quickstart-create-account/)). Changing this forces a new resource to be created.
Expand Down