This commit is contained in:
Muhammad Atif Ali
2023-09-20 16:48:42 +03:00
parent b8eb296abd
commit 8ab05d70a8
6 changed files with 336 additions and 9 deletions

View File

@@ -18,6 +18,6 @@ To use this module, add the following snippet to your template manifest:
module "gcp_regions" {
source = "https://registry.coder.com/modules/gcp-regions"
gcp_regions = ["us-west1", "us-west2", "us-west3"] # Add your desired regions here, use ["all"] for all regions
gpu_only = true
gpu_only = true
}
```

View File

@@ -143,13 +143,13 @@ locals {
{ zone = "europe-west12-c", has_gpu = false, location = "Turin, Italy", icon = "/emojis/1f1ee-1f1f9.png" },
# Middleeast Central (Qatar, Saudi Arabia)
{ zone = "me-central1-a ", has_gpu = false, location = "Doha, Qatar", icon = "/emojis/1f1f6-1f1e6.png" },
{ zone = "me-central1-b ", has_gpu = false, location = "Doha, Qatar", icon = "/emojis/1f1f6-1f1e6.png" },
{ zone = "me-central1-c ", has_gpu = false, location = "Doha, Qatar", icon = "/emojis/1f1f6-1f1e6.png" },
{ zone = "me-central1-a", has_gpu = false, location = "Doha, Qatar", icon = "/emojis/1f1f6-1f1e6.png" },
{ zone = "me-central1-b", has_gpu = false, location = "Doha, Qatar", icon = "/emojis/1f1f6-1f1e6.png" },
{ zone = "me-central1-c", has_gpu = false, location = "Doha, Qatar", icon = "/emojis/1f1f6-1f1e6.png" },
{ zone = "me-central2-a ", has_gpu = false, location = "Dammam, Saudi Arabia", icon = "/emojis/1f1f8-1f1e6.png" },
{ zone = "me-central2-b ", has_gpu = false, location = "Dammam, Saudi Arabia", icon = "/emojis/1f1f8-1f1e6.png" },
{ zone = "me-central2-c ", has_gpu = false, location = "Dammam, Saudi Arabia", icon = "/emojis/1f1f8-1f1e6.png" },
{ zone = "me-central2-a", has_gpu = false, location = "Dammam, Saudi Arabia", icon = "/emojis/1f1f8-1f1e6.png" },
{ zone = "me-central2-b", has_gpu = false, location = "Dammam, Saudi Arabia", icon = "/emojis/1f1f8-1f1e6.png" },
{ zone = "me-central2-c", has_gpu = false, location = "Dammam, Saudi Arabia", icon = "/emojis/1f1f8-1f1e6.png" },
# Middleeast West (Israel)
{ zone = "me-west1-a", has_gpu = false, location = "Tel Aviv, Israel", icon = "/emojis/1f1ee-1f1f1.png" },
@@ -202,11 +202,11 @@ locals {
]
}
data "coder_parameter" "gcp-zones" {
data "coder_parameter" "gcp_zones" {
type = "list(string)"
name = "gcp_zones"
display_name = "GCP Zones"
icon = "/icon/gcp/svg"
icon = "/icon/gcp.svg"
mutable = true
dynamic "option" {

56
gcp-regions/update.sh Normal file
View File

@@ -0,0 +1,56 @@
#!/bin/bash
declare -A zone_to_location=(
["us-central1"]="Council Bluffs, Iowa, USA"
["us-east1"]="Moncks Corner, S. Carolina, USA"
)
declare -A zone_to_emoji=(
["us-central1"]="/emojis/1f1fa-1f1f8.png"
["us-east1"]="/emojis/1f1fa-1f1f8.png"
# ... Add other mappings here
)
# Function to check if a zone has a GPU
has_gpu() {
local zone=$1
gcloud compute machine-types list --filter="zone:($zone) AND guestCpus:>=0" --format="csv[no-heading](name)" | grep -q "gpu"
}
# Function to fetch zones from GCP and format them for Terraform
fetch_zones() {
gcloud compute zones list --format="csv[no-heading](name,region)" | while IFS=',' read -r zone region; do
# Check if the zone has a GPU
gpu_status=false
if has_gpu "$zone"; then
gpu_status=true
fi
# Fetch location and emoji from the mapping
location=${zone_to_location[${zone%-*}]:-"TODO: Add Location"}
emoji=${zone_to_emoji[${zone%-*}]:-"/emojis/TODO: Add Emoji"}
# Format the Terraform entry for this zone
echo " { zone = \"${zone}\", has_gpu = ${gpu_status}, location = \"${location}\", icon = \"${emoji}\" },"
done
}
# Temporary file to store the updated Terraform content
temp_file=$(mktemp)
# Print everything before the zone list
awk '/locals {/,/all_zones = \[/{print; exit}' your_terraform_file.tf > "$temp_file"
# Fetch and format the zones, appending them to the temporary file
echo " all_zones = [" >> "$temp_file"
fetch_zones >> "$temp_file"
echo " ]" >> "$temp_file"
# Print everything after the zone list
awk '/\],/{flag=1; next} flag' your_terraform_file.tf >> "$temp_file"
# Replace the original Terraform file with the updated one
mv "$temp_file" your_terraform_file.tf
# Clean up
rm -f "$temp_file"