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

Support for Blob Public Access setting in azurerm_storage_account #7700

Closed
wants to merge 5 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ func dataSourceArmStorageAccount() *schema.Resource {
},
},

"allow_blob_public_access": {
Type: schema.TypeBool,
Computed: true,
},

"enable_https_traffic_only": {
Type: schema.TypeBool,
Computed: true,
Expand Down Expand Up @@ -305,6 +310,7 @@ func dataSourceArmStorageAccountRead(d *schema.ResourceData, meta interface{}) e

if props := resp.AccountProperties; props != nil {
d.Set("access_tier", props.AccessTier)
d.Set("allow_blob_public_access", props.AllowBlobPublicAccess)
d.Set("enable_https_traffic_only", props.EnableHTTPSTrafficOnly)
d.Set("is_hns_enabled", props.IsHnsEnabled)

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

"allow_blob_public_access": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},

"enable_https_traffic_only": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -610,6 +616,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)
allowBlobPublicAccess := d.Get("allow_blob_public_access").(bool)
isHnsEnabled := d.Get("is_hns_enabled").(bool)

accountTier := d.Get("account_tier").(string)
Expand All @@ -625,6 +632,7 @@ func resourceArmStorageAccountCreate(d *schema.ResourceData, meta interface{}) e
Kind: storage.Kind(accountKind),
AccountPropertiesCreateParameters: &storage.AccountPropertiesCreateParameters{
EnableHTTPSTrafficOnly: &enableHTTPSTrafficOnly,
AllowBlobPublicAccess: &allowBlobPublicAccess,
NetworkRuleSet: expandStorageAccountNetworkRules(d),
IsHnsEnabled: &isHnsEnabled,
},
Expand Down Expand Up @@ -860,6 +868,20 @@ func resourceArmStorageAccountUpdate(d *schema.ResourceData, meta interface{}) e
}
}

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

opts := storage.AccountUpdateParameters{
AccountPropertiesUpdateParameters: &storage.AccountPropertiesUpdateParameters{
AllowBlobPublicAccess: &allowBlobPublicAccess,
},
}

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

if d.HasChange("identity") {
opts := storage.AccountUpdateParameters{
Identity: expandAzureRmStorageAccountIdentity(d),
Expand Down Expand Up @@ -1013,6 +1035,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("allow_blob_public_access", props.AllowBlobPublicAccess)
d.Set("is_hns_enabled", props.IsHnsEnabled)

if customDomain := props.CustomDomain; customDomain != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,33 @@ func TestAccAzureRMStorageAccount_blobConnectionString(t *testing.T) {
})
}

func TestAccAzureRMStorageAccount_allowBlobPublicAccess(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_allowBlobPublicAccess(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMStorageAccountExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "allow_blob_public_access", "true"),
),
},
data.ImportStep(),
{
Config: testAccAzureRMStorageAccount_allowBlobPublicAccessDisabled(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMStorageAccountExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "allow_blob_public_access", "false"),
),
},
},
})
}

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

Expand Down Expand Up @@ -888,6 +915,60 @@ resource "azurerm_storage_account" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomString)
}

func testAccAzureRMStorageAccount_allowBlobPublicAccess(data acceptance.TestData) 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"
allow_blob_public_access = true

tags = {
environment = "production"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString)
}

func testAccAzureRMStorageAccount_allowBlobPublicAccessDisabled(data acceptance.TestData) 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"
allow_blob_public_access = false

tags = {
environment = "production"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString)
}

func testAccAzureRMStorageAccount_enableHttpsTrafficOnly(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
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 @@ -43,6 +43,8 @@ output "storage_account_tier" {

* `access_tier` - The access tier for `BlobStorage` accounts.

* `allow_blob_public_access` - Can blobs in this storage account be configured for public access.

* `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.

Expand Down
4 changes: 3 additions & 1 deletion website/docs/r/storage_account.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,12 @@ The following arguments are supported:

* `access_tier` - (Optional) Defines the access tier for `BlobStorage`, `FileStorage` and `StorageV2` accounts. Valid options are `Hot` and `Cool`, defaults to `Hot`.

* `allow_blob_public_access` = (Optional) Boolean flag which disallows blobs to be confiured for public access. Enabling it does not allow public access to the blobs directly, each blob still need to be configured to allow public access. Setting this to false will remove all public access from the blobs does not matter per-blob configuration. Defaults to `true`

* `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`.

* `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.
* `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.

-> **NOTE:** When this is set to `true` the `account_tier` argument must be set to `Standard`

Expand Down