Skip to content

Commit

Permalink
feat(instances): use terraform workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiomario committed Nov 7, 2024
1 parent 4267896 commit 61d592f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 40 deletions.
40 changes: 30 additions & 10 deletions instances/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,43 @@ provider "aws" {
region = "us-east-1"
}

locals {
# Tipo de imagem para o servidor legado (APIS e Clientes Bonde)
ami = "ami-0866a3c8686eaeeba"

# Nome da chave SSH
key_name = "custom-host"

# Caminho para a chave privada SSH
private_key_path = "~/.ssh/ailton-krenak.pem"

# Ambiente (dev, staging, production)
env = terraform.workspace

# Tipo de instância para o servidor legado (APIS e Clientes Bonde)
legacy_server_instance_type = terraform.workspace == "stage" ? "t3.small" : "t3.micro"

# Tipo de instância para o servidor de sites (Bonde Público e CMS)
sites_server_instance_type = terraform.workspace == "stage" ? "t3.micro" : "t2.micro"
}

# Módulo para o servidor web
module "legacy_server" {
source = "./modules/common"
ami = var.ami
instance_type = var.legacy_server_instance_type
instance_name = "legacy-server-${var.env}"
key_name = var.key_name
private_key_path = var.private_key_path
ami = local.ami
instance_type = local.legacy_server_instance_type
instance_name = "legacy-server-${local.env}"
key_name = local.key_name
private_key_path = local.private_key_path
monitoring_files_path = "./monitoring"
}

module "sites_server" {
source = "./modules/common"
ami = var.ami
instance_type = var.sites_server_instance_type
instance_name = "sites-server-${var.env}"
key_name = var.key_name
private_key_path = var.private_key_path
ami = local.ami
instance_type = local.sites_server_instance_type
instance_name = "sites-server-${local.env}"
key_name = local.key_name
private_key_path = local.private_key_path
monitoring_files_path = "./monitoring"
}
1 change: 1 addition & 0 deletions instances/modules/common/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ resource "aws_instance" "server" {
ami = var.ami
instance_type = var.instance_type

# Nome da chave existente na Amazon, você deve ter o par da chave na sua máquina
key_name = var.key_name

tags = {
Expand Down
30 changes: 0 additions & 30 deletions instances/variables.tf

This file was deleted.

0 comments on commit 61d592f

Please sign in to comment.