Refactor main.tf and add infra mix tasks

Refactor main.tf to use the correct project name (oops).

Add terraform infra(structure) tasks to projects mix file:
  - infra.apply: Deploys the infra. according using terraform
  - infra.destroy: Destroys the currently deployed infrastructure
  - infra.plan: Plans a deployment using terraform
This commit is contained in:
mitchell 2020-03-12 23:20:20 -04:00
parent 7ea55a00f3
commit a021daf62f
2 changed files with 27 additions and 8 deletions

View File

@ -24,7 +24,7 @@ variable "deletion_protection" {
} }
output "shortnr_static_ip" { 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." description = "The public static IP address used by the Shortnr instance."
} }
@ -33,17 +33,17 @@ data "google_compute_image" "debian_image" {
project = "debian-cloud" project = "debian-cloud"
} }
resource "google_compute_address" "selfpass" { resource "google_compute_address" "shortnr" {
name = "selfpass-address" name = "shortnr-address"
} }
resource "google_compute_instance" "selfpass" { resource "google_compute_instance" "shortnr" {
name = "selfpass-instance" name = "shortnr-instance"
machine_type = "f1-micro" machine_type = "f1-micro"
deletion_protection = var.deletion_protection deletion_protection = var.deletion_protection
boot_disk { boot_disk {
auto_delete = false auto_delete = true
initialize_params { initialize_params {
image = data.google_compute_image.debian_image.self_link image = data.google_compute_image.debian_image.self_link
@ -53,7 +53,7 @@ resource "google_compute_instance" "selfpass" {
network_interface { network_interface {
network = "default" network = "default"
access_config { access_config {
nat_ip = google_compute_address.selfpass.address nat_ip = google_compute_address.shortnr.address
} }
} }

21
mix.exs
View File

@ -38,10 +38,29 @@ defmodule Shortnr.MixProject do
[ [
build: &docker_build/1, build: &docker_build/1,
"build.dev": &docker_build_dev/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 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 defp docker_build(_) do
0 = Mix.shell().cmd("docker build -t shortnr:latest .") 0 = Mix.shell().cmd("docker build -t shortnr:latest .")
end end