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

Add property allow_blob_public_access to azurerm_storage_account #7739

Merged
merged 2 commits into from
Jul 14, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ func dataSourceArmStorageAccount() *schema.Resource {
Computed: true,
},

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

"is_hns_enabled": {
Type: schema.TypeBool,
Computed: true,
Expand Down Expand Up @@ -307,6 +312,7 @@ func dataSourceArmStorageAccountRead(d *schema.ResourceData, meta interface{}) e
d.Set("access_tier", props.AccessTier)
d.Set("enable_https_traffic_only", props.EnableHTTPSTrafficOnly)
d.Set("is_hns_enabled", props.IsHnsEnabled)
d.Set("allow_blob_public_access", props.AllowBlobPublicAccess)

if customDomain := props.CustomDomain; customDomain != nil {
if err := d.Set("custom_domain", flattenStorageAccountCustomDomain(customDomain)); err != nil {
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 @@ -145,6 +145,12 @@ func resourceArmStorageAccount() *schema.Resource {
ForceNew: true,
},

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

"network_rules": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -611,6 +617,7 @@ func resourceArmStorageAccountCreate(d *schema.ResourceData, meta interface{}) e
t := d.Get("tags").(map[string]interface{})
enableHTTPSTrafficOnly := d.Get("enable_https_traffic_only").(bool)
isHnsEnabled := d.Get("is_hns_enabled").(bool)
allowBlobPublicAccess := d.Get("allow_blob_public_access").(bool)

accountTier := d.Get("account_tier").(string)
replicationType := d.Get("account_replication_type").(string)
Expand All @@ -627,6 +634,7 @@ func resourceArmStorageAccountCreate(d *schema.ResourceData, meta interface{}) e
EnableHTTPSTrafficOnly: &enableHTTPSTrafficOnly,
NetworkRuleSet: expandStorageAccountNetworkRules(d),
IsHnsEnabled: &isHnsEnabled,
AllowBlobPublicAccess: &allowBlobPublicAccess,
},
}

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 @@ -1014,6 +1036,7 @@ func resourceArmStorageAccountRead(d *schema.ResourceData, meta interface{}) err
d.Set("access_tier", props.AccessTier)
d.Set("enable_https_traffic_only", props.EnableHTTPSTrafficOnly)
d.Set("is_hns_enabled", props.IsHnsEnabled)
d.Set("allow_blob_public_access", props.AllowBlobPublicAccess)

if customDomain := props.CustomDomain; customDomain != nil {
if err := d.Set("custom_domain", flattenStorageAccountCustomDomain(customDomain)); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,33 @@ func TestAccAzureRMStorageAccount_enableHttpsTrafficOnly(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_disAllowBlobPublicAccess(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMStorageAccountExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "allow_blob_public_access", "false"),
),
},
},
})
}

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

Expand Down Expand Up @@ -942,6 +969,64 @@ 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_disAllowBlobPublicAccess(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_isHnsEnabledTrue(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 @@ -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.

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

* `is_hns_enabled` - Is Hierarchical Namespace enabled?

* `custom_domain` - A `custom_domain` block as documented below.
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`.

* `allow_blob_public_access` - Allow or disallow public access to all blobs or containers in the storage account. 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.

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