diff --git a/terraform/main.tf b/infra/main.tf similarity index 82% rename from terraform/main.tf rename to infra/main.tf index e543f01..70a4b9c 100644 --- a/terraform/main.tf +++ b/infra/main.tf @@ -24,7 +24,7 @@ variable "deletion_protection" { } output "shortnr_static_ip" { - value = google_compute_address.selfpass.address + value = google_compute_address.shortnr.address description = "The public static IP address used by the Shortnr instance." } @@ -33,17 +33,17 @@ data "google_compute_image" "debian_image" { project = "debian-cloud" } -resource "google_compute_address" "selfpass" { - name = "selfpass-address" +resource "google_compute_address" "shortnr" { + name = "shortnr-address" } -resource "google_compute_instance" "selfpass" { - name = "selfpass-instance" +resource "google_compute_instance" "shortnr" { + name = "shortnr-instance" machine_type = "f1-micro" deletion_protection = var.deletion_protection boot_disk { - auto_delete = false + auto_delete = true initialize_params { image = data.google_compute_image.debian_image.self_link @@ -53,7 +53,7 @@ resource "google_compute_instance" "selfpass" { network_interface { network = "default" access_config { - nat_ip = google_compute_address.selfpass.address + nat_ip = google_compute_address.shortnr.address } } diff --git a/mix.exs b/mix.exs index f89ef5e..f131481 100644 --- a/mix.exs +++ b/mix.exs @@ -38,10 +38,29 @@ defmodule Shortnr.MixProject do [ build: &docker_build/1, "build.dev": &docker_build_dev/1, - lint: ["compile", "dialyzer", "credo --strict"] + lint: ["compile", "dialyzer", "credo --strict"], + "infra.apply": &infra_apply/1, + "infra.plan": &infra_plan/1, + "infra.destroy": &infra_destroy/1 ] end + defp infra_apply(_) do + if Mix.shell().yes?("Are you sure you want to apply? (Have you run plan?)") do + 0 = Mix.shell().cmd("cd ./infra && terraform validate && terraform apply -auto-approve") + end + end + + defp infra_destroy(_) do + if Mix.shell().yes?("Are you sure you want to destroy?") do + 0 = Mix.shell().cmd("cd ./infra && terraform validate && terraform destroy -auto-approve") + end + end + + defp infra_plan(_) do + 0 = Mix.shell().cmd("cd ./infra && terraform validate && terraform plan") + end + defp docker_build(_) do 0 = Mix.shell().cmd("docker build -t shortnr:latest .") end