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

Support for content in azurerm_storage_blob data source #18779

Closed
1 task done
gaui opened this issue Oct 14, 2022 · 6 comments
Closed
1 task done

Support for content in azurerm_storage_blob data source #18779

gaui opened this issue Oct 14, 2022 · 6 comments

Comments

@gaui
Copy link

gaui commented Oct 14, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

Currently the azurerm_storage_blob data source supports has the following outputs:

  • id - The ID of the storage blob.
  • url - The URL of the storage blob.
  • type - The type of the storage blob
  • access_tier - The access tier of the storage blob.
  • content_type - The content type of the storage blob.
  • content_md5 - The MD5 sum of the blob contents.
  • metadata - A map of custom blob metadata.

I see that it supports content_md5 but no content. Is there any particular reason not to be able to fetch the content itself, but only the MD5 sum and the type? I would like to suggest that this would be made possible.

Reference:
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/storage_blob

New or Affected Resource(s)/Data Source(s)

azurerm_storage_blob

Potential Terraform Configuration

data "azurerm_storage_blob" "blob" {
  name                   = "blob.txt"
  storage_account_name   = azurerm_storage_account.account.name
  storage_container_name = azurerm_storage_container.container.name
}

output "blob_content" {
  value = data.azurerm_storage_blob.blob.content
}

References

No response

@magodo magodo added enhancement service/storage sdk/not-yet-supported Support for this does not exist in the upstream SDK at this time labels Oct 17, 2022
@magodo
Copy link
Collaborator

magodo commented Oct 17, 2022

@gaui Thank you for submitting this! Currently, the azurerm_storage_blob data source is only exposing the properties of the blob via its get blob propertes API. In order to getting the content, it requires support on the storage SDK.

@tombuildsstuff tombuildsstuff removed the sdk/not-yet-supported Support for this does not exist in the upstream SDK at this time label Oct 17, 2022
@gaui
Copy link
Author

gaui commented Oct 17, 2022

@tombuildsstuff
Copy link
Contributor

hey @gaui

Thanks for opening this issue.

This issue's been requested previously (although unfortunately I can't find the issue/PR right now), and we've previously opted not to expose the contents from this Data Source since this would involve storing the file contents within the state file which would end up causing issues (both due to the size of the state file, and encoding, amongst other issues).

Instead it should be possible to retrieve an existing file using a SAS Token and the http data source - which would allow you to download this to a file, rather than storing this within the State File itself. Would you be able to take a look and see if that works for you here?

Thanks!

@tombuildsstuff
Copy link
Contributor

hey @gaui

Since we've not heard back from you here I'm going to close this issue for now - but if that doesn't work for you then please let us know and we can take another look.

Thanks!

@jsok
Copy link
Contributor

jsok commented Mar 30, 2023

Instead it should be possible to retrieve an existing file using a SAS Token and the http data source - which would allow you to download this to a file, rather than storing this within the State File itself. Would you be able to take a look and see if that works for you here?

After attempting this, it's not exactly concise or easy:

data "azurerm_storage_account_blob_container_sas" "container" {
  connection_string = data.azurerm_storage_account.account.primary_connection_string
  container_name    = "my-container"

  start  = timestamp()
  expiry = timeadd(timestamp(), "1h")

  permissions {
    read   = true
    add    = false
    create = false
    write  = false
    delete = false
    list   = false
  }

  content_type = "application/json"
}

data "http" "artifacts" {
  url = "${data.azurerm_storage_account.account.primary_blob_endpoint}my-container/path/to/file.ext${data.azurerm_storage_account_blob_container_sas.cicd_metadata.sas}"

  lifecycle {
    postcondition {
      condition     = self.status_code == 200
      error_message = "Could not fetch: ${self.response_body}"
    }
  }
}

Surely proper data source support for this would be better.
In some cases the file is small and you'd be more than happy to keep it in the state file.

@github-actions
Copy link

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants