Skip to content

Commit

Permalink
Merge pull request #1888 from aztfmod/ak-fix-urlpathmap
Browse files Browse the repository at this point in the history
Resolved #1840 Issue with updating url_path_map
  • Loading branch information
arnaudlh authored Jan 5, 2024
2 parents 4d9f5a0 + 2720bda commit 5ebb0a4
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 13 deletions.
37 changes: 29 additions & 8 deletions examples/networking/app_gateway/301-agw-v1/agw_application.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ application_gateway_applications_v1 = {
# key = ""
# }
}
demo2 = {
name = "demo_pool02"
fqdns = ["babc-app-ptsg-5sspdemoappap2-lo.babc-ase-ase01-pd.appserviceenvironment.net"]
}
demo3 = {
name = "demo_pool03"
fqdns = ["babc-app-ptsg-5sspdemoappap3-lo.babc-ase-ase01-pd.appserviceenvironment.net"]
}
demo4 = {
name = "demo_pool04"
fqdns = ["babc-app-ptsg-5sspdemoappap4-lo.babc-ase-ase01-pd.appserviceenvironment.net"]
}
}

http_settings = {
Expand Down Expand Up @@ -83,12 +95,14 @@ application_gateway_applications_v1 = {

url_path_maps = {
demo = {
name = "test_path_map"
paths = "/test/*"
rule_name = "test_path_rule"
backend_pool_key = "demo"
http_settings_key = "demo"
rewrite_rule_set_key = "rrs1"
name = "test_path_map"
paths = "/test/*"
rule_name = "test_path_rule"
default_backend_pool_key = "demo"
backend_pool_key = "demo"
default_http_settings_key = "demo"
http_settings_key = "demo"
rewrite_rule_set_key = "rrs1"
}
}

Expand All @@ -97,14 +111,21 @@ application_gateway_applications_v1 = {
name = "rule1-demo"
url_path_map_key = "demo"
paths = "/test/rule1/*"
backend_pool_key = "demo"
backend_pool_key = "demo2"
http_settings_key = "demo"
}
rule2 = {
name = "rule2-demo"
url_path_map_key = "demo"
paths = "/test/rule2/*"
backend_pool_key = "demo"
backend_pool_key = "demo3"
http_settings_key = "demo"
}
rule3 = {
name = "rule3-demo"
url_path_map_key = "demo"
paths = "/test/rule3/*"
backend_pool_key = "demo4"
http_settings_key = "demo"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,35 @@ case "${RESOURCE}" in
--name ${NAME} ${certfile}${keyvaultsecretid}
;;
PATHMAP)
addresspool=$([ -z "${ADDRESS_POOL}" ] && echo "" || echo "--address-pool ${ADDRESS_POOL} --default-address-pool ${ADDRESS_POOL} ")
httpsettings=$([ -z "${HTTP_SETTINGS}" ] && echo "" || echo "--http-settings ${HTTP_SETTINGS} --default-http-settings ${HTTP_SETTINGS} ")
defaultaddresspool=$([ -z "${DEFAULT_ADDRESS_POOL}" ] && echo "" || echo "--default-address-pool ${DEFAULT_ADDRESS_POOL} ")
addresspool=$([ -z "${ADDRESS_POOL}" ] && echo "" || echo "--address-pool ${ADDRESS_POOL} ")
defaulthttpsettings=$([ -z "${DEFAULT_HTTP_SETTINGS}" ] && echo "" || echo "--default-http-settings ${DEFAULT_HTTP_SETTINGS} ")
httpsettings=$([ -z "${HTTP_SETTINGS}" ] && echo "" || echo "--http-settings ${HTTP_SETTINGS} ")
defaultredirectconfig=$([ -z "${DEFAULT_REDIRECT_CONFIG}" ] && echo "" || echo "--default-redirect-config ${DEFAULT_REDIRECT_CONFIG} ")
redirectconfig=$([ -z "${REDIRECT_CONFIG}" ] && echo "" || echo "--redirect-config ${REDIRECT_CONFIG} ")
defaultrewriteruleset=$([ -z "${DEFAULT_REWRITE_RULE_SET}" ] && echo "" || echo "--default-rewrite-rule-set ${DEFAULT_REWRITE_RULE_SET} ")
rewriteruleset=$([ -z "${REWRITE_RULE_SET}" ] && echo "" || echo "--rewrite-rule-set ${REWRITE_RULE_SET} ")
rulename=$([ -z "${RULE_NAME}" ] && echo "" || echo "--rule-name ${RULE_NAME} ")
wafpolicy=$([ -z "${WAF_POLICY}" ] && echo "" || echo "--waf-policy ${WAF_POLICY} ")

execute_with_backoff az network application-gateway url-path-map create -g ${RG_NAME} --gateway-name ${APPLICATION_GATEWAY_NAME} \
-n ${NAME} --paths ${PATHS} ${addresspool}${httpsettings}${redirectconfig}${rewriteruleset}${rulename}${wafpolicy}
# Check if pathmap already created
output=$(az network application-gateway url-path-map show -g ${RG_NAME} --gateway-name ${APPLICATION_GATEWAY_NAME} -n ${NAME} 2> error.txt)

# Check if the error file contains the ResourceNotFoundError message
if grep -q "ResourceNotFoundError" error.txt; then
execute_with_backoff az network application-gateway url-path-map create -g ${RG_NAME} --gateway-name ${APPLICATION_GATEWAY_NAME} \
-n ${NAME} --paths ${PATHS} ${defaultaddresspool}${addresspool}${defaulthttpsettings}${httpsettings} \
${defaultredirectconfig}${redirectconfig}${defaultrewriteruleset}${rewriteruleset}${rulename}${wafpolicy}
else
execute_with_backoff az network application-gateway url-path-map update -g ${RG_NAME} --gateway-name ${APPLICATION_GATEWAY_NAME} \
-n ${NAME} ${defaultaddresspool}${defaulthttpsettings}${defaultredirectconfig}${defaultrewriteruleset}
execute_with_backoff az network application-gateway url-path-map rule create -g ${RG_NAME} --gateway-name ${APPLICATION_GATEWAY_NAME} \
-n ${RULE_NAME} --path-map-name ${NAME} --paths ${PATHS} ${addresspool}${httpsettings}${redirectconfig}${rewriteruleset}${wafpolicy}
fi

# Remove the error file
rm error.txt

;;
PATHRULE)
addresspool=$([ -z "${ADDRESS_POOL}" ] && echo "" || echo "--address-pool ${ADDRESS_POOL} ")
Expand Down Expand Up @@ -215,7 +235,7 @@ case "${RESOURCE}" in
ignorecase=$([ -z "${IGNORE_CASE}" ] && echo "" || echo "--ignore-case ${IGNORE_CASE} ")
negate=$([ -z "${NEGATE}" ] && echo "" || echo "--negate ${NEGATE} ")
pattern=$([ -z "${PATTERN}" ] && echo "" || echo "--pattern ${PATTERN} ")

2
execute_with_backoff az network application-gateway rewrite-rule condition create -g ${RG_NAME} \
--gateway-name ${APPLICATION_GATEWAY_NAME} --variable ${VARIABLE} --rule-set-name ${RULE_SET_NAME} --rule-name ${RULE_NAME}\
${ignorecase} ${negate} ${pattern}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ resource "null_resource" "set_url_path_map" {
APPLICATION_GATEWAY_ID = var.application_gateway.id
NAME = each.value.name
PATHS = each.value.paths
DEFAULT_ADDRESS_POOL = try(var.settings.backend_pools[each.value.default_backend_pool_key].name, var.settings.backend_pools[each.value.backend_pool_key].name)
ADDRESS_POOL = var.settings.backend_pools[each.value.backend_pool_key].name
DEFAULT_HTTP_SETTINGS = try(var.settings.http_settings[each.value.default_http_settings_key].name, var.settings.http_settings[each.value.http_settings_key].name)
HTTP_SETTINGS = var.settings.http_settings[each.value.http_settings_key].name
DEFAULT_REDIRECT_CONFIG = try(each.value.default_redirect_config, each.value.redirect_config, null)
REDIRECT_CONFIG = try(each.value.redirect_config, null)
DEFAULT_REWRITE_RULE_SET = try(var.settings.rewrite_rule_sets[each.value.default_rewrite_rule_set_key].name, var.settings.rewrite_rule_sets[each.value.rewrite_rule_set_key].name, null)
REWRITE_RULE_SET = try(var.settings.rewrite_rule_sets[each.value.rewrite_rule_set_key].name, null)
RULE_NAME = try(each.value.rule_name, null)
WAF_POLICY = try(each.value.waf_policy, null)
Expand Down

0 comments on commit 5ebb0a4

Please sign in to comment.