Skip to content

Commit ed07211

Browse files
committed
Added more modules
1 parent 0503d14 commit ed07211

File tree

29 files changed

+291
-0
lines changed

29 files changed

+291
-0
lines changed

environments/dev/vm.tf

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
# Static Internal IP
12
resource "google_compute_address" "dev_app_ip" {
23
name = "dev-app-1-ip"
34
region = "asia-southeast1"
45
address_type = "INTERNAL"
56
subnetwork = module.subnets.subnet_ids["dev-vpc-a-subnet-1"]
67
}
78

9+
# VM Instances
810
module "vm_instances" {
911
source = "../../modules/vm_instance"
1012
depends_on = [module.vpc, module.subnets]
@@ -34,3 +36,31 @@ module "vm_instances" {
3436
}
3537
}
3638
}
39+
40+
# Unmanaged Instance Groups
41+
module "instance_groups" {
42+
source = "../../modules/unmanaged_instance_group"
43+
depends_on = [module.vm_instances]
44+
45+
instance_groups = {
46+
"dev-umig-a" = {
47+
name = "dev-umig-a"
48+
description = "Unmanaged instance group for dev apps"
49+
zone = "asia-southeast1-b"
50+
instances = [
51+
module.vm_instances.instance_self_links["dev-app-1"],
52+
]
53+
network = module.vpc.vpc_networks["dev-vpc-a"].self_link
54+
named_ports = [
55+
{
56+
name = "http"
57+
port = 80
58+
},
59+
{
60+
name = "https"
61+
port = 443
62+
}
63+
]
64+
}
65+
}
66+
}

modules/backend_service/main.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
terraform {
2+
required_version = ">= 1.11.4"
3+
required_providers {
4+
google = {
5+
source = "hashicorp/google"
6+
version = ">= 5.29"
7+
}
8+
}
9+
}
10+
11+
resource "google_compute_backend_service" "default" {
12+
for_each = var.backend_services
13+
14+
name = each.value.name
15+
protocol = "HTTP"
16+
port_name = "http"
17+
timeout_sec = 10
18+
load_balancing_scheme = "EXTERNAL"
19+
health_checks = [each.value.health_check]
20+
backend {
21+
group = each.value.instance_group
22+
}
23+
}

modules/backend_service/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
output "backend_service_self_links" {
2+
value = {
3+
for k, bs in google_compute_backend_service.default : k => bs.self_link
4+
}
5+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
variable "backend_services" {
2+
type = map(object({
3+
name = string
4+
instance_group = string
5+
health_check = string
6+
}))
7+
}

modules/health_check/main.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
terraform {
2+
required_version = ">= 1.11.4"
3+
required_providers {
4+
google = {
5+
source = "hashicorp/google"
6+
version = ">= 5.29"
7+
}
8+
}
9+
}
10+
11+
resource "google_compute_health_check" "http" {
12+
for_each = var.health_checks
13+
14+
name = each.value.name
15+
check_interval_sec = each.value.check_interval_sec
16+
timeout_sec = each.value.timeout_sec
17+
healthy_threshold = each.value.healthy_threshold
18+
unhealthy_threshold = each.value.unhealthy_threshold
19+
20+
http_health_check {
21+
port = each.value.http_port
22+
request_path = each.value.request_path
23+
}
24+
}

modules/health_check/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
output "health_check_self_links" {
2+
value = {
3+
for k, hc in google_compute_health_check.http : k => hc.self_link
4+
}
5+
}

modules/health_check/variables.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
variable "health_checks" {
2+
type = map(object({
3+
name = string
4+
check_interval_sec = number
5+
timeout_sec = number
6+
healthy_threshold = number
7+
unhealthy_threshold = number
8+
http_port = number
9+
request_path = string
10+
}))
11+
}

modules/lb/dns_record/main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
resource "google_dns_record_set" "this" {
2+
name = var.record_name
3+
type = "A"
4+
ttl = var.ttl
5+
managed_zone = var.managed_zone
6+
rrdatas = [var.ip_address]
7+
}

modules/lb/dns_record/outputs.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
output "fqdn" {
2+
value = google_dns_record_set.this.name
3+
}

modules/lb/dns_record/variables.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
variable "record_name" {
2+
type = string
3+
}
4+
5+
variable "ttl" {
6+
type = number
7+
default = 300
8+
}
9+
10+
variable "managed_zone" {
11+
type = string
12+
}
13+
14+
variable "ip_address" {
15+
type = string
16+
}

0 commit comments

Comments
 (0)