Skip to content

Commit

Permalink
Merge branch 'fix/azs-for-serves' of https://github.com/opensourcecor…
Browse files Browse the repository at this point in the history
…p/workshop-linux into feature/wetty-ssl
  • Loading branch information
JDeBo committed Jan 12, 2025
2 parents e14cf69 + 7d1db83 commit 9444f51
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 43 deletions.
1 change: 1 addition & 0 deletions terraform/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.terraform/
*.tfvars
*tfstate*
!main.auto.tfvars
62 changes: 30 additions & 32 deletions terraform/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 32 additions & 8 deletions terraform/dns.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,39 @@

data "aws_route53_zone" "name" {
count = var.zone_name ? 1 : 0
data "aws_route53_zone" "root_zone" {
count = var.create_dns ? 1 : 0
name = var.zone_name

}

resource "aws_route53_record" "name" {
count = var.zone_name ? var.num_teams : 0
zone_id = data.aws_route53_zone.name[0].zone_id
name = "team-${count.index + 1}"
resource "aws_route53_zone" "workshop_zone" {
count = var.create_dns ? 1 : 0
name = "${var.event_name}.${var.zone_name}"
}

resource "aws_route53_record" "workshop" {
count = var.create_dns ? 1 : 0
zone_id = data.aws_route53_zone.root_zone[0].zone_id
name = aws_route53_zone.workshop_zone[0].name
type = "NS"
ttl = "300"
records = aws_route53_zone.workshop_zone[0].name_servers
}

resource "aws_route53_record" "teams" {
count = var.create_dns ? var.num_teams : 0
zone_id = aws_route53_zone.workshop_zone[0].zone_id
name = "team-${count.index + 1}"
type = "A"
ttl = 300 #5 mins
records = [module.team_servers[count.index].public_ip]
depends_on = [aws_route53_record.hub]
}

resource "aws_route53_record" "hub" {
count = var.create_dns ? 1 : 0
zone_id = aws_route53_zone.workshop_zone[0].zone_id
name = "hub"
type = "A"
ttl = var.ttl
records = [aws_instance.instance[count.index].public_ip]
ttl = 300 #5 mins
records = [module.hub.public_ip]
}
27 changes: 27 additions & 0 deletions terraform/main.auto.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
num_teams = 2
event_name = "codemash"
custom_security_group_ingress = [{
from_port = 2332,
to_port = 2332,
protocol = "tcp",
description = "ssh",
cidr_blocks = "0.0.0.0/0"
},
{
from_port = 8080,
to_port = 8080,
protocol = "tcp",
description = "http",
cidr_blocks = "0.0.0.0/0"
}
# Wetty config
, {
from_port = 0,
to_port = 6556,
protocol = "tcp",
description = "http",
cidr_blocks = "0.0.0.0/0"
}
]
zone_name = "sbx.justindebo.com"
create_dns = true
6 changes: 3 additions & 3 deletions terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ module "vpc" {
name = local.name
cidr = "10.0.0.0/16"

azs = [data.aws_availability_zones.available.names]
public_subnets = ["10.0.1.0/24"]
azs = [data.aws_availability_zones.available.names[0], data.aws_availability_zones.available.names[1]]
public_subnets = cidrsubnets("10.0.0.0/16", 8, 8)

enable_nat_gateway = false

Expand Down Expand Up @@ -124,7 +124,7 @@ module "team_servers" {
instance_type = "t3a.micro"
key_name = aws_key_pair.main.key_name
vpc_security_group_ids = [module.security_group.security_group_id]
subnet_id = module.vpc.public_subnets[0]
subnet_id = module.vpc.public_subnets[count.index % 2]
associate_public_ip_address = true

user_data = <<-EOF
Expand Down
4 changes: 4 additions & 0 deletions terraform/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ output "instance_ips" {
value = { for instance in module.team_servers : instance.tags_all["Name"] => instance.public_ip }
}

output "instance_dns" {
value = { for dns in aws_route53_record.teams : "${dns.name}.${aws_route53_zone.workshop_zone[0].name}" => dns.records }
}

output "hub_pub_ip" {
value = module.hub.public_ip
}
Expand Down
12 changes: 12 additions & 0 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,15 @@ variable "ssh_local_key_path" {
type = string
default = "~/.ssh/id_rsa.pub"
}

variable "create_dns" {
description = "Whether to create a Route53 DNS zone for the workshop instances"
type = bool
default = false
}

variable "zone_name" {
description = "Route53 zone name to use for workshop instances"
type = string
default = null
}

0 comments on commit 9444f51

Please sign in to comment.