Skip to content

Commit f24dde3

Browse files
authored
Improve cors rules settings (#17)
* Added possibility for setting multiple cors rules * Corrected small typo errors
1 parent 7b7ff68 commit f24dde3

2 files changed

Lines changed: 62 additions & 15 deletions

File tree

main.tf

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,16 @@ resource "azurerm_storage_account" "storage_account" {
5656
content {
5757
versioning_enabled = local.storage_account[each.key].blob_properties.versioning_enabled
5858
change_feed_enabled = local.storage_account[each.key].blob_properties.change_feed_enabled
59-
default_service_version = local.storage_account[each.key].blob_properties.change_feed_default_service_versionenabled
59+
default_service_version = local.storage_account[each.key].blob_properties.default_service_version
6060
last_access_time_enabled = local.storage_account[each.key].blob_properties.last_access_time_enabled
6161
dynamic "cors_rule" {
6262
for_each = local.storage_account[each.key].blob_properties.cors_rule
6363
content {
64-
allowed_headers = local.storage_account[each.key].blob_properties.cors_rule.allowed_headers
65-
allowed_methods = local.storage_account[each.key].blob_properties.cors_rule.allowed_methods
66-
allowed_origins = local.storage_account[each.key].blob_properties.cors_rule.allowed_origins
67-
exposed_headers = local.storage_account[each.key].blob_properties.cors_rule.exposed_headers
68-
max_age_in_seconds = local.storage_account[each.key].blob_properties.cors_rule.max_age_in_seconds
64+
allowed_headers = local.storage_account[each.key].blob_properties.cors_rule[cors_rule.key].allowed_headers
65+
allowed_methods = local.storage_account[each.key].blob_properties.cors_rule[cors_rule.key].allowed_methods
66+
allowed_origins = local.storage_account[each.key].blob_properties.cors_rule[cors_rule.key].allowed_origins
67+
exposed_headers = local.storage_account[each.key].blob_properties.cors_rule[cors_rule.key].exposed_headers
68+
max_age_in_seconds = local.storage_account[each.key].blob_properties.cors_rule[cors_rule.key].max_age_in_seconds
6969
}
7070
}
7171
dynamic "delete_retention_policy" {
@@ -77,7 +77,7 @@ resource "azurerm_storage_account" "storage_account" {
7777
dynamic "container_delete_retention_policy" {
7878
for_each = local.storage_account[each.key].blob_properties.container_delete_retention_policy
7979
content {
80-
days = local.storage_account[each.key].blob_properties.delete_retention_policy.days
80+
days = local.storage_account[each.key].blob_properties.container_delete_retention_policy.days
8181
}
8282
}
8383
}
@@ -89,11 +89,11 @@ resource "azurerm_storage_account" "storage_account" {
8989
dynamic "cors_rule" {
9090
for_each = local.storage_account[each.key].queue_properties.cors_rule
9191
content {
92-
allowed_headers = local.storage_account[each.key].queue_properties.cors_rule.allowed_headers
93-
allowed_methods = local.storage_account[each.key].queue_properties.cors_rule.allowed_methods
94-
allowed_origins = local.storage_account[each.key].queue_properties.cors_rule.allowed_origins
95-
exposed_headers = local.storage_account[each.key].queue_properties.cors_rule.exposed_headers
96-
max_age_in_seconds = local.storage_account[each.key].queue_properties.cors_rule.max_age_in_seconds
92+
allowed_headers = local.storage_account[each.key].queue_properties.cors_rule[cors_rule.key].allowed_headers
93+
allowed_methods = local.storage_account[each.key].queue_properties.cors_rule[cors_rule.key].allowed_methods
94+
allowed_origins = local.storage_account[each.key].queue_properties.cors_rule[cors_rule.key].allowed_origins
95+
exposed_headers = local.storage_account[each.key].queue_properties.cors_rule[cors_rule.key].exposed_headers
96+
max_age_in_seconds = local.storage_account[each.key].queue_properties.cors_rule[cors_rule.key].max_age_in_seconds
9797
}
9898
}
9999
dynamic "logging" {

variables.tf

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,22 @@ locals {
4949
type = ""
5050
identity_ids = null
5151
}
52-
blob_properties = {}
53-
queue_properties = {}
54-
static_website = {}
52+
blob_properties = {
53+
versioning_enabled = false
54+
change_feed_enabled = false
55+
default_service_version = "2020-06-12"
56+
last_access_time_enabled = false
57+
cors_rule = {}
58+
delete_retention_policy = {}
59+
container_delete_retention_policy = {}
60+
}
61+
queue_properties = {
62+
cors_rule = {}
63+
logging = {}
64+
minute_metrics = {}
65+
hour_metrics = {}
66+
}
67+
static_website = {}
5568
network_rules = {
5669
default_action = ""
5770
bypass = null
@@ -94,6 +107,18 @@ locals {
94107
for storage_account in keys(var.storage_account) :
95108
storage_account => merge(local.default.storage_account, var.storage_account[storage_account])
96109
}
110+
storage_account_blob_properties_values = {
111+
for storage_account in keys(var.storage_account) :
112+
storage_account => {
113+
blob_properties = merge(local.default.storage_account.blob_properties, local.storage_account_values[storage_account].blob_properties)
114+
}
115+
}
116+
storage_account_queue_properties_values = {
117+
for storage_account in keys(var.storage_account) :
118+
storage_account => {
119+
queue_properties = merge(local.default.storage_account.queue_properties, local.storage_account_values[storage_account].queue_properties)
120+
}
121+
}
97122
storage_share_values = {
98123
for storage_share in keys(var.storage_share) :
99124
storage_share => merge(local.default.storage_share, var.storage_share[storage_share])
@@ -108,6 +133,28 @@ locals {
108133
#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"] :
109134
for config in ["custom_domain", "customer_managed_key", "identity", "static_website", "azure_files_authentication", "routing", ] :
110135
config => merge(local.default.storage_account[config], local.storage_account_values[storage_account][config])
136+
},
137+
{
138+
blob_properties = merge(
139+
local.storage_account_blob_properties_values[storage_account].blob_properties,
140+
{
141+
cors_rule = {
142+
for key in keys(local.storage_account_blob_properties_values[storage_account].blob_properties.cors_rule) :
143+
key => merge(local.default.storage_account.blob_properties.cors_rule, local.storage_account_blob_properties_values[storage_account].blob_properties.cors_rule[key])
144+
}
145+
}
146+
)
147+
},
148+
{
149+
queue_properties = merge(
150+
local.storage_account_queue_properties_values[storage_account].queue_properties,
151+
{
152+
cors_rule = {
153+
for key in keys(local.storage_account_queue_properties_values[storage_account].queue_properties.cors_rule) :
154+
key => merge(local.default.storage_account.queue_properties.cors_rule, local.storage_account_queue_properties_values[storage_account].queue_properties.cors_rule[key])
155+
}
156+
}
157+
)
111158
}
112159
)
113160
}

0 commit comments

Comments
 (0)