Last active
August 19, 2023 10:13
-
-
Save lAnubisl/a8b95a2391669a5c943271f937dd6752 to your computer and use it in GitHub Desktop.
Terraform Infrastructure | React FrontEnd Application on Azure Storage Account
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "azurerm_resource_group" "rg" { | |
name = "rg-my-react-app" | |
location = "westeurope" | |
} | |
resource "azurerm_storage_account" "sa" { | |
name = "mystorageaccount1985" | |
resource_group_name = azurerm_resource_group.rg.name | |
location = azurerm_resource_group.rg.location | |
account_tier = "Standard" | |
account_replication_type = "LRS" | |
allow_nested_items_to_be_public = true | |
} | |
resource "azurerm_storage_container" "sc" { | |
name = "www" | |
storage_account_name = azurerm_storage_account.sa.name | |
container_access_type = "blob" | |
} | |
resource "azurerm_cdn_profile" "cdn" { | |
name = "my-cdn-profile" | |
location = azurerm_resource_group.rg.location | |
resource_group_name = azurerm_resource_group.rg.name | |
sku = "Standard_Microsoft" | |
} | |
resource "azurerm_cdn_endpoint" "endpoint" { | |
name = "myreactwebsite1985" | |
profile_name = azurerm_cdn_profile.cdn.name | |
location = azurerm_resource_group.rg.location | |
resource_group_name = azurerm_resource_group.rg.name | |
origin_host_header = azurerm_storage_account.sa.primary_blob_host | |
origin_path = "/${azurerm_storage_container.sc.name}" | |
origin { | |
name = "StorageAccountOrigin" | |
host_name = azurerm_storage_account.sa.primary_blob_host | |
} | |
global_delivery_rule { | |
cache_expiration_action { | |
behavior = "Override" | |
duration = "00:05:00" | |
} | |
} | |
delivery_rule { | |
name = "ReactRewriteRule" | |
order = 1 | |
url_file_extension_condition { | |
operator = "LessThan" | |
match_values = ["1"] | |
} | |
url_rewrite_action { | |
source_pattern = "/" | |
destination = "/index.html" | |
preserve_unmatched_path = false | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment