-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Conversation
@@ -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 != "" { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
)
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
There was a problem hiding this 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 👍
azurerm/resource_arm_storage_blob.go
Outdated
blob.Properties.ContentType = d.Get("content_type").(string) | ||
} | ||
|
||
err = blob.SetProperties(nil) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default timeout 30s should be just fine: https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-blob-service-operations.
azurerm/resource_arm_storage_blob.go
Outdated
return fmt.Errorf("Error getting storage account %s: %+v", storageAccountName, err) | ||
} | ||
if !accountExists { | ||
return fmt.Errorf("Storage account %s not found", storageAccountName) |
There was a problem hiding this comment.
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?
azurerm/resource_arm_storage_blob.go
Outdated
@@ -556,6 +600,13 @@ func resourceArmStorageBlobRead(d *schema.ResourceData, meta interface{}) error | |||
|
|||
container := blobClient.GetContainerReference(storageContainerName) | |||
blob := container.GetBlobReference(name) | |||
|
|||
err = blob.GetProperties(nil) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default timeout 30s should be just fine: https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-blob-service-operations.
"content_type": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Default: "application/octet-stream", |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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 != "" { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
)
azurerm/resource_arm_storage_blob.go
Outdated
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Properties
is not a pointer type: https://github.com/terraform-providers/terraform-provider-azurerm/blob/master/vendor/github.com/Azure/azure-sdk-for-go/storage/blob.go#L34. Actually both Properties
and ContentType
are not pointer types.
Dismiss the review since all comments have been resolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the changes, LGTM 👍
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 👉 hashibot-feedback@hashicorp.com. Thanks! |
url
of the blobThis resolves issue #999 .