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

Allow blob upload in archive tier #22250

Merged
merged 4 commits into from
Jan 25, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 12 additions & 12 deletions internal/services/storage/storage_blob_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,18 +252,6 @@ func resourceStorageBlobUpdate(d *pluginsdk.ResourceData, meta interface{}) erro
return fmt.Errorf("building Blobs Client: %s", err)
}

if d.HasChange("access_tier") {
// this is only applicable for Gen2/BlobStorage accounts
log.Printf("[DEBUG] Updating Access Tier for Blob %q (Container %q / Account %q)...", id.BlobName, id.ContainerName, id.AccountName)
accessTier := blobs.AccessTier(d.Get("access_tier").(string))

if _, err := blobsClient.SetTier(ctx, id.AccountName, id.ContainerName, id.BlobName, accessTier); err != nil {
return fmt.Errorf("updating Access Tier for Blob %q (Container %q / Account %q): %s", id.BlobName, id.ContainerName, id.AccountName, err)
}

log.Printf("[DEBUG] Updated Access Tier for Blob %q (Container %q / Account %q).", id.BlobName, id.ContainerName, id.AccountName)
}

if d.HasChange("content_type") || d.HasChange("cache_control") {
log.Printf("[DEBUG] Updating Properties for Blob %q (Container %q / Account %q)...", id.BlobName, id.ContainerName, id.AccountName)
input := blobs.SetPropertiesInput{
Expand Down Expand Up @@ -299,6 +287,18 @@ func resourceStorageBlobUpdate(d *pluginsdk.ResourceData, meta interface{}) erro
log.Printf("[DEBUG] Updated MetaData for Blob %q (Container %q / Account %q).", id.BlobName, id.ContainerName, id.AccountName)
}

if d.HasChange("access_tier") {
// this is only applicable for Gen2/BlobStorage accounts
log.Printf("[DEBUG] Updating Access Tier for Blob %q (Container %q / Account %q)...", id.BlobName, id.ContainerName, id.AccountName)
accessTier := blobs.AccessTier(d.Get("access_tier").(string))

if _, err := blobsClient.SetTier(ctx, id.AccountName, id.ContainerName, id.BlobName, accessTier); err != nil {
return fmt.Errorf("updating Access Tier for Blob %q (Container %q / Account %q): %s", id.BlobName, id.ContainerName, id.AccountName, err)
}

log.Printf("[DEBUG] Updated Access Tier for Blob %q (Container %q / Account %q).", id.BlobName, id.ContainerName, id.AccountName)
}

return resourceStorageBlobRead(d, meta)
}

Expand Down
33 changes: 33 additions & 0 deletions internal/services/storage/storage_blob_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,21 @@ func TestAccStorageBlob_update(t *testing.T) {
})
}

func TestAccStorageBlob_archive(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_storage_blob", "test")
r := StorageBlobResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.archive(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("parallelism", "size", "type", "source_content"),
})
}

func (r StorageBlobResource) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := blobs.ParseResourceID(state.ID)
if err != nil {
Expand Down Expand Up @@ -1106,6 +1121,24 @@ resource "azurerm_storage_container" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomString, accessLevel)
}

func (r StorageBlobResource) archive(data acceptance.TestData) string {
template := r.template(data, "private")
return fmt.Sprintf(`
provider "azurerm" {}

%s

resource "azurerm_storage_blob" "test" {
name = "rick.morty"
storage_account_name = azurerm_storage_account.test.name
storage_container_name = azurerm_storage_container.test.name
type = "Block"
source_content = "Wubba Lubba Dub Dub"
access_tier = "Archive"
}
`, template)
}

func populateTempFile(input *os.File) error {
if err := input.Truncate(25*1024*1024 + 512); err != nil {
return fmt.Errorf("Failed to truncate file to 25M")
Expand Down