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

Introduce content_type to azurerm_storage_blob #1304

Merged
merged 6 commits into from
Jun 12, 2018
Merged

Conversation

JunyiYi
Copy link

@JunyiYi JunyiYi commented May 26, 2018

  • user can specify the blob MIME type (Azure accepts all kinds of string not only MIME, so I didn't add validation rule here)
  • the MIME type will be returned in HTTP header when user access the output url of the blob
  • the MIME type is updatable and unlike other properties in SDK, it is a plain string rather than a pointer

This resolves issue #999 .

@JunyiYi JunyiYi self-assigned this May 26, 2018
@@ -149,6 +156,7 @@ func resourceArmStorageBlobCreate(d *schema.ResourceData, meta interface{}) erro
blobType := d.Get("type").(string)
cont := d.Get("storage_container_name").(string)
sourceUri := d.Get("source_uri").(string)
contentType := d.Get("content_type").(string)

log.Printf("[INFO] Creating blob %q in storage account %q", name, storageAccountName)
if sourceUri != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refer to this article to simplify the happy-path code block:
https://medium.com/@matryer/line-of-sight-in-code-186dd7cdea88

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can pull this out into separate methods - but I think that's outside of the scope of this PR tbh; so let's do that in a separate PR

Copy link
Author

@JunyiYi JunyiYi May 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with @tombuildsstuff . The blob storage code is messy and the fields also make people confused. So let's do it in another PR if possible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, at some point in the future (read: when the SDK's are more stable) we'll be switching over to the new Storage SDKs; which would probably be a sensible time to do this refactoring

@@ -53,6 +54,12 @@ func resourceArmStorageBlob() *schema.Resource {
Default: 0,
ValidateFunc: validateArmStorageBlobSize,
},
"content_type": {
Type: schema.TypeString,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should do a state migration test here? Just to make sure it doesn't break anything downstream?

Copy link
Author

@JunyiYi JunyiYi May 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I run the new terraform plan after the old terraform apply, and it turns out nothing has been changed. I think there is not needs to do state migration here. @katbyte @tombuildsstuff @paultyng what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

related question below: where does this default value come from?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we also document this new field in the docs (website/docs/r/storage_blob.html.markdown)

Copy link
Author

@JunyiYi JunyiYi Jun 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. The default value comes from Content-Type section in https://docs.microsoft.com/en-us/rest/api/storageservices/put-blob#request-headers-all-blob-types. And blobs created by old plugin have the application/octet-stream content type as well.

Copy link
Collaborator

@WodansSon WodansSon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a question, but other than that LGTM.

Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor comments (sorry, forgot to hit submit yesterday) - but this is otherwise off to a good start 👍

blob.Properties.ContentType = d.Get("content_type").(string)
}

err = blob.SetProperties(nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we pass in the SetBlobPropertiesOptions object here? we should pass in a sensible timeout here too

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return fmt.Errorf("Error getting storage account %s: %+v", storageAccountName, err)
}
if !accountExists {
return fmt.Errorf("Storage account %s not found", storageAccountName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we append the resource group name in here?

@@ -556,6 +600,13 @@ func resourceArmStorageBlobRead(d *schema.ResourceData, meta interface{}) error

container := blobClient.GetContainerReference(storageContainerName)
blob := container.GetBlobReference(name)

err = blob.GetProperties(nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we pass in the GetBlobPropertiesOptions object here? we should pass in a sensible timeout here too

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"content_type": {
Type: schema.TypeString,
Optional: true,
Default: "application/octet-stream",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where does this default come from?

Copy link
Author

@JunyiYi JunyiYi Jun 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. The default value comes from Content-Type section in https://docs.microsoft.com/en-us/rest/api/storageservices/put-blob#request-headers-all-blob-types. And blobs created by old plugin have the application/octet-stream content type as well.

@@ -53,6 +54,12 @@ func resourceArmStorageBlob() *schema.Resource {
Default: 0,
ValidateFunc: validateArmStorageBlobSize,
},
"content_type": {
Type: schema.TypeString,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

related question below: where does this default value come from?

@@ -149,6 +156,7 @@ func resourceArmStorageBlobCreate(d *schema.ResourceData, meta interface{}) erro
blobType := d.Get("type").(string)
cont := d.Get("storage_container_name").(string)
sourceUri := d.Get("source_uri").(string)
contentType := d.Get("content_type").(string)

log.Printf("[INFO] Creating blob %q in storage account %q", name, storageAccountName)
if sourceUri != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, at some point in the future (read: when the SDK's are more stable) we'll be switching over to the new Storage SDKs; which would probably be a sensible time to do this refactoring

@@ -666,3 +711,45 @@ resource "azurerm_storage_blob" "destination" {
}
`, rInt, location, rString, sourceBlobName)
}

func testAccAzureRMStorageBlobPage_blockContentType(rInt int, rString, sourceBlobName, location, contentType string) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor we've got a vague convention here of making these (rInt, rString, location, [others])

@@ -53,6 +54,12 @@ func resourceArmStorageBlob() *schema.Resource {
Default: 0,
ValidateFunc: validateArmStorageBlobSize,
},
"content_type": {
Type: schema.TypeString,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we also document this new field in the docs (website/docs/r/storage_blob.html.markdown)

if err != nil {
return fmt.Errorf("Error getting properties of blob %s (container %s, storage account %s): %+v", name, storageContainerName, storageAccountName, err)
}
d.Set("content_type", blob.Properties.ContentType)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we nil-check if Properties != nil here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JunyiYi JunyiYi dismissed tombuildsstuff’s stale review June 8, 2018 22:02

Dismiss the review since all comments have been resolved.

Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JunyiYi,

Thank you for the changes, LGTM 👍

@katbyte
Copy link
Collaborator

katbyte commented Jun 12, 2018

Tests pass:
screen shot 2018-06-11 at 23 15 53

@katbyte katbyte merged commit 30077d9 into master Jun 12, 2018
@katbyte katbyte deleted the blob_content_type branch June 12, 2018 06:18
@katbyte katbyte modified the milestones: Soon, 1.7.0 Jun 12, 2018
katbyte added a commit that referenced this pull request Jun 12, 2018
@ghost
Copy link

ghost commented Mar 30, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants