From 433466469a8080cc7951b83a7b2baef5d8ffddfb Mon Sep 17 00:00:00 2001 From: Igor Santos Date: Tue, 12 Nov 2024 12:02:03 -0300 Subject: [PATCH] feat(instances): add command to attach server in portainer --- instances/main.tf | 2 ++ instances/modules/common/main.tf | 2 ++ instances/modules/common/variables.tf | 11 +++++++++++ instances/variables.tf | 11 +++++++++++ 4 files changed, 26 insertions(+) diff --git a/instances/main.tf b/instances/main.tf index 3b6556c..30f52be 100644 --- a/instances/main.tf +++ b/instances/main.tf @@ -46,6 +46,8 @@ module "legacy_server" { monitoring_files_path = "./monitoring" influxdb_token = var.influxdb_token elastic_ip_allocation_id = var.legacy_elastic_ip_allocation_id + portainer_edge_id = var.legacy_portainer_edge_id + portainer_edge_key = var.legacy_portainer_edge_key } # module "sites_server" { diff --git a/instances/modules/common/main.tf b/instances/modules/common/main.tf index 3b6ede9..586c462 100644 --- a/instances/modules/common/main.tf +++ b/instances/modules/common/main.tf @@ -43,6 +43,8 @@ resource "aws_instance" "server" { "sudo su -c 'echo \"INFLUXDB_TOKEN=${var.influxdb_token}\" >> /etc/default/telegraf'", # Reinicia o telegraf para garantir que a variavel está configurada "sudo systemctl restart telegraf", + # Adiciona essa instância ao Portainer + "sudo docker run -d -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/docker/volumes:/var/lib/docker/volumes -v /:/host -v portainer_agent_data:/data --restart always -e EDGE=1 -e EDGE_ID=${var.portainer_edge_id} -e EDGE_KEY=${var.portainer_edge_key} -e EDGE_INSECURE_POLL=1 --name portainer_edge_agent portainer/agent:2.15.1" ] connection { diff --git a/instances/modules/common/variables.tf b/instances/modules/common/variables.tf index 21bd6df..022fd15 100644 --- a/instances/modules/common/variables.tf +++ b/instances/modules/common/variables.tf @@ -38,4 +38,15 @@ variable "elastic_ip_allocation_id" { description = "ID da alocação de um IP Elástico da AWS" type = string default = "" +} + +variable "portainer_edge_id" { + description = "ID do ambiente no Portainer" + type = string +} + +variable "portainer_edge_key" { + description = "Chave Secreta do ambiente no Portainer" + type = string + sensitive = true } \ No newline at end of file diff --git a/instances/variables.tf b/instances/variables.tf index d03c376..79e5943 100644 --- a/instances/variables.tf +++ b/instances/variables.tf @@ -28,4 +28,15 @@ variable "sites_server_instance_type" { description = "Tipo de instância para o servidor de sites (Bonde Público e CMS)" type = string default = "t3.micro" +} + +variable "legacy_portainer_edge_id" { + description = "ID do ambiente no Portainer" + type = string +} + +variable "legacy_portainer_edge_key" { + description = "Chave Secreta do ambiente no Portainer" + type = string + sensitive = true } \ No newline at end of file