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 allowed_copy_scope #19906

Merged
merged 1 commit into from
Jan 10, 2023
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
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 @@ -1766,6 +1779,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 @@ -2101,6 +2126,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 @@ -1352,6 +1352,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 @@ -4125,6 +4154,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