Skip to content

Commit

Permalink
azurerm_storage_account - Support allowed_copy_scope (#19906)
Browse files Browse the repository at this point in the history
Fix #19888
  • Loading branch information
magodo committed Jan 10, 2023
1 parent 2a90ccd commit ce1a809
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
26 changes: 26 additions & 0 deletions internal/services/storage/storage_account_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,15 @@ func resourceStorageAccount() *pluginsdk.Resource {
},
},

"allowed_copy_scope": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
string(storage.AllowedCopyScopePrivateLink),
string(storage.AllowedCopyScopeAAD),
}, false),
},

"sftp_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Expand Down Expand Up @@ -1125,6 +1134,10 @@ func resourceStorageAccountCreate(d *pluginsdk.ResourceData, meta interface{}) e
},
}

if v := d.Get("allowed_copy_scope").(string); v != "" {
parameters.AccountPropertiesCreateParameters.AllowedCopyScope = storage.AllowedCopyScope(v)
}

// For all Clouds except Public, China, and USGovernmentCloud, don't specify "allow_blob_public_access" and "min_tls_version" in request body.
// https://github.com/hashicorp/terraform-provider-azurerm/issues/7812
// https://github.com/hashicorp/terraform-provider-azurerm/issues/8083
Expand Down Expand Up @@ -1769,6 +1782,18 @@ func resourceStorageAccountUpdate(d *pluginsdk.ResourceData, meta interface{}) e
}
}

if d.HasChange("allowed_copy_scope") {
// TODO: Currently, due to Track1 SDK has no way to represent a `null` value in the payload - instead it will be omitted, `allowed_copy_scope` can not be disabled once enabled.
opts := storage.AccountUpdateParameters{
AccountPropertiesUpdateParameters: &storage.AccountPropertiesUpdateParameters{
AllowedCopyScope: storage.AllowedCopyScope(d.Get("allowed_copy_scope").(string)),
},
}
if _, err := client.Update(ctx, id.ResourceGroup, id.Name, opts); err != nil {
return fmt.Errorf("updating Azure Storage Account allowed_copy_scope %q: %+v", id.Name, err)
}
}

supportLevel := resolveStorageAccountServiceSupportLevel(storage.Kind(accountKind), storage.SkuTier(accountTier))

if d.HasChange("blob_properties") {
Expand Down Expand Up @@ -2107,6 +2132,7 @@ func resourceStorageAccountRead(d *pluginsdk.ResourceData, meta interface{}) err
return fmt.Errorf("setting `sas_policy`: %+v", err)
}

d.Set("allowed_copy_scope", props.AllowedCopyScope)
d.Set("sftp_enabled", props.IsSftpEnabled)
}

Expand Down
52 changes: 52 additions & 0 deletions internal/services/storage/storage_account_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,35 @@ func TestAccStorageAccount_sasPolicy(t *testing.T) {
})
}

func TestAccStorageAccount_allowedCopyScope(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_storage_account", "test")
r := StorageAccountResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.allowedCopyScope(data, "AAD"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.allowedCopyScope(data, "PrivateLink"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccStorageAccount_isSftpEnabled(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_storage_account", "test")
r := StorageAccountResource{}
Expand Down Expand Up @@ -4165,6 +4194,29 @@ resource "azurerm_storage_account" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomString)
}

func (r StorageAccountResource) allowedCopyScope(data acceptance.TestData, scope 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"
allowed_copy_scope = %q
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString, scope)
}

func (r StorageAccountResource) emptyShareProperties(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
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 @@ -166,6 +166,8 @@ The following arguments are supported:

* `sas_policy` - (Optional) A `sas_policy` block as defined below.

* `allowed_copy_scope` - (Optional) Restrict copy to and from Storage Accounts within an AAD tenant or with Private Links to the same VNet. Possible values are `AAD` and `PrivateLink`.

* `sftp_enabled` - (Optional) Boolean, enable SFTP for the storage account

-> **NOTE:** SFTP support requires `is_hns_enabled` set to `true`. [More information on SFTP support can be found here](https://learn.microsoft.com/azure/storage/blobs/secure-file-transfer-protocol-support). Defaults to `false`
Expand Down

0 comments on commit ce1a809

Please sign in to comment.