-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Add support for static website to azurerm_storage_account #1903
Comments
For those who can not wait until this feature lands in stable terraform and still want to manage their storage with static website hosting enabled via terraform, I have a possible workaround. First, I tried creating azurerm_template_deployment and enable the static website feature via an ARM template. Unfortunately this is not possible, because static website feature is also not available via arm templates yet, see here. It is only possible via Blob Service REST API since API Version 2018-03-28 which you can use via azure cli. So the workaround is to run enable static website via azure cli using terraform's resource "azurerm_storage_account" "static_website" {
account_replication_type = "RAGRS"
account_tier = "Standard"
account_kind = "StorageV2"
location = "westeurope"
name = "static_website_storage_account"
resource_group_name = "static_website_rg"
enable_https_traffic_only = true
provisioner "local-exec" {
command = <<EOF
az extension add --name storage-preview
az storage blob service-properties update \
--subscription "${var.subscription_id}" \
--account-name static_website_storage_account \
--static-website \
--404-document 404.html \
--index-document index.html
EOF
}
} This will make sure that the static website feature is enabled via cli right after the storage account resource is created. Downside of this is that the command will never be executed when you import an existing storage account into your tfstate and just want to enable static website later. To allow this, you can move the resource "null_resource" "static_website_cmd" {
provisioner "local-exec" {
command = <<EOF
az extension add --name storage-preview
az storage blob service-properties update \
--subscription "${var.subscription_id}" \
--account-name static_website_storage_account \
--static-website \
--404-document 404.html \
--index-document index.html
EOF
}
depends_on = ["azurerm_storage_account.static_website"]
} This way you are more flexible, e.g. you can taint the null_resource (which manually marks the resource for redeployment in the tfstate) and by that triggers a re-execution of the command. Tainting can be done like this: $ terraform taint -module my_module null_resource.static_website_cmd
$ terraform apply
...
-/+ module.my_module.null_resource.static_website_cmd (tainted) (new resource required)
id: "123456789123456789" => <computed> (forces new resource)
... |
Hi @hughtopping, @0x7f I looked at the latest version of the SDK & storage API and I don't see any sign of these properties 🙁 Until they are in the SDK this is unfortunately blocked. |
Hi @katbyte true, the Azure Go SDK does not support it, but there is also the azure-storage-blog-go SDK that actually has support for it, see here. To be honest, I don't know the difference between the two SDKs, especially since both are provided by Azure. Maybe it is possible to use that one instead? |
@0x7f there's several blocking issues in the new Storage SDK which mean we're unable to migrate over to using them at this time, unfortunately. |
Here the code provided by Microsoft blog using the provisionner
source : terraform-jamstack-azure-gatsby-azure-pipelines-git |
Good suggestion! Just tested it and I found a few issues with it...
|
@pwelch @ykhemani Here's the Azure issue I was up against this week. If this were a native Terraform feature, instead of a |
@pburkholder, yes waiting for this feature. |
So does this mean it's being ignored by hashicorp devs ? |
@Djiit no, unfortunately there's multiple blockers preventing us from adopting the new Storage SDK (as mentioned above) - whilst we're working on a solution for this, unfortunately we don't have a timeline (which is why this is in the |
Hello @kvaes and @tombuildsstuff I followed up on this and was able to successfully configure the storage account for website hosting. Were you able to figure out a way to output the URL? Looking at the resource documentation I thought that maybe primary_blob_endpoint was the way to go but this is not the correct endpoint and I couldn't find anything else... Any ideas? Thanks |
I'm using "data" "storage_account" "primary_web_endpoint" output attibute. https://www.terraform.io/docs/providers/azurerm/d/storage_account.html#primary_web_endpoint |
missed that. worked like a charm. thanks! |
Since it looks like this can stay a while open, I created a module to wrap the at CLI command in a reusable way: https://registry.terraform.io/modules/StefanSchoof/static-website/azurerm |
Upstream issue: tombuildsstuff/giovanni#17 |
Hi there team. Just wondering if there's any progress on this? |
I'm using Terraform Cloud which does not have the Any advice on a better workaround is welcome @WillAtHashicorp I've tried for a little too long to get az cli working on TF Cloud but there's no standalone install I can pull and configure that'll work on the runner as far as I've been able to manage. |
I too am eagerly awaiting progress on this issue. What's the latest? |
This is now unblocked, I added support for it to the upstream library in tombuildsstuff/giovanni#21 Thanks for the review @tombuildsstuff :) |
@timja thanks again for that PR - I'm going to open a PR shortly to vendor v0.7.0 into this Provider, at which point it should be possible for someone to take a look at this :) |
Exciting news! Can't wait to use it! 👍 |
@tombuildsstuff So, when will this feature be added to the schema? It appears it was released in provider 1.39.0 but the schema hasn't been updated to allow the configuration. |
Opened a PR to update the schema 👍 |
This has been released in version 2.0.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example: provider "azurerm" {
version = "~> 2.0.0"
}
# ... other configuration ... |
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! |
Community Note
Description
Static website hosting for Azure Storage is now in public preview. See here for Azure announcement.
Currently this can be added with the Azure Portal UI, but is missing from the
azurerm_storage_account
Terraform resource.New or Affected Resource(s)
Potential Terraform Configuration
References
The text was updated successfully, but these errors were encountered: