generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 3
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 middleware to App Gateway #458
Merged
Merged
Changes from 7 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
28ef475
Add middleware to app gateway
6ebfb09
fmt
f162efa
push middleware image to dev
3a879f8
wip
1aee8f9
wip
97a82e0
wip
bddcb8d
wip
6e4c811
wrong image
93f4f86
wrong image
eb399bf
rm entrypoint
d81fa29
try diff dockerfile fmt
f6535bb
try diff dockerfile fmt
cb88e00
try diff dockerfile fmt
bd9202c
try diff dockerfile fmt
30a3b49
try diff dockerfile fmt
d894ee8
try diff dockerfile fmt
9cbab03
try diff dockerfile fmt
f55ed1f
try diff dockerfile fmt
e3fb8f5
try diff dockerfile fmt
6dcd27b
try diff dockerfile fmt
636719a
try diff dockerfile fmt
4e422b8
try diff dockerfile fmt
02247a3
try diff dockerfile fmt
5cc093e
try diff dockerfile fmt
52f1179
try diff dockerfile fmt
7d3a15b
clean
b29e740
clean
8dd3531
clean
aa6f7e1
Merge branch 'main' into put-middle-behind-app-gateway
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,21 +10,27 @@ resource "azurerm_public_ip" "lb-pip" { | |
|
||
# since these variables are re-used - a locals block makes this more maintainable | ||
locals { | ||
backend_address_pool_name_static = "${var.name}-${var.env}-beap-static" | ||
backend_address_pool_name_api = "${var.name}-${var.env}-beap-api" | ||
frontend_port_name_api = "${var.name}-${var.env}-feport-api" | ||
frontend_port_name_static = "${var.name}-${var.env}-feport-static" | ||
frontend_ip_configuration_name = "${var.name}-${var.env}-feip" | ||
http_setting_name_static = "${var.name}-${var.env}-be-htst-static" | ||
http_setting_name_api = "${var.name}-${var.env}-be-htst-api" | ||
listener_name_static = "${var.name}-${var.env}-httplstn-static" | ||
listener_name_api = "${var.name}-${var.env}-httplstn-api" | ||
request_routing_rule_name_api = "${var.name}-${var.env}-rqrt-api" | ||
request_routing_rule_name_static = "${var.name}-${var.env}-rqrt-static" | ||
redirect_configuration_name = "${var.name}-${var.env}-rdrcfg" | ||
static_probe_name_app = "${var.name}-${var.env}-be-probe-app-static" | ||
api_probe_name_app = "${var.name}-${var.env}-be-probe-app-api" | ||
redirect_rule = "${var.name}-${var.env}-redirect" | ||
backend_address_pool_name_static = "${var.name}-${var.env}-beap-static" | ||
backend_address_pool_name_api_ocr = "${var.name}-${var.env}-beap-api-ocr" | ||
backend_address_pool_name_api_middleware = "${var.name}-${var.env}-beap-api-middleware" | ||
frontend_port_name_api_ocr = "${var.name}-${var.env}-feport-api-ocr" | ||
frontend_port_name_api_middleware = "${var.name}-${var.env}-feport-api-middleware" | ||
frontend_port_name_static = "${var.name}-${var.env}-feport-static" | ||
frontend_ip_configuration_name = "${var.name}-${var.env}-feip" | ||
http_setting_name_static = "${var.name}-${var.env}-be-htst-static" | ||
http_setting_name_api_ocr = "${var.name}-${var.env}-be-htst-api-ocr" | ||
http_setting_name_api_middleware = "${var.name}-${var.env}-be-htst-api-middleware" | ||
listener_name_static = "${var.name}-${var.env}-httplstn-static" | ||
listener_name_api_ocr = "${var.name}-${var.env}-httplstn-api-ocr" | ||
listener_name_api_middleware = "${var.name}-${var.env}-httplstn-api-middleware" | ||
request_routing_rule_name_api_ocr = "${var.name}-${var.env}-rqrt-api-ocr" | ||
request_routing_rule_name_api_middleware = "${var.name}-${var.env}-rqrt-api-middleware" | ||
request_routing_rule_name_static = "${var.name}-${var.env}-rqrt-static" | ||
redirect_configuration_name = "${var.name}-${var.env}-rdrcfg" | ||
static_probe_name_app = "${var.name}-${var.env}-be-probe-app-static" | ||
api_probe_name_app_ocr = "${var.name}-${var.env}-be-probe-app-api-ocr" | ||
api_probe_name_app_middleware = "${var.name}-${var.env}-be-probe-app-api-middleware" | ||
redirect_rule = "${var.name}-${var.env}-redirect" | ||
} | ||
|
||
resource "azurerm_application_gateway" "load_balancer" { | ||
|
@@ -35,7 +41,6 @@ resource "azurerm_application_gateway" "load_balancer" { | |
sku { | ||
name = "Standard_v2" | ||
tier = "Standard_v2" | ||
capacity = 2 | ||
} | ||
|
||
gateway_ip_configuration { | ||
|
@@ -72,23 +77,23 @@ resource "azurerm_application_gateway" "load_balancer" { | |
|
||
# ------- OCR API ------------------------- | ||
backend_address_pool { | ||
name = local.backend_address_pool_name_api | ||
fqdns = [var.fqdns] | ||
name = local.backend_address_pool_name_api_ocr | ||
fqdns = [var.fqdns_ocr] | ||
ip_addresses = var.ip_addresses | ||
} | ||
|
||
backend_http_settings { | ||
name = local.http_setting_name_api | ||
name = local.http_setting_name_api_ocr | ||
cookie_based_affinity = "Disabled" | ||
port = 443 | ||
protocol = "Https" | ||
request_timeout = 120 | ||
pick_host_name_from_backend_address = true | ||
probe_name = local.api_probe_name_app | ||
probe_name = local.api_probe_name_app_ocr | ||
} | ||
|
||
probe { | ||
name = local.api_probe_name_app | ||
name = local.api_probe_name_app_ocr | ||
interval = 30 | ||
timeout = 30 | ||
unhealthy_threshold = 3 | ||
|
@@ -102,6 +107,38 @@ resource "azurerm_application_gateway" "load_balancer" { | |
} | ||
} | ||
|
||
# ------- Middleware API ------------------------- | ||
backend_address_pool { | ||
name = local.backend_address_pool_name_api_middleware | ||
fqdns = [var.fqdns_middleware] | ||
ip_addresses = var.ip_addresses | ||
} | ||
|
||
backend_http_settings { | ||
name = local.http_setting_name_api_middleware | ||
cookie_based_affinity = "Disabled" | ||
port = 443 | ||
protocol = "Https" | ||
request_timeout = 120 | ||
pick_host_name_from_backend_address = true | ||
probe_name = local.api_probe_name_app_middleware | ||
} | ||
|
||
probe { | ||
name = local.api_probe_name_app_middleware | ||
interval = 30 | ||
timeout = 30 | ||
unhealthy_threshold = 3 | ||
protocol = "Https" | ||
port = 443 | ||
path = "/actuator/health" | ||
pick_host_name_from_backend_http_settings = true | ||
match { | ||
body = "UP" | ||
status_code = [200] | ||
} | ||
} | ||
|
||
# ------- Listeners ------------------------- | ||
frontend_ip_configuration { | ||
name = local.frontend_ip_configuration_name | ||
|
@@ -116,11 +153,19 @@ resource "azurerm_application_gateway" "load_balancer" { | |
} | ||
|
||
http_listener { | ||
name = local.listener_name_api | ||
name = local.listener_name_api_ocr | ||
frontend_ip_configuration_name = local.frontend_ip_configuration_name | ||
frontend_port_name = local.frontend_port_name_static | ||
protocol = "Http" | ||
host_names = [var.fqdns_ocr] | ||
} | ||
|
||
http_listener { | ||
name = local.listener_name_api_middleware | ||
frontend_ip_configuration_name = local.frontend_ip_configuration_name | ||
frontend_port_name = local.frontend_port_name_static | ||
protocol = "Http" | ||
host_names = [var.fqdns] | ||
host_names = [var.fqdns_middleware] | ||
} | ||
|
||
http_listener { | ||
|
@@ -142,33 +187,48 @@ resource "azurerm_application_gateway" "load_balancer" { | |
} | ||
|
||
request_routing_rule { | ||
name = local.request_routing_rule_name_api | ||
name = local.request_routing_rule_name_api_ocr | ||
priority = 100 | ||
rule_type = "Basic" | ||
http_listener_name = local.listener_name_api | ||
backend_address_pool_name = local.backend_address_pool_name_api | ||
backend_http_settings_name = local.http_setting_name_api | ||
http_listener_name = local.listener_name_api_ocr | ||
backend_address_pool_name = local.backend_address_pool_name_api_ocr | ||
backend_http_settings_name = local.http_setting_name_api_ocr | ||
} | ||
|
||
request_routing_rule { | ||
name = local.request_routing_rule_name_api_middleware | ||
priority = 150 | ||
rule_type = "Basic" | ||
http_listener_name = local.listener_name_api_middleware | ||
backend_address_pool_name = local.backend_address_pool_name_api_middleware | ||
backend_http_settings_name = local.http_setting_name_api_middleware | ||
} | ||
|
||
url_path_map { | ||
name = "${var.name}-${var.env}-urlmap" | ||
default_backend_address_pool_name = local.backend_address_pool_name_static | ||
default_backend_http_settings_name = local.http_setting_name_static | ||
default_rewrite_rule_set_name = "${var.name}-routing" | ||
default_rewrite_rule_set_name = "${var.name}-middleware-routing" | ||
|
||
path_rule { | ||
name = "api" | ||
name = "ocr" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the name just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh the name here doesn't really matter, just needs to be different than the middleware rule. |
||
paths = ["/ocr-api/*", "/ocr-api"] | ||
backend_address_pool_name = local.backend_address_pool_name_api | ||
backend_http_settings_name = local.http_setting_name_api | ||
backend_address_pool_name = local.backend_address_pool_name_api_ocr | ||
backend_http_settings_name = local.http_setting_name_api_ocr | ||
// this is the default, why would we set it again? | ||
// because if we don't do this we get 404s on API calls | ||
rewrite_rule_set_name = "${var.name}-routing" | ||
rewrite_rule_set_name = "${var.name}-ocr-routing" | ||
} | ||
path_rule { | ||
name = "middleware" | ||
paths = ["/middleware-api/*", "/middleware-api"] | ||
backend_address_pool_name = local.backend_address_pool_name_api_middleware | ||
backend_http_settings_name = local.http_setting_name_api_middleware | ||
rewrite_rule_set_name = "${var.name}-middleware-routing" | ||
} | ||
} | ||
rewrite_rule_set { | ||
name = "${var.name}-routing" | ||
name = "${var.name}-ocr-routing" | ||
|
||
rewrite_rule { | ||
name = "ocr-api-wildcard" | ||
|
@@ -189,4 +249,32 @@ resource "azurerm_application_gateway" "load_balancer" { | |
} | ||
} | ||
} | ||
|
||
rewrite_rule_set { | ||
name = "${var.name}-middleware-routing" | ||
|
||
rewrite_rule { | ||
name = "middleware-api-wildcard" | ||
rule_sequence = 101 | ||
condition { | ||
ignore_case = true | ||
negate = false | ||
pattern = ".*middleware-api/(.*)" | ||
variable = "var_uri_path" | ||
} | ||
|
||
url { | ||
path = "/{var_uri_path_1}" | ||
reroute = false | ||
# Per documentation, we should be able to leave this pass-through out. See however | ||
# https://github.com/terraform-providers/terraform-provider-azurerm/issues/11563 | ||
query_string = "{var_query_string}" | ||
} | ||
} | ||
} | ||
|
||
autoscale_configuration { | ||
min_capacity = 0 | ||
max_capacity = 5 | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,3 @@ | ||
output "fqdn" { | ||
value = azurerm_public_ip.lb-pip.fqdn | ||
} | ||
|
||
output "app_gateway_hostname" { | ||
value = azurerm_application_gateway.load_balancer.id | ||
sensitive = true | ||
} | ||
|
||
output "app_gateway_ip" { | ||
value = azurerm_public_ip.lb-pip.ip_address | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to hardcode
dev
here? Or can we make dynamic so if whomever picks it up can selectdev
, as well as,stage
orprod
(after they build out those environments)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is how we do local github action testing. I will make this a draft
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also wouldnt need to test like this if we create a seperate worflow for building and deploying the middleware