Skip to content

Commit

Permalink
fix(ci/cd): add variable to setup influxdb token in servers
Browse files Browse the repository at this point in the history
  • Loading branch information
igr-santos committed Nov 7, 2024
1 parent 8f18146 commit c044059
Show file tree
Hide file tree
Showing 7 changed files with 13,719 additions and 4 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/terraform-stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
# Confira o repositório para o GitHub Actions runner
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true # Clona os submódulos junto com o repositório principal
fetch-depth: 0 # Garante que o histórico completo seja baixado, necessário para alguns submódulos
token: ${{ secrets.GITHUB_TOKEN }} # Usa o token para acessar submódulos privados
# with:
# submodules: true # Clona os submódulos junto com o repositório principal
# fetch-depth: 0 # Garante que o histórico completo seja baixado, necessário para alguns submódulos
# token: ${{ secrets.GITHUB_TOKEN }} # Usa o Github token para acessar submódulos privados

- name: Setup SSH key
env:
Expand All @@ -48,6 +48,7 @@ jobs:
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
TF_VAR_INFLUXDB_TOKEN: ${{ secrets.INFLUXDB_TOKEN }}
run: terraform init

- name: Terraform Validate
Expand All @@ -60,18 +61,21 @@ jobs:
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
TF_VAR_INFLUXDB_TOKEN: ${{ secrets.INFLUXDB_TOKEN }}
run: terraform workspace select stage

- name: Terraform Plan
working-directory: ./instances
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
TF_VAR_INFLUXDB_TOKEN: ${{ secrets.INFLUXDB_TOKEN }}
run: terraform plan

- name: Terraform Apply
working-directory: ./instances
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
TF_VAR_INFLUXDB_TOKEN: ${{ secrets.INFLUXDB_TOKEN }}
run: terraform apply -auto-approve
2 changes: 2 additions & 0 deletions instances/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ module "legacy_server" {
key_name = local.key_name
private_key_path = local.private_key_path
monitoring_files_path = "./monitoring"
influxdb_token = var.influxdb_token
}

module "sites_server" {
Expand All @@ -63,4 +64,5 @@ module "sites_server" {
key_name = local.key_name
private_key_path = local.private_key_path
monitoring_files_path = "./monitoring"
influxdb_token = var.influxdb_token
}
2 changes: 2 additions & 0 deletions instances/modules/common/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ resource "aws_instance" "server" {
"sudo usermod -aG docker ubuntu",
# Altera o hostname antes de instalar o telegraf
"sudo hostnamectl set-hostname --transient --static ${var.instance_name}",
# Configura a variável que será usada no telegraf
"echo 'export INFLUXDB_TOKEN=\"${var.influxdb_token}\"' >> /etc/profile.d/influxdb_token.sh"
# Inicia a configuração do monitoramento
"cd /home/ubuntu/monitoring/",
"sudo chmod +x install-telegraf.sh",
Expand Down
6 changes: 6 additions & 0 deletions instances/modules/common/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,10 @@ variable "private_key_path" {
variable "monitoring_files_path" {
description = "Caminho para arquivos de instalação do monitoramento"
type = string
}

variable "influxdb_token" {
description = "Chave utilizada para o telegraf enviar dados ao Influxdb"
type = string
sensitive = true
}
Loading

0 comments on commit c044059

Please sign in to comment.