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

Improve cors rules settings #17

Merged
merged 2 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ resource "azurerm_storage_account" "storage_account" {
content {
versioning_enabled = local.storage_account[each.key].blob_properties.versioning_enabled
change_feed_enabled = local.storage_account[each.key].blob_properties.change_feed_enabled
default_service_version = local.storage_account[each.key].blob_properties.change_feed_default_service_versionenabled
default_service_version = local.storage_account[each.key].blob_properties.default_service_version
last_access_time_enabled = local.storage_account[each.key].blob_properties.last_access_time_enabled
dynamic "cors_rule" {
for_each = local.storage_account[each.key].blob_properties.cors_rule
content {
allowed_headers = local.storage_account[each.key].blob_properties.cors_rule.allowed_headers
allowed_methods = local.storage_account[each.key].blob_properties.cors_rule.allowed_methods
allowed_origins = local.storage_account[each.key].blob_properties.cors_rule.allowed_origins
exposed_headers = local.storage_account[each.key].blob_properties.cors_rule.exposed_headers
max_age_in_seconds = local.storage_account[each.key].blob_properties.cors_rule.max_age_in_seconds
allowed_headers = local.storage_account[each.key].blob_properties.cors_rule[cors_rule.key].allowed_headers
allowed_methods = local.storage_account[each.key].blob_properties.cors_rule[cors_rule.key].allowed_methods
allowed_origins = local.storage_account[each.key].blob_properties.cors_rule[cors_rule.key].allowed_origins
exposed_headers = local.storage_account[each.key].blob_properties.cors_rule[cors_rule.key].exposed_headers
max_age_in_seconds = local.storage_account[each.key].blob_properties.cors_rule[cors_rule.key].max_age_in_seconds
}
}
dynamic "delete_retention_policy" {
Expand All @@ -77,7 +77,7 @@ resource "azurerm_storage_account" "storage_account" {
dynamic "container_delete_retention_policy" {
for_each = local.storage_account[each.key].blob_properties.container_delete_retention_policy
content {
days = local.storage_account[each.key].blob_properties.delete_retention_policy.days
days = local.storage_account[each.key].blob_properties.container_delete_retention_policy.days
}
}
}
Expand All @@ -89,11 +89,11 @@ resource "azurerm_storage_account" "storage_account" {
dynamic "cors_rule" {
for_each = local.storage_account[each.key].queue_properties.cors_rule
content {
allowed_headers = local.storage_account[each.key].queue_properties.cors_rule.allowed_headers
allowed_methods = local.storage_account[each.key].queue_properties.cors_rule.allowed_methods
allowed_origins = local.storage_account[each.key].queue_properties.cors_rule.allowed_origins
exposed_headers = local.storage_account[each.key].queue_properties.cors_rule.exposed_headers
max_age_in_seconds = local.storage_account[each.key].queue_properties.cors_rule.max_age_in_seconds
allowed_headers = local.storage_account[each.key].queue_properties.cors_rule[cors_rule.key].allowed_headers
allowed_methods = local.storage_account[each.key].queue_properties.cors_rule[cors_rule.key].allowed_methods
allowed_origins = local.storage_account[each.key].queue_properties.cors_rule[cors_rule.key].allowed_origins
exposed_headers = local.storage_account[each.key].queue_properties.cors_rule[cors_rule.key].exposed_headers
max_age_in_seconds = local.storage_account[each.key].queue_properties.cors_rule[cors_rule.key].max_age_in_seconds
}
}
dynamic "logging" {
Expand Down
53 changes: 50 additions & 3 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,22 @@ locals {
type = ""
identity_ids = null
}
blob_properties = {}
queue_properties = {}
static_website = {}
blob_properties = {
versioning_enabled = false
change_feed_enabled = false
default_service_version = "2020-06-12"
last_access_time_enabled = false
cors_rule = {}
delete_retention_policy = {}
container_delete_retention_policy = {}
}
queue_properties = {
cors_rule = {}
logging = {}
minute_metrics = {}
hour_metrics = {}
}
static_website = {}
network_rules = {
default_action = ""
bypass = null
Expand Down Expand Up @@ -94,6 +107,18 @@ locals {
for storage_account in keys(var.storage_account) :
storage_account => merge(local.default.storage_account, var.storage_account[storage_account])
}
storage_account_blob_properties_values = {
for storage_account in keys(var.storage_account) :
storage_account => {
blob_properties = merge(local.default.storage_account.blob_properties, local.storage_account_values[storage_account].blob_properties)
}
}
storage_account_queue_properties_values = {
for storage_account in keys(var.storage_account) :
storage_account => {
queue_properties = merge(local.default.storage_account.queue_properties, local.storage_account_values[storage_account].queue_properties)
}
}
storage_share_values = {
for storage_share in keys(var.storage_share) :
storage_share => merge(local.default.storage_share, var.storage_share[storage_share])
Expand All @@ -108,6 +133,28 @@ locals {
#for config in ["custom_domain", "customer_managed_key", "identity", "blob_properties", "queue_properties", "static_website", "network_rules", "azure_files_authentication", "routing", "queue_encryption_key_type", "table_encryption_key_type", "infrastructure_encryption_enabled"] :
for config in ["custom_domain", "customer_managed_key", "identity", "static_website", "azure_files_authentication", "routing", ] :
config => merge(local.default.storage_account[config], local.storage_account_values[storage_account][config])
},
{
blob_properties = merge(
local.storage_account_blob_properties_values[storage_account].blob_properties,
{
cors_rule = {
for key in keys(local.storage_account_blob_properties_values[storage_account].blob_properties.cors_rule) :
key => merge(local.default.storage_account.blob_properties.cors_rule, local.storage_account_blob_properties_values[storage_account].blob_properties.cors_rule[key])
}
}
)
},
{
queue_properties = merge(
local.storage_account_queue_properties_values[storage_account].queue_properties,
{
cors_rule = {
for key in keys(local.storage_account_queue_properties_values[storage_account].queue_properties.cors_rule) :
key => merge(local.default.storage_account.queue_properties.cors_rule, local.storage_account_queue_properties_values[storage_account].queue_properties.cors_rule[key])
}
}
)
}
)
}
Expand Down