diff --git a/main.tf b/main.tf index 0cfa335..36fb320 100644 --- a/main.tf +++ b/main.tf @@ -11,19 +11,6 @@ module "instance" { fancy_store_name = module.storage.fancy_store_name } -module "healthchecks" { - source = "./modules/network/healthchecks" -} - -module "firewall" { - source = "./modules/network/firewall" - -} - -module "loadbalancer" { - source = "./modules/network/loadbalancer" -} - module "network" { source = "./modules/network" diff --git a/modules/network/firewall/main.tf b/modules/network/firewall/main.tf deleted file mode 100644 index a5c08db..0000000 --- a/modules/network/firewall/main.tf +++ /dev/null @@ -1,21 +0,0 @@ -## Firewall Rules to allow Front-End and Back-End - -resource "google_compute_firewall" "fw_fe" { - name = "fw-fe" - network = "default" - allow { - protocol = "tcp" - ports = ["8080"] - } - target_tags = ["frontend"] -} - -resource "google_compute_firewall" "fw_be" { - name = "fw-be" - network = "default" - allow { - protocol = "tcp" - ports = ["8081-8082"] - } - target_tags = ["backend"] -} diff --git a/modules/network/healthchecks/main.tf b/modules/network/healthchecks/main.tf deleted file mode 100644 index ce4eec6..0000000 --- a/modules/network/healthchecks/main.tf +++ /dev/null @@ -1,40 +0,0 @@ -#Create HealthChecks - -resource "google_compute_http_health_check" "fancy_fe_hc" { - name = "fancy-fe-hc" - port = "8080" - request_path = "/" - check_interval_sec = 30 - timeout_sec = 10 - healthy_threshold = 1 - unhealthy_threshold = 3 -} - -resource "google_compute_http_health_check" "fancy_be_hc" { - name = "fancy-be-hc" - port = "8081" - request_path = "/api/orders" - check_interval_sec = 30 - timeout_sec = 10 - healthy_threshold = 1 - unhealthy_threshold = 3 -} - - -resource "google_compute_http_health_check" "fancy_fe_frontend_hc" { - name = "fancy-fe-frontend-hc" - request_path = "/" - port = 8080 -} - -resource "google_compute_http_health_check" "fancy_be_orders_hc" { - name = "fancy-be-orders-hc" - request_path = "/api/orders" - port = 8081 -} - -resource "google_compute_http_health_check" "fancy_be_products_hc" { - name = "fancy-be-products-hc" - request_path = "/api/products" - port = 8082 -} \ No newline at end of file diff --git a/modules/network/loadbalancer/main.tf b/modules/network/loadbalancer/main.tf deleted file mode 100644 index ca81c5d..0000000 --- a/modules/network/loadbalancer/main.tf +++ /dev/null @@ -1,82 +0,0 @@ -resource "google_compute_backend_service" "fancy_fe_frontend" { - name = "fancy-fe-frontend" - port_name = "frontend" - protocol = "HTTP" - load_balancing_scheme = "INTERNAL_SELF_MANAGED" - - backend { - group = google_compute_instance_group_manager.fancy_fe_mig.self_link - } - - health_checks = [ - google_compute_http_health_check.fancy_fe_frontend_hc.self_link - ] -} - -resource "google_compute_backend_service" "fancy_be_orders" { - name = "fancy-be-orders" - port_name = "orders" - protocol = "HTTP" - load_balancing_scheme = "INTERNAL_SELF_MANAGED" - - backend { - group = google_compute_instance_group_manager.fancy_be_mig.self_link - } - - health_checks = [ - google_compute_http_health_check.fancy_be_orders_hc.self_link - ] -} - -resource "google_compute_backend_service" "fancy_be_products" { - name = "fancy-be-products" - port_name = "products" - protocol = "HTTP" - load_balancing_scheme = "INTERNAL_SELF_MANAGED" - - backend { - group = google_compute_instance_group_manager.fancy_be_mig.self_link - } - - health_checks = [ - google_compute_http_health_check.fancy_be_products_hc.self_link - ] -} - -resource "google_compute_url_map" "fancy_map" { - name = "fancy-map" - default_service = google_compute_backend_service.fancy_fe_frontend.self_link -} - -resource "google_compute_path_matcher" "fancy_path_matcher" { - name = "orders" - default_service = google_compute_backend_service.fancy_fe_frontend.self_link - - path_rule { - paths = ["/api/orders"] - service = google_compute_backend_service.fancy_be_orders.self_link - } - - path_rule { - paths = ["/api/products"] - service = google_compute_backend_service.fancy_be_products.self_link - } - - url_map = google_compute_url_map.fancy_map.self_link -} - -resource "google_compute_target_http_proxy" "fancy_proxy" { - name = "fancy-proxy" - url_map = google_compute_url_map.fancy_map.self_link -} - -resource "google_compute_global_forwarding_rule" "fancy_http_rule" { - name = "fancy-http-rule" - target = google_compute_target_http_proxy.fancy_proxy.self_link - port_range = "80" -} - - - - - diff --git a/modules/network/main.tf b/modules/network/main.tf index 79c4246..9e7f2e8 100644 --- a/modules/network/main.tf +++ b/modules/network/main.tf @@ -56,4 +56,208 @@ resource "google_compute_firewall" "allow_health_check" { "130.211.0.0/22", "35.191.0.0/16" ] -} \ No newline at end of file +} + +resource "google_compute_backend_service" "fancy_fe_frontend" { + name = "fancy-fe-frontend" + port_name = "frontend" + protocol = "HTTP" + load_balancing_scheme = "INTERNAL_SELF_MANAGED" + + backend { + group = google_compute_instance_group_manager.fancy_fe_mig.self_link + } + + health_checks = [ + google_compute_http_health_check.fancy_fe_frontend_hc.self_link + ] +} + +resource "google_compute_backend_service" "fancy_be_orders" { + name = "fancy-be-orders" + port_name = "orders" + protocol = "HTTP" + load_balancing_scheme = "INTERNAL_SELF_MANAGED" + + backend { + group = google_compute_instance_group_manager.fancy_be_mig.self_link + } + + health_checks = [ + google_compute_http_health_check.fancy_be_orders_hc.self_link + ] +} + +resource "google_compute_backend_service" "fancy_be_products" { + name = "fancy-be-products" + port_name = "products" + protocol = "HTTP" + load_balancing_scheme = "INTERNAL_SELF_MANAGED" + + backend { + group = google_compute_instance_group_manager.fancy_be_mig.self_link + } + + health_checks = [ + google_compute_http_health_check.fancy_be_products_hc.self_link + ] +} + +resource "google_compute_url_map" "fancy_map" { + name = "fancy-map" + default_service = google_compute_backend_service.fancy_fe_frontend.self_link +} + +resource "google_compute_path_matcher" "fancy_path_matcher" { + name = "orders" + default_service = google_compute_backend_service.fancy_fe_frontend.self_link + + path_rule { + paths = ["/api/orders"] + service = google_compute_backend_service.fancy_be_orders.self_link + } + + path_rule { + paths = ["/api/products"] + service = google_compute_backend_service.fancy_be_products.self_link + } + + url_map = google_compute_url_map.fancy_map.self_link +} + +resource "google_compute_target_http_proxy" "fancy_proxy" { + name = "fancy-proxy" + url_map = google_compute_url_map.fancy_map.self_link +} + +resource "google_compute_global_forwarding_rule" "fancy_http_rule" { + name = "fancy-http-rule" + target = google_compute_target_http_proxy.fancy_proxy.self_link + port_range = "80" +} + + +#Create HealthChecks + +resource "google_compute_http_health_check" "fancy_fe_hc" { + name = "fancy-fe-hc" + port = "8080" + request_path = "/" + check_interval_sec = 30 + timeout_sec = 10 + healthy_threshold = 1 + unhealthy_threshold = 3 +} + +resource "google_compute_http_health_check" "fancy_be_hc" { + name = "fancy-be-hc" + port = "8081" + request_path = "/api/orders" + check_interval_sec = 30 + timeout_sec = 10 + healthy_threshold = 1 + unhealthy_threshold = 3 +} + + +resource "google_compute_http_health_check" "fancy_fe_frontend_hc" { + name = "fancy-fe-frontend-hc" + request_path = "/" + port = 8080 +} + +resource "google_compute_http_health_check" "fancy_be_orders_hc" { + name = "fancy-be-orders-hc" + request_path = "/api/orders" + port = 8081 +} + +resource "google_compute_http_health_check" "fancy_be_products_hc" { + name = "fancy-be-products-hc" + request_path = "/api/products" + port = 8082 +} + +## Firewall Rules to allow Front-End and Back-End + +resource "google_compute_firewall" "fw_fe" { + name = "fw-fe" + network = "default" + allow { + protocol = "tcp" + ports = ["8080"] + } + target_tags = ["frontend"] +} + +resource "google_compute_firewall" "fw_be" { + name = "fw-be" + network = "default" + allow { + protocol = "tcp" + ports = ["8081-8082"] + } + target_tags = ["backend"] +} +#Create HealthChecks + +resource "google_compute_http_health_check" "fancy_fe_hc" { + name = "fancy-fe-hc" + port = "8080" + request_path = "/" + check_interval_sec = 30 + timeout_sec = 10 + healthy_threshold = 1 + unhealthy_threshold = 3 +} + +resource "google_compute_http_health_check" "fancy_be_hc" { + name = "fancy-be-hc" + port = "8081" + request_path = "/api/orders" + check_interval_sec = 30 + timeout_sec = 10 + healthy_threshold = 1 + unhealthy_threshold = 3 +} + + +resource "google_compute_http_health_check" "fancy_fe_frontend_hc" { + name = "fancy-fe-frontend-hc" + request_path = "/" + port = 8080 +} + +resource "google_compute_http_health_check" "fancy_be_orders_hc" { + name = "fancy-be-orders-hc" + request_path = "/api/orders" + port = 8081 +} + +resource "google_compute_http_health_check" "fancy_be_products_hc" { + name = "fancy-be-products-hc" + request_path = "/api/products" + port = 8082 +} + +## Firewall Rules to allow Front-End and Back-End + +resource "google_compute_firewall" "fw_fe" { + name = "fw-fe" + network = "default" + allow { + protocol = "tcp" + ports = ["8080"] + } + target_tags = ["frontend"] +} + +resource "google_compute_firewall" "fw_be" { + name = "fw-be" + network = "default" + allow { + protocol = "tcp" + ports = ["8081-8082"] + } + target_tags = ["backend"] +}