-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ahoyworld): droplet configs, add eng clt VMs
- Loading branch information
1 parent
a1a7d88
commit 4ff6a38
Showing
6 changed files
with
232 additions
and
33 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
terraform/stg-cluster-ahoyworld/cloud-init--userdata.yml.tftpl
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#cloud-config | ||
merge_how: | ||
- name: list | ||
settings: [append] | ||
- name: dict | ||
settings: [no_replace, recurse_list] | ||
# -- allow root login temporarily for remote-exec, where we need to run as root. | ||
disable_root: false | ||
# -- allow root login temporarily for remote-exec, where we need to run as root. | ||
ssh_pwauth: false | ||
allow_public_ssh_keys: true | ||
|
||
users: | ||
- name: freecodecamp | ||
groups: | ||
- sudo | ||
- docker | ||
shell: /bin/bash | ||
sudo: "ALL=(ALL) NOPASSWD:ALL" | ||
ssh_import_id: | ||
- gh:camperbot | ||
- gh:raisedadead | ||
|
||
preserve_hostname: true | ||
fqdn: ${tf_fqdn} | ||
hostname: ${tf_hostname} | ||
prefer_fqdn_over_hostname: true | ||
create_hostname_file: true | ||
|
||
# Add DNS resolver configuration | ||
# network: | ||
# version: 2 | ||
# ethernets: | ||
# eth0: | ||
# dhcp4: true | ||
# nameservers: | ||
# addresses: | ||
# - 1.1.1.1 | ||
# - 1.0.0.1 | ||
|
||
final_message: "Setup complete" |
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
resource "digitalocean_droplet" "stg_ahoyworld_pxy" { | ||
count = local.pxy_node_count | ||
name = "stg-vm-ahoyworld-pxy-${count.index + 1}" | ||
tags = ["stg", "ahoyworld", "pxy", "stg_ahoyworld_pxy"] | ||
|
||
image = data.hcp_packer_artifact.do_ubuntu.external_identifier | ||
size = "s-2vcpu-4gb" | ||
region = "nyc3" | ||
vpc_uuid = digitalocean_vpc.stg_vpc.id | ||
|
||
ssh_keys = [for ssh_key in data.digitalocean_ssh_key.stg_ssh_keys : ssh_key.id] | ||
|
||
user_data = templatefile("${path.root}/cloud-init--userdata.yml.tftpl", { | ||
tf_fqdn = "pxy-${count.index + 1}.ahoyworld.stg.${local.zone}" | ||
tf_hostname = "pxy-stg-${count.index + 1}" | ||
}) | ||
|
||
# -- All of the provisioning should be done via cloud-init, this is just to setup the reboot. | ||
connection { | ||
host = self.ipv4_address | ||
user = "root" | ||
private_key = var.ssh_terraform_ed25519_private_key | ||
timeout = "2m" | ||
} | ||
provisioner "remote-exec" { | ||
inline = [ | ||
# Wait for cloud-init to finish. | ||
"while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done", | ||
"echo Current hostname...; hostname", | ||
"shutdown -r +1 'Terraform: Rebooting to apply hostname change in 1 min.'" | ||
] | ||
} | ||
provisioner "remote-exec" { | ||
# This is just to verify the reboot worked. | ||
inline = [ | ||
"uptime" | ||
] | ||
} | ||
provisioner "remote-exec" { | ||
inline = [ | ||
# Disable root login by setting PermitRootLogin to 'no' in sshd_config | ||
"sed -i 's/^PermitRootLogin.*/PermitRootLogin no/' /etc/ssh/sshd_config", | ||
# Restart SSH service to apply changes | ||
"systemctl restart ssh" | ||
] | ||
} | ||
# -- All of the provisioning should be done via cloud-init, this is just to setup the reboot. | ||
} | ||
|
||
resource "cloudflare_record" "stg_ahoyworld_pxy_dns__public" { | ||
count = local.pxy_node_count | ||
|
||
zone_id = data.cloudflare_zone.cf_zone.id | ||
type = "A" | ||
proxied = false | ||
ttl = 120 | ||
|
||
name = "pxy-${count.index + 1}.ahoyworld.stg.${var.network_subdomain}" | ||
content = digitalocean_droplet.stg_ahoyworld_pxy[count.index].ipv4_address | ||
} | ||
|
||
resource "cloudflare_record" "stg_ahoyworld_pxy_dns__private" { | ||
count = local.pxy_node_count | ||
|
||
zone_id = data.cloudflare_zone.cf_zone.id | ||
type = "A" | ||
proxied = false | ||
ttl = 120 | ||
|
||
name = "pxy-${count.index + 1}.ahoyworld.stg" | ||
content = digitalocean_droplet.stg_ahoyworld_pxy[count.index].ipv4_address_private | ||
} |
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
resource "digitalocean_droplet" "stg_ahoyworld_clt" { | ||
for_each = { for i in local.clt_instances : i.instance => i } | ||
|
||
name = "stg-vm-ahoyworld-clt-${each.value.instance}" | ||
tags = ["stg", "ahoyworld", "clt", "stg_ahoyworld_clt", "${each.value.name}"] | ||
|
||
image = data.hcp_packer_artifact.do_ubuntu.external_identifier | ||
size = "s-2vcpu-4gb" | ||
region = "nyc3" | ||
vpc_uuid = digitalocean_vpc.stg_vpc.id | ||
|
||
ssh_keys = [for ssh_key in data.digitalocean_ssh_key.stg_ssh_keys : ssh_key.id] | ||
|
||
user_data = templatefile("${path.root}/cloud-init--userdata.yml.tftpl", { | ||
tf_fqdn = "clt-${each.value.instance}.ahoyworld.stg.${local.zone}" | ||
tf_hostname = "clt-stg-${each.value.instance}" | ||
}) | ||
|
||
# -- All of the provisioning should be done via cloud-init, this is just to setup the reboot. | ||
connection { | ||
host = self.ipv4_address | ||
user = "root" | ||
private_key = var.ssh_terraform_ed25519_private_key | ||
timeout = "2m" | ||
} | ||
provisioner "remote-exec" { | ||
inline = [ | ||
# Wait for cloud-init to finish. | ||
"while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done", | ||
"echo Current hostname...; hostname", | ||
"shutdown -r +1 'Terraform: Rebooting to apply hostname change in 1 min.'" | ||
] | ||
} | ||
provisioner "remote-exec" { | ||
# This is just to verify the reboot worked. | ||
inline = [ | ||
"uptime" | ||
] | ||
} | ||
provisioner "remote-exec" { | ||
inline = [ | ||
# Disable root login by setting PermitRootLogin to 'no' in sshd_config | ||
"sed -i 's/^PermitRootLogin.*/PermitRootLogin no/' /etc/ssh/sshd_config", | ||
# Restart SSH service to apply changes | ||
"systemctl restart ssh" | ||
] | ||
} | ||
# -- All of the provisioning should be done via cloud-init, this is just to setup the reboot. | ||
} | ||
|
||
resource "cloudflare_record" "stg_ahoyworld_clt_dns__public" { | ||
for_each = { for i in local.clt_instances : i.instance => i } | ||
|
||
zone_id = data.cloudflare_zone.cf_zone.id | ||
type = "A" | ||
proxied = false | ||
ttl = 120 | ||
|
||
name = "clt-${each.value.instance}.ahoyworld.stg.${var.network_subdomain}" | ||
content = digitalocean_droplet.stg_ahoyworld_clt[each.key].ipv4_address | ||
} | ||
|
||
resource "cloudflare_record" "stg_ahoyworld_clt_dns__private" { | ||
for_each = { for i in local.clt_instances : i.instance => i } | ||
|
||
zone_id = data.cloudflare_zone.cf_zone.id | ||
type = "A" | ||
proxied = false | ||
ttl = 120 | ||
|
||
name = "clt-${each.value.instance}.ahoyworld.stg" | ||
content = digitalocean_droplet.stg_ahoyworld_clt[each.key].ipv4_address_private | ||
} |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
resource "digitalocean_project" "stg_project" { | ||
name = "stg-ahoyworld" | ||
description = "AhoyWorld staging resources." | ||
purpose = "Web Application" | ||
environment = "Staging" | ||
} | ||
|
||
resource "digitalocean_project_resources" "stg_project_resources" { | ||
project = digitalocean_project.stg_project.id | ||
resources = flatten([ | ||
[for droplet in digitalocean_droplet.stg_ahoyworld_pxy : droplet.urn], | ||
[for droplet in digitalocean_droplet.stg_ahoyworld_clt : droplet.urn] | ||
]) | ||
} |
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