diff --git a/instances/envs/production.tfvars b/instances/envs/production.tfvars new file mode 100644 index 0000000..aca2c97 --- /dev/null +++ b/instances/envs/production.tfvars @@ -0,0 +1,6 @@ +legacy_server_instance_type="t2.micro" +sites_server_instance_type="t3.micro" +ami="ami-0866a3c8686eaeeba" +env="production" +key_name="custom-host" +private_key_path="~/Repositories/nossas/keys/ailton-krenak.pem" \ No newline at end of file diff --git a/instances/main.tf b/instances/main.tf index 6038267..783674a 100644 --- a/instances/main.tf +++ b/instances/main.tf @@ -15,31 +15,21 @@ provider "aws" { # Módulo para o servidor web module "legacy_server" { - source = "./modules/legacy_server" + source = "./modules/common" ami = var.ami instance_type = var.legacy_server_instance_type - env = var.env + instance_name = "legacy-server-${var.env}" key_name = var.key_name private_key_path = var.private_key_path monitoring_files_path = "./monitoring" } module "sites_server" { - source = "./modules/sites_server" + source = "./modules/common" ami = var.ami instance_type = var.sites_server_instance_type - env = var.env + instance_name = "sites-server-${var.env}" key_name = var.key_name private_key_path = var.private_key_path monitoring_files_path = "./monitoring" -} - -# Módulo para o servidor de banco de dados -# module "db_server" { -# source = "./modules/db_server" -# ami_id = var.db_server_ami_id -# instance_type = var.db_server_instance_type -# key_name = var.key_name -# instance_name = "db-server-${var.env}" -# private_key_path = var.private_key_path -# } \ No newline at end of file +} \ No newline at end of file diff --git a/instances/modules/common/main.tf b/instances/modules/common/main.tf index b2cf93b..3e5de6b 100644 --- a/instances/modules/common/main.tf +++ b/instances/modules/common/main.tf @@ -1,9 +1,8 @@ -# resource "aws_key_pair" "devops_key_pair" { -# key_name = "devops-host" -# public_key = file("~/.ssh/id_rsa.pub") -# } +# Define um formato de instância genérica para criar novas instâncias monitoradas +# e habilitadas para implantar arquiteturas baseadas em Docker. -resource "aws_instance" "common_instance" { +resource "aws_instance" "server" { + # Sistema operacional na Amazon ami = var.ami instance_type = var.instance_type @@ -33,7 +32,7 @@ resource "aws_instance" "common_instance" { "sudo systemctl start docker", "sudo systemctl enable docker", "sudo usermod -aG docker ubuntu", - # Altera o hostname antes de instalar o telegraf + # Altera o hostname antes de instalar o telegraf "sudo hostnamectl set-hostname --transient --static ${var.instance_name}", # Inicia a configuração do monitoramento "cd /home/ubuntu/monitoring/", diff --git a/instances/modules/legacy_server/main.tf b/instances/modules/legacy_server/main.tf deleted file mode 100644 index 40e2502..0000000 --- a/instances/modules/legacy_server/main.tf +++ /dev/null @@ -1,16 +0,0 @@ -module "common" { - source = "../common" - ami = var.ami - instance_type = var.instance_type - instance_name = "legacy-server-${var.env}" - key_name = var.key_name - private_key_path = var.private_key_path - monitoring_files_path = var.monitoring_files_path -} - -resource "aws_instance" "legacy_server" { - ami = var.ami - instance_type = var.instance_type - - depends_on = [ module.common ] -} \ No newline at end of file diff --git a/instances/modules/legacy_server/variables.tf b/instances/modules/legacy_server/variables.tf deleted file mode 100644 index 7a3de24..0000000 --- a/instances/modules/legacy_server/variables.tf +++ /dev/null @@ -1,29 +0,0 @@ -variable ami { - description = "Tipo de imagem para o servidor legado (APIS e Clientes Bonde)" - type = string -} - -variable "instance_type" { - description = "Tipo de instância para o servidor legado (APIS e Clientes Bonde)" - type = string -} - -variable "env" { - description = "Ambiente (dev, staging, production)" - type = string -} - -variable "key_name" { - description = "Nome da chave SSH" - type = string -} - -variable "private_key_path" { - description = "Caminho para a chave privada SSH" - type = string -} - -variable "monitoring_files_path" { - description = "Caminho para arquivos de instalação do monitoramento" - type = string -} \ No newline at end of file diff --git a/instances/modules/sites_server/main.tf b/instances/modules/sites_server/main.tf deleted file mode 100644 index e0fc809..0000000 --- a/instances/modules/sites_server/main.tf +++ /dev/null @@ -1,16 +0,0 @@ -module "common" { - source = "../common" - ami = var.ami - instance_type = var.instance_type - instance_name = "sites-server-${var.env}" - key_name = var.key_name - private_key_path = var.private_key_path - monitoring_files_path = var.monitoring_files_path -} - -resource "aws_instance" "sites_server" { - ami = var.ami - instance_type = var.instance_type - - depends_on = [ module.common ] -} \ No newline at end of file diff --git a/instances/modules/sites_server/variables.tf b/instances/modules/sites_server/variables.tf deleted file mode 100644 index 90935a4..0000000 --- a/instances/modules/sites_server/variables.tf +++ /dev/null @@ -1,29 +0,0 @@ -variable ami { - description = "Tipo de imagem para o servidor de sites (APIS e Clientes Bonde)" - type = string -} - -variable "instance_type" { - description = "Tipo de instância para o servidor legado (APIS e Clientes Bonde)" - type = string -} - -variable "env" { - description = "Ambiente (dev, staging, production)" - type = string -} - -variable "key_name" { - description = "Nome da chave SSH" - type = string -} - -variable "private_key_path" { - description = "Caminho para a chave privada SSH" - type = string -} - -variable "monitoring_files_path" { - description = "Caminho para arquivos de instalação do monitoramento" - type = string -} \ No newline at end of file diff --git a/instances/variables.tf b/instances/variables.tf index 912f682..95334db 100644 --- a/instances/variables.tf +++ b/instances/variables.tf @@ -1,19 +1,17 @@ variable ami { description = "Tipo de imagem para o servidor legado (APIS e Clientes Bonde)" type = string - default = "ami-0866a3c8686eaeeba" + default = "ami-0866a3c8686eaeeba" # Ubuntu } variable "legacy_server_instance_type" { description = "Tipo de instância para o servidor legado (APIS e Clientes Bonde)" type = string - default = "t2.micro" } variable "sites_server_instance_type" { description = "Tipo de instância para o servidor de sites (Bonde Público e CMS)" type = string - default = "t2.micro" } variable "env" {