From 92ef6b37270d4a656cf152711a1a840993ca74a3 Mon Sep 17 00:00:00 2001 From: Matthew Creal Morgan Date: Mon, 17 Mar 2025 15:05:34 -0700 Subject: [PATCH] Autoscaling (#13) * action * autoscaling * update requests --- .github/workflows/terragrunt-cicd.yml | 101 ++++++++++++++++++++++++++ .tflint.hcl | 26 +++---- README.md | 4 +- main.tf | 42 +++++++++++ 4 files changed, 157 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/terragrunt-cicd.yml diff --git a/.github/workflows/terragrunt-cicd.yml b/.github/workflows/terragrunt-cicd.yml new file mode 100644 index 0000000..a78523e --- /dev/null +++ b/.github/workflows/terragrunt-cicd.yml @@ -0,0 +1,101 @@ +name: 'Terraform Module CI' + +on: + push: + branches: + - main + paths: + - '**/*.hcl' + - '**/*.tf' + pull_request: + branches: + - main + paths: + - '**/*.hcl' + - '**/*.tf' + +permissions: + contents: read + pull-requests: write + +jobs: + validate: + name: 'Validate Module' + runs-on: self-hosted + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Terraform + uses: hashicorp/setup-terraform@v2 + with: + terraform_version: 1.5.0 + + - name: Terraform Init + run: | + terraform init -backend=false + + - name: Terraform Format + run: | + terraform fmt -check + + - name: Terraform Validate + run: | + terraform validate + + - name: Run tflint + uses: terraform-linters/setup-tflint@v3 + if: github.event_name == 'pull_request' + + - name: Lint Terraform + if: github.event_name == 'pull_request' + run: | + tflint --format compact + + release: + name: 'Create Release' + needs: validate + if: github.ref == 'refs/heads/main' && github.event_name == 'push' + runs-on: self-hosted + permissions: + contents: write + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: '3.9' + + - name: Install Commitizen + run: | + pip install commitizen + + - name: Configure Git + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + + - name: Bump Version and Generate Changelog + id: cz + run: | + cz bump --yes + echo "new_version=$(cz version --project)" >> $GITHUB_OUTPUT + echo "changelog=$(cz changelog --dry-run)" >> $GITHUB_OUTPUT + + - name: Create Release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: v${{ steps.cz.outputs.new_version }} + release_name: Release v${{ steps.cz.outputs.new_version }} + draft: false + prerelease: false + body: ${{ steps.cz.outputs.changelog }} diff --git a/.tflint.hcl b/.tflint.hcl index f63db7d..6a77997 100644 --- a/.tflint.hcl +++ b/.tflint.hcl @@ -5,18 +5,18 @@ config { } -rule "aws_instance_invalid_type" { - enabled = true -} +# rule "aws_instance_invalid_type" { +# enabled = true +# } -plugin "aws" { - enabled = true - version = "0.32.0" - source = "github.com/terraform-linters/tflint-ruleset-aws" -} +# plugin "aws" { +# enabled = true +# version = "0.32.0" +# source = "github.com/terraform-linters/tflint-ruleset-aws" +# } -plugin "terraform" { - enabled = true - version = "0.9.0" - source = "github.com/terraform-linters/tflint-ruleset-terraform" -} +# plugin "terraform" { +# enabled = true +# version = "0.9.0" +# source = "github.com/terraform-linters/tflint-ruleset-terraform" +# } diff --git a/README.md b/README.md index 3e07f85..68e37b8 100644 --- a/README.md +++ b/README.md @@ -69,8 +69,7 @@ sys 0m3.489s | Name | Version | |------|---------| -| [helm](#provider\_helm) | 2.16.1 | -| [kubernetes](#provider\_kubernetes) | 2.33.0 | +| [helm](#provider\_helm) | 2.17.0 | ## Modules @@ -83,7 +82,6 @@ sys 0m3.489s | Name | Type | |------|------| | [helm_release.prometheus](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource | -| [kubernetes_namespace.ns](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/namespace) | resource | ## Inputs diff --git a/main.tf b/main.tf index c1c7b09..9fb4dcb 100644 --- a/main.tf +++ b/main.tf @@ -113,4 +113,46 @@ resource "helm_release" "prometheus" { name = "prometheus-pushgateway.image.tag" value = module.images.images[local.pushgateway_key].tag } + + set { + name = "server.resources.requests.cpu" + value = "1m" + } + + set { + name = "server.resources.requests.memory" + value = "1Mi" + } + + set { + name = "server.resources.limits.cpu" + value = "1000m" + } + + set { + name = "server.resources.limits.memory" + value = "2Gi" + } + + # Autoscaling for Prometheus server + set { + name = "server.autoscaling.enabled" + value = "true" + } + + set { + name = "server.autoscaling.minReplicas" + value = "1" + } + + set { + name = "server.autoscaling.maxReplicas" + value = "5" + } + + set { + name = "server.autoscaling.targetCPUUtilizationPercentage" + value = "80" + } + }