From 2e18450e9ac97aaaea61f0e90f488dc7bbc77e1c Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Tue, 6 Aug 2024 17:31:45 -0400 Subject: [PATCH 1/8] =?UTF-8?q?=F0=9F=8E=A8=20style(repo):=20add=20repo=20?= =?UTF-8?q?features=20pre-commit=20and=20commitizen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .cz.yaml | 8 ++++ .github/dependabot.yml | 11 +++++ .gitignore | 1 - .gitignore copy | 37 +++++++++++++++ .pre-commit-config.yaml | 99 +++++++++++++++++++++++++++++++++++++++++ .releaserc.json | 36 +++++++++++++++ .terraform-docs.yml | 44 ++++++++++++++++++ .tflint.hcl | 22 +++++++++ README.md | 22 +++++---- copy_images.tf | 10 ----- examples/simple/main.tf | 31 +++++++------ main.tf | 6 +-- outputs.tf | 11 +++-- requirements.tf | 8 ---- version.tf | 4 +- 15 files changed, 298 insertions(+), 52 deletions(-) create mode 100644 .cz.yaml create mode 100644 .github/dependabot.yml create mode 100644 .gitignore copy create mode 100644 .pre-commit-config.yaml create mode 100644 .releaserc.json create mode 100644 .terraform-docs.yml create mode 100644 .tflint.hcl diff --git a/.cz.yaml b/.cz.yaml new file mode 100644 index 0000000..b1981ec --- /dev/null +++ b/.cz.yaml @@ -0,0 +1,8 @@ +--- +commitizen: + major_version_zero: true + name: cz_gitmoji + tag_format: $version + update_changelog_on_bump: true + version_provider: scm + version_scheme: semver2 diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..867570d --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "terraform" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "daily" diff --git a/.gitignore b/.gitignore index 7c1cae9..403ffa9 100644 --- a/.gitignore +++ b/.gitignore @@ -35,4 +35,3 @@ override.tf.json # Ignore CLI configuration files .terraformrc terraform.rc - diff --git a/.gitignore copy b/.gitignore copy new file mode 100644 index 0000000..403ffa9 --- /dev/null +++ b/.gitignore copy @@ -0,0 +1,37 @@ +# Local .terraform directories +**/.terraform/* + +# terraform lock file. +**/.terraform.lock.hcl + +# .tfstate files +*.tfstate +*.tfstate.* + +# Crash log files +crash.log +crash.*.log + +# Exclude all .tfvars files, which are likely to contain sensitive data, +# such as password, private keys, and other secrets. These should not be +# part of version control as they are data points which are potentially +# sensitive and subject to change depending on the environment. +*.tfvars +*.tfvars.json + +# Ignore override files as they are usually used to override resources +# locally and so are not checked in +override.tf +override.tf.json +*_override.tf +*_override.tf.json + +# Include override files you do wish to add to version control using negated pattern +# !example_override.tf + +# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan +# example: *tfplan* + +# Ignore CLI configuration files +.terraformrc +terraform.rc diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..6bfca7a --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,99 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: + # Git style + - id: check-added-large-files + - id: check-merge-conflict + - id: check-vcs-permalinks + - id: forbid-new-submodules + - id: no-commit-to-branch + + # Common errors + - id: end-of-file-fixer + - id: trailing-whitespace + args: [--markdown-linebreak-ext=md] + exclude: CHANGELOG.md + - id: check-yaml + - id: check-merge-conflict + - id: check-executables-have-shebangs + + # Cross platform + - id: check-case-conflict + - id: mixed-line-ending + args: [--fix=lf] + + # Security + - id: detect-aws-credentials + args: ['--allow-missing-credentials'] + - id: detect-private-key + +# JSON5 Linter +- repo: https://github.com/pre-commit/mirrors-prettier + rev: v4.0.0-alpha.8 + hooks: + - id: prettier + # https://prettier.io/docs/en/options.html#parser + files: '.json5$' + +# Terraform Hooks +- repo: https://github.com/antonbabenko/pre-commit-terraform + rev: v1.92.1 # Get the latest from: https://github.com/antonbabenko/pre-commit-terraform/releases + hooks: + - id: terraform_fmt + args: + - --hook-config=--parallelism-ci-cpu-cores=2 + - id: terraform_docs + args: + - --hook-config=--parallelism-ci-cpu-cores=2 + - id: terraform_tflint + name: Terraform validate with tflint + description: Validates all Terraform configuration files with TFLint. + require_serial: true + entry: hooks/terraform_tflint.sh + language: script + files: (\.tf|\.tfvars)$ + exclude: \.(terraform/.*|terragrunt-cache)$ + args: + - --hook-config=--parallelism-ci-cpu-cores=2 + - id: terragrunt_fmt + name: Terragrunt fmt + description: Rewrites all Terragrunt configuration files to a canonical format. + entry: hooks/terragrunt_fmt.sh + language: script + files: (\.hcl)$ + exclude: \.(terraform/.*|terragrunt-cache)$ + args: + - --hook-config=--parallelism-ci-cpu-cores=2 + # - id: terragrunt_validate + # name: Terragrunt validate + # description: Validates all Terragrunt configuration files. + # entry: hooks/terragrunt_validate.sh + # language: script + # files: (\.hcl)$ + # exclude: \.(terraform/.*|terragrunt-cache)$ + # args: + # - --hook-config=--parallelism-ci-cpu-cores=2 + # - id: terragrunt_validate_inputs + # name: Terragrunt validate inputs + # description: Validates Terragrunt unused and undefined inputs. + # entry: hooks/terragrunt_validate_inputs.sh + # language: script + # files: (\.hcl)$ + # exclude: \.(terraform/.*|terragrunt-cache)$ + # args: + # - --hook-config=--parallelism-ci-cpu-cores=2 + # - id: terragrunt_providers_lock + # name: Terragrunt providers lock + # description: Updates provider signatures in dependency lock files using terragrunt. + # entry: hooks/terragrunt_providers_lock.sh + # language: script + # files: (terragrunt|\.terraform\.lock)\.hcl$ + # exclude: \.(terraform/.*|terragrunt-cache)$ + # args: + # - --hook-config=--parallelism-ci-cpu-cores=2 + +- repo: https://github.com/ljnsn/cz-conventional-gitmoji + rev: v0.3.2 + hooks: + - id: conventional-gitmoji diff --git a/.releaserc.json b/.releaserc.json new file mode 100644 index 0000000..6e39031 --- /dev/null +++ b/.releaserc.json @@ -0,0 +1,36 @@ +{ + "branches": [ + "main", + "master" + ], + "ci": false, + "plugins": [ + "@semantic-release/commit-analyzer", + "@semantic-release/release-notes-generator", + [ + "@semantic-release/github", + { + "successComment": + "This ${issue.pull_request ? 'PR is included' : 'issue has been resolved'} in version ${nextRelease.version} :tada:", + "labels": false, + "releasedLabels": false + } + ], + [ + "@semantic-release/changelog", + { + "changelogFile": "CHANGELOG.md", + "changelogTitle": "# Changelog\n\nAll notable changes to this project will be documented in this file." + } + ], + [ + "@semantic-release/git", + { + "assets": [ + "CHANGELOG.md" + ], + "message": "chore(release): version ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}" + } + ] + ] +} diff --git a/.terraform-docs.yml b/.terraform-docs.yml new file mode 100644 index 0000000..fabfb8d --- /dev/null +++ b/.terraform-docs.yml @@ -0,0 +1,44 @@ +formatter: markdown table + +header-from: main.tf +footer-from: "" + +sections: +## hide: [] + show: + - data-sources + - header + - footer + - inputs + - modules + - outputs + - providers + - requirements + - resources + +output: + file: README.md + mode: inject + template: |- + + {{ .Content }} + + +output-values: + enabled: false + from: "" + +sort: + enabled: true + by: name + +settings: + anchor: true + color: true + default: true + description: true + escape: true + indent: 2 + required: true + sensitive: true + type: true diff --git a/.tflint.hcl b/.tflint.hcl new file mode 100644 index 0000000..f63db7d --- /dev/null +++ b/.tflint.hcl @@ -0,0 +1,22 @@ +config { + module = true + force = false + disabled_by_default = false + +} + +rule "aws_instance_invalid_type" { + enabled = true +} + +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" +} diff --git a/README.md b/README.md index bab6556..71871be 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # tfmod-prometheus -Prometheus is an open source monitoring and alerting tool designed for dynamic cloud systems and especially well suited for monitoring microservice architectures. Prometheus collects and stores metrics as time series data. Metrics are a key means in understanding an applications behavior and a critical facet of operations support. Collectively, "it collects metrics from configured targets at given intervals, evaluates rule expressions, displays the results, and can trigger alerts if some condition is observed to be true." - [prometheus.io](https://prometheus.io/) +Prometheus is an open source monitoring and alerting tool designed for dynamic cloud systems and especially well suited for monitoring microservice architectures. Prometheus collects and stores metrics as time series data. Metrics are a key means in understanding an applications behavior and a critical facet of operations support. Collectively, "it collects metrics from configured targets at given intervals, evaluates rule expressions, displays the results, and can trigger alerts if some condition is observed to be true." - [prometheus.io](https://prometheus.io/) This modules uses Helm to deploy Prometheus to a cluster using the official chart. By default this will install dependent charts/components: - [alertmanager](https://github.com/prometheus-community/helm-charts/tree/main/charts/alertmanager) @@ -29,17 +29,15 @@ Versions are module variables, but latest versions are intended to be be reflect | Name | Version | |------|---------| | [terraform](#requirement\_terraform) | >= 0.13 | -| [aws](#requirement\_aws) | >= 5.14.0 | | [helm](#requirement\_helm) | >= 2.11.0 | | [kubernetes](#requirement\_kubernetes) | >= 2.23.0 | -| [null](#requirement\_null) | >= 3.2.1 | ## Providers | Name | Version | |------|---------| -| [helm](#provider\_helm) | >= 2.11.0 | -| [kubernetes](#provider\_kubernetes) | >= 2.23.0 | +| [helm](#provider\_helm) | 2.14.0 | +| [kubernetes](#provider\_kubernetes) | 2.31.0 | ## Modules @@ -53,7 +51,7 @@ Versions are module variables, but latest versions are intended to be be reflect |------|------| | [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 | -| [kubernetes_namespace.existing-ns](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/data-sources/namespace) | data source | +| [kubernetes_namespace.existing_ns](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/data-sources/namespace) | data source | ## Inputs @@ -67,7 +65,7 @@ Versions are module variables, but latest versions are intended to be be reflect | [node\_exporter\_tag](#input\_node\_exporter\_tag) | The image tag of the node-exporter image. | `string` | `"v1.8.2"` | no | | [profile](#input\_profile) | AWS\_PROFILE to use to apply the terraform script. | `string` | `""` | no | | [prometheus\_chart\_version](#input\_prometheus\_chart\_version) | The version of prometheus to install into the cluster. | `string` | `"25.24.1"` | no | -| [prometheus\_config\_reloader\_tag](#input\_prometheus\_config\_reloader\_tag) | The image tag of the prometheus-config-reloader image. | `string` | `"v0.75.1"` | no | +| [prometheus\_config\_reloader\_tag](#input\_prometheus\_config\_reloader\_tag) | The image tag of the prometheus-config-reloader image. | `string` | `"v0.74.0"` | no | | [prometheus\_server\_tag](#input\_prometheus\_server\_tag) | The image tag of prometheus server to install into the cluster. | `string` | `"v2.53.1"` | no | | [pushgateway\_tag](#input\_pushgateway\_tag) | The image tag of the pushgateway image. | `string` | `"v1.9.0"` | no | | [rwo\_storage\_class](#input\_rwo\_storage\_class) | Specify the storage class for read/write/once persistent volumes. | `string` | `"gp3-encrypted"` | no | @@ -76,11 +74,11 @@ Versions are module variables, but latest versions are intended to be be reflect | Name | Description | |------|-------------| -| [alertmanager\_headless\_internal\_endpoint](#output\_alertmanager\_headless\_internal\_endpoint) | n/a | -| [alertmanager\_internal\_endpoint](#output\_alertmanager\_internal\_endpoint) | n/a | +| [alertmanager\_headless\_internal\_endpoint](#output\_alertmanager\_headless\_internal\_endpoint) | headless internal endpoint for alertmanager | +| [alertmanager\_internal\_endpoint](#output\_alertmanager\_internal\_endpoint) | internal endpoint for alertmanager | | [module\_name](#output\_module\_name) | The name of this module. | | [module\_version](#output\_module\_version) | The version of this module. | -| [prometheus\_namespace](#output\_prometheus\_namespace) | n/a | -| [prometheus\_server\_internal\_endpoint](#output\_prometheus\_server\_internal\_endpoint) | n/a | -| [pushgateway\_internal\_endpoint](#output\_pushgateway\_internal\_endpoint) | n/a | +| [prometheus\_namespace](#output\_prometheus\_namespace) | namespace for prometheus | +| [prometheus\_server\_internal\_endpoint](#output\_prometheus\_server\_internal\_endpoint) | internal endpoint for prometheus | +| [pushgateway\_internal\_endpoint](#output\_pushgateway\_internal\_endpoint) | internal endpoint for pushgateway | diff --git a/copy_images.tf b/copy_images.tf index 8bb3eab..a64dbbb 100644 --- a/copy_images.tf +++ b/copy_images.tf @@ -83,16 +83,6 @@ module "images" { image_config = local.image_config tags = {} - ### optional - ## account_alias = "" - ## account_id = "" - ## destination_password = "" - ## destination_username = "" - ## override_prefixes = {} - ## region = "" - ## source_password = "" - ## source_username = "" - enable_lifecycle_policy = true lifecycle_policy_all = true force_delete = true diff --git a/examples/simple/main.tf b/examples/simple/main.tf index b2ed1d7..fb5e808 100644 --- a/examples/simple/main.tf +++ b/examples/simple/main.tf @@ -1,3 +1,20 @@ +terraform { + required_version = ">= 0.13" + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 5.14.0" + } + helm = { + source = "hashicorp/helm" + version = ">= 2.11.0" + } + kubernetes = { + source = "hashicorp/kubernetes" + version = ">= 2.23.0" + } + } +} provider "aws" { profile = local.profile region = local.region @@ -34,18 +51,6 @@ locals { namespace = "prometheus" create_namespace = "true" - # tags = { - # project_number = "fs0000000078" - # project_name = "csvd_platformbaseline" - # project_role = "csvd_platformbaseline_app" - # organization = "census:ocio:csvd" - # created_by = "luther.coleman.mcginty@census.gov" - # created_for = "luther.coleman.mcginty@census.gov" - # created_reason = "Testing eks module operation" - # Terraform = "true" - # Terragrunt = "true" - # test_adjustment = "testing adding tags" - # } } module "prometheus" { @@ -55,4 +60,4 @@ module "prometheus" { cluster_name = local.cluster_name namespace = local.namespace create_namespace = local.create_namespace -} \ No newline at end of file +} diff --git a/main.tf b/main.tf index 949f768..9a93623 100644 --- a/main.tf +++ b/main.tf @@ -28,7 +28,7 @@ resource "kubernetes_namespace" "ns" { } } -data "kubernetes_namespace" "existing-ns" { +data "kubernetes_namespace" "existing_ns" { count = var.create_namespace == true ? 0 : 1 metadata { @@ -37,7 +37,7 @@ data "kubernetes_namespace" "existing-ns" { } locals { - ns = try(kubernetes_namespace.ns[0].metadata[0].name, data.kubernetes_namespace.existing-ns[0].metadata[0].name) + ns = try(kubernetes_namespace.ns[0].metadata[0].name, data.kubernetes_namespace.existing_ns[0].metadata[0].name) } resource "helm_release" "prometheus" { @@ -52,7 +52,7 @@ resource "helm_release" "prometheus" { # Global set { - name = "server.extraArgs.web.enable-remote-write-receiver" + name = "server.extraArgs.web.enable-remote-write-receiver" value = "null" # kubectl -n prometheus describe deployment prometheus-server # Will show in the args list as: diff --git a/outputs.tf b/outputs.tf index ed51506..e047fe6 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,4 +1,5 @@ output "alertmanager_internal_endpoint" { + description = "internal endpoint for alertmanager" value = { hostname = local.alertmanager_internal_hostname port_number = local.alertmanager_internal_port_number @@ -7,6 +8,7 @@ output "alertmanager_internal_endpoint" { } output "alertmanager_headless_internal_endpoint" { + description = "headless internal endpoint for alertmanager" value = { hostname = local.headless_alertmanager_internal_hostname port_number = local.headless_alertmanager_internal_port_number @@ -15,6 +17,7 @@ output "alertmanager_headless_internal_endpoint" { } output "pushgateway_internal_endpoint" { + description = "internal endpoint for pushgateway" value = { hostname = local.pushgateway_internal_hostname port_number = local.pushgateway_internal_port_number @@ -23,6 +26,7 @@ output "pushgateway_internal_endpoint" { } output "prometheus_server_internal_endpoint" { + description = "internal endpoint for prometheus" value = { hostname = local.server_internal_hostname port_number = local.server_internal_port_number @@ -31,7 +35,8 @@ output "prometheus_server_internal_endpoint" { } output "prometheus_namespace" { - value = local.ns + description = "namespace for prometheus" + value = local.ns } ################################################################################ @@ -40,10 +45,10 @@ output "prometheus_namespace" { output "module_name" { description = "The name of this module." - value = local._module_name + value = local.module_name } output "module_version" { description = "The version of this module." - value = local._module_version + value = local.module_version } diff --git a/requirements.tf b/requirements.tf index 32e5c6f..5f150af 100644 --- a/requirements.tf +++ b/requirements.tf @@ -2,10 +2,6 @@ terraform { required_version = ">= 0.13" required_providers { - aws = { - source = "hashicorp/aws" - version = ">= 5.14.0" - } helm = { source = "hashicorp/helm" version = ">= 2.11.0" @@ -14,9 +10,5 @@ terraform { source = "hashicorp/kubernetes" version = ">= 2.23.0" } - null = { - source = "hashicorp/null" - version = ">= 3.2.1" - } } } diff --git a/version.tf b/version.tf index 98adbea..55397e7 100644 --- a/version.tf +++ b/version.tf @@ -1,4 +1,4 @@ locals { - _module_name = "tfmod-prometheus" - _module_version = "0.0.2" + module_name = "tfmod-prometheus" + module_version = "0.0.2" } From 657969f751e6e7a2f0e92cd713d271bb1498d214 Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Tue, 6 Aug 2024 17:35:32 -0400 Subject: [PATCH 2/8] =?UTF-8?q?=F0=9F=9A=A8=20fix-lint(CHANGELOG.md):=20re?= =?UTF-8?q?solved=20lints,=20added=20changelog=20updated=20readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore copy | 37 ------------------------------------- CHANGELOG.md | 17 +++++++++++++++++ README.md | 13 ------------- 3 files changed, 17 insertions(+), 50 deletions(-) delete mode 100644 .gitignore copy create mode 100644 CHANGELOG.md diff --git a/.gitignore copy b/.gitignore copy deleted file mode 100644 index 403ffa9..0000000 --- a/.gitignore copy +++ /dev/null @@ -1,37 +0,0 @@ -# Local .terraform directories -**/.terraform/* - -# terraform lock file. -**/.terraform.lock.hcl - -# .tfstate files -*.tfstate -*.tfstate.* - -# Crash log files -crash.log -crash.*.log - -# Exclude all .tfvars files, which are likely to contain sensitive data, -# such as password, private keys, and other secrets. These should not be -# part of version control as they are data points which are potentially -# sensitive and subject to change depending on the environment. -*.tfvars -*.tfvars.json - -# Ignore override files as they are usually used to override resources -# locally and so are not checked in -override.tf -override.tf.json -*_override.tf -*_override.tf.json - -# Include override files you do wish to add to version control using negated pattern -# !example_override.tf - -# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan -# example: *tfplan* - -# Ignore CLI configuration files -.terraformrc -terraform.rc diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..1ddcff0 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,17 @@ +## Unreleased + +### 🎨🏗️ Style & Architecture + +- **repo**: add repo features pre-commit and commitizen + +# CHANGELOG +* 0.0.2 -- 2024-07-30 + - formatting + - added module default outputs + - updated images module + - add prometheus_namespace as output +* 0.0.1 -- 2024-07-22 + - add force_delete and lifecycle policies to copy_images + - updated version.tf to 0.0.1 + - included module.images in depends on helm charts + - created changelog diff --git a/README.md b/README.md index 71871be..158e5e9 100644 --- a/README.md +++ b/README.md @@ -10,19 +10,6 @@ This modules uses Helm to deploy Prometheus to a cluster using the official char Versions are module variables, but latest versions are intended to be be reflected in the default values. -# CHANGELOG -* 0.0.2 -- 2024-07-30 - - formatting - - added module default outputs - - updated images module - - add prometheus_namespace as output - - add --web.enable-remote-write-receiver -* 0.0.1 -- 2024-07-22 - - add force_delete and lifecycle policies to copy_images - - updated version.tf to 0.0.1 - - included module.images in depends on helm charts - - created changelog - ## Requirements From c6d018583c17fb8206d49c00fac782d3907de399 Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Tue, 6 Aug 2024 21:58:20 -0400 Subject: [PATCH 3/8] ns changes for testing --- README.md | 9 +++++---- main.tf | 17 +++-------------- variables.tf | 14 +++++++------- 3 files changed, 15 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 158e5e9..a47a7de 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,9 @@ This modules uses Helm to deploy Prometheus to a cluster using the official char Versions are module variables, but latest versions are intended to be be reflected in the default values. + + + ## Requirements @@ -38,7 +41,6 @@ Versions are module variables, but latest versions are intended to be be reflect |------|------| | [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 | -| [kubernetes_namespace.existing_ns](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/data-sources/namespace) | data source | ## Inputs @@ -46,13 +48,12 @@ Versions are module variables, but latest versions are intended to be be reflect |------|-------------|------|---------|:--------:| | [alertmanager\_tag](#input\_alertmanager\_tag) | The image tag of the alertmanager image. | `string` | `"v0.27.0"` | no | | [cluster\_name](#input\_cluster\_name) | The name of the cluster into which prometheus will be installed. | `string` | n/a | yes | -| [create\_namespace](#input\_create\_namespace) | Indicates whether the `namespace` needs to be created ('true') or already exists (not `true`) | `bool` | `true` | no | | [kube\_state\_metrics\_tag](#input\_kube\_state\_metrics\_tag) | The image tag of the kube-state-metrics image. | `string` | `"v2.13.0"` | no | | [namespace](#input\_namespace) | The namespace to install the prometheus components. Defaults to 'prometheus' | `string` | `"prometheus"` | no | | [node\_exporter\_tag](#input\_node\_exporter\_tag) | The image tag of the node-exporter image. | `string` | `"v1.8.2"` | no | | [profile](#input\_profile) | AWS\_PROFILE to use to apply the terraform script. | `string` | `""` | no | -| [prometheus\_chart\_version](#input\_prometheus\_chart\_version) | The version of prometheus to install into the cluster. | `string` | `"25.24.1"` | no | -| [prometheus\_config\_reloader\_tag](#input\_prometheus\_config\_reloader\_tag) | The image tag of the prometheus-config-reloader image. | `string` | `"v0.74.0"` | no | +| [prometheus\_chart\_version](#input\_prometheus\_chart\_version) | The version of prometheus to install into the cluster. | `string` | `"25.25.0"` | no | +| [prometheus\_config\_reloader\_tag](#input\_prometheus\_config\_reloader\_tag) | The image tag of the prometheus-config-reloader image. | `string` | `"v0.75.2"` | no | | [prometheus\_server\_tag](#input\_prometheus\_server\_tag) | The image tag of prometheus server to install into the cluster. | `string` | `"v2.53.1"` | no | | [pushgateway\_tag](#input\_pushgateway\_tag) | The image tag of the pushgateway image. | `string` | `"v1.9.0"` | no | | [rwo\_storage\_class](#input\_rwo\_storage\_class) | Specify the storage class for read/write/once persistent volumes. | `string` | `"gp3-encrypted"` | no | diff --git a/main.tf b/main.tf index 9a93623..6f63a0e 100644 --- a/main.tf +++ b/main.tf @@ -8,6 +8,8 @@ locals { headless_alertmanager_internal_port_number = 9093 headless_alertmanager_internal_url = format("http://%v:%v/", local.alertmanager_internal_hostname, local.alertmanager_internal_port_number) + # ns = try(kubernetes_namespace.ns[0].metadata[0].name, data.kubernetes_namespace.existing_ns[0].metadata[0].name) + pushgateway_internal_hostname = format("prometheus-prometheus-pushgateway.%v.svc.cluster.local", local.ns) pushgateway_internal_port_number = 9091 pushgateway_internal_url = format("http://%v:%v/", local.pushgateway_internal_hostname, local.pushgateway_internal_port_number) @@ -18,8 +20,6 @@ locals { } resource "kubernetes_namespace" "ns" { - count = var.create_namespace == true ? 1 : 0 - metadata { name = var.namespace labels = { @@ -28,17 +28,6 @@ resource "kubernetes_namespace" "ns" { } } -data "kubernetes_namespace" "existing_ns" { - count = var.create_namespace == true ? 0 : 1 - - metadata { - name = var.namespace - } -} - -locals { - ns = try(kubernetes_namespace.ns[0].metadata[0].name, data.kubernetes_namespace.existing_ns[0].metadata[0].name) -} resource "helm_release" "prometheus" { depends_on = [ @@ -46,7 +35,7 @@ resource "helm_release" "prometheus" { ] chart = "prometheus" name = "prometheus" - namespace = local.ns + namespace = kubernetes_namespace.ns[0].metadata[0].name version = var.prometheus_chart_version repository = "https://prometheus-community.github.io/helm-charts" diff --git a/variables.tf b/variables.tf index 37bba80..483b268 100644 --- a/variables.tf +++ b/variables.tf @@ -15,18 +15,18 @@ variable "namespace" { default = "prometheus" } -variable "create_namespace" { - description = "Indicates whether the `namespace` needs to be created ('true') or already exists (not `true`)" - type = bool - default = true -} +# variable "create_namespace" { +# description = "Indicates whether the `namespace` needs to be created ('true') or already exists (not `true`)" +# type = bool +# default = true +# } # helm repo add prometheus-community https://prometheus-community.github.io/helm-charts # helm search repo prometheus-community/prometheus | head -2 variable "prometheus_chart_version" { description = "The version of prometheus to install into the cluster." type = string - default = "25.24.1" + default = "25.25.0" } # The `APP VERSION` of the output found while determining the chart version @@ -40,7 +40,7 @@ variable "prometheus_server_tag" { variable "prometheus_config_reloader_tag" { description = "The image tag of the prometheus-config-reloader image." type = string - default = "v0.75.1" + default = "v0.75.2" } # The `APP VERSION` of the output: From 23451d9e9cce6c69b792654bf3e9944a73cca477 Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Tue, 6 Aug 2024 22:01:35 -0400 Subject: [PATCH 4/8] lints --- main.tf | 10 +++++----- outputs.tf | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/main.tf b/main.tf index 6f63a0e..a28532c 100644 --- a/main.tf +++ b/main.tf @@ -1,20 +1,20 @@ locals { - alertmanager_internal_hostname = format("prometheus-alertmanager.%v.svc.cluster.local", local.ns) + alertmanager_internal_hostname = format("prometheus-alertmanager.%v.svc.cluster.local", kubernetes_namespace.ns.metadata.name) alertmanager_internal_port_number = 9093 alertmanager_internal_url = format("http://%v:%v/", local.alertmanager_internal_hostname, local.alertmanager_internal_port_number) - headless_alertmanager_internal_hostname = format("prometheus-alertmanager-headless.%v.svc.cluster.local", local.ns) + headless_alertmanager_internal_hostname = format("prometheus-alertmanager-headless.%v.svc.cluster.local", kubernetes_namespace.ns.metadata.name) headless_alertmanager_internal_port_number = 9093 headless_alertmanager_internal_url = format("http://%v:%v/", local.alertmanager_internal_hostname, local.alertmanager_internal_port_number) # ns = try(kubernetes_namespace.ns[0].metadata[0].name, data.kubernetes_namespace.existing_ns[0].metadata[0].name) - pushgateway_internal_hostname = format("prometheus-prometheus-pushgateway.%v.svc.cluster.local", local.ns) + pushgateway_internal_hostname = format("prometheus-prometheus-pushgateway.%v.svc.cluster.local", kubernetes_namespace.ns.metadata.name) pushgateway_internal_port_number = 9091 pushgateway_internal_url = format("http://%v:%v/", local.pushgateway_internal_hostname, local.pushgateway_internal_port_number) - server_internal_hostname = format("prometheus-server.%v.svc.cluster.local", local.ns) + server_internal_hostname = format("prometheus-server.%v.svc.cluster.local", kubernetes_namespace.ns.metadata.name) server_internal_port_number = 9090 server_internal_url = format("http://%v:%v/", local.server_internal_hostname, local.server_internal_port_number) } @@ -35,7 +35,7 @@ resource "helm_release" "prometheus" { ] chart = "prometheus" name = "prometheus" - namespace = kubernetes_namespace.ns[0].metadata[0].name + namespace = kubernetes_namespace.ns.metadata.name version = var.prometheus_chart_version repository = "https://prometheus-community.github.io/helm-charts" diff --git a/outputs.tf b/outputs.tf index e047fe6..569df86 100644 --- a/outputs.tf +++ b/outputs.tf @@ -36,7 +36,7 @@ output "prometheus_server_internal_endpoint" { output "prometheus_namespace" { description = "namespace for prometheus" - value = local.ns + value = kubernetes_namespace.ns.metadata.name } ################################################################################ From a2f69300073a4f83b100e97cfa762ecee1f12e23 Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Tue, 6 Aug 2024 22:04:33 -0400 Subject: [PATCH 5/8] =?UTF-8?q?=F0=9F=9A=A8=20fix-lint(namespace[0]):=20na?= =?UTF-8?q?mespace=20refs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.tf | 13 ++++++------- outputs.tf | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/main.tf b/main.tf index a28532c..cb6ad53 100644 --- a/main.tf +++ b/main.tf @@ -1,20 +1,19 @@ - locals { - alertmanager_internal_hostname = format("prometheus-alertmanager.%v.svc.cluster.local", kubernetes_namespace.ns.metadata.name) + alertmanager_internal_hostname = format("prometheus-alertmanager.%v.svc.cluster.local", kubernetes_namespace.ns.metadata[0].name) alertmanager_internal_port_number = 9093 alertmanager_internal_url = format("http://%v:%v/", local.alertmanager_internal_hostname, local.alertmanager_internal_port_number) - headless_alertmanager_internal_hostname = format("prometheus-alertmanager-headless.%v.svc.cluster.local", kubernetes_namespace.ns.metadata.name) + headless_alertmanager_internal_hostname = format("prometheus-alertmanager-headless.%v.svc.cluster.local", kubernetes_namespace.ns.metadata[0].name) headless_alertmanager_internal_port_number = 9093 headless_alertmanager_internal_url = format("http://%v:%v/", local.alertmanager_internal_hostname, local.alertmanager_internal_port_number) - # ns = try(kubernetes_namespace.ns[0].metadata[0].name, data.kubernetes_namespace.existing_ns[0].metadata[0].name) + # ns = try(kubernetes_namespace.ns[0].metadata[0][0].name, data.kubernetes_namespace.existing_ns[0].metadata[0][0].name) - pushgateway_internal_hostname = format("prometheus-prometheus-pushgateway.%v.svc.cluster.local", kubernetes_namespace.ns.metadata.name) + pushgateway_internal_hostname = format("prometheus-prometheus-pushgateway.%v.svc.cluster.local", kubernetes_namespace.ns.metadata[0].name) pushgateway_internal_port_number = 9091 pushgateway_internal_url = format("http://%v:%v/", local.pushgateway_internal_hostname, local.pushgateway_internal_port_number) - server_internal_hostname = format("prometheus-server.%v.svc.cluster.local", kubernetes_namespace.ns.metadata.name) + server_internal_hostname = format("prometheus-server.%v.svc.cluster.local", kubernetes_namespace.ns.metadata[0].name) server_internal_port_number = 9090 server_internal_url = format("http://%v:%v/", local.server_internal_hostname, local.server_internal_port_number) } @@ -35,7 +34,7 @@ resource "helm_release" "prometheus" { ] chart = "prometheus" name = "prometheus" - namespace = kubernetes_namespace.ns.metadata.name + namespace = kubernetes_namespace.ns.metadata[0].name version = var.prometheus_chart_version repository = "https://prometheus-community.github.io/helm-charts" diff --git a/outputs.tf b/outputs.tf index 569df86..ac3c50c 100644 --- a/outputs.tf +++ b/outputs.tf @@ -36,7 +36,7 @@ output "prometheus_server_internal_endpoint" { output "prometheus_namespace" { description = "namespace for prometheus" - value = kubernetes_namespace.ns.metadata.name + value = kubernetes_namespace.ns.metadata[0].name } ################################################################################ From 9c5ce807d5cb2c593b3ec45f9fe75b29534f0165 Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Tue, 13 Aug 2024 00:11:36 -0400 Subject: [PATCH 6/8] =?UTF-8?q?=F0=9F=90=9B=20fix(main.tf):=20updates=20co?= =?UTF-8?q?nfig=20to=20fix=20crashloopbackoff?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.tf | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/main.tf b/main.tf index cb6ad53..fc17910 100644 --- a/main.tf +++ b/main.tf @@ -40,11 +40,8 @@ resource "helm_release" "prometheus" { # Global set { - name = "server.extraArgs.web.enable-remote-write-receiver" - value = "null" - # kubectl -n prometheus describe deployment prometheus-server - # Will show in the args list as: - # --web=map[enable-remote-write-receiver:] + name = "server.web.enable-remote-write-receiver" + value = "" } # Prometheus chart: From 907b7dee3ed38d4f19cd7bccaff987a9dde67983 Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Wed, 21 Aug 2024 18:28:30 -0400 Subject: [PATCH 7/8] =?UTF-8?q?=F0=9F=9A=A8=20fix-lint(main.tf):=20removed?= =?UTF-8?q?=20ns=20definition?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.tf | 3 --- 1 file changed, 3 deletions(-) diff --git a/main.tf b/main.tf index fc17910..12cdc83 100644 --- a/main.tf +++ b/main.tf @@ -7,8 +7,6 @@ locals { headless_alertmanager_internal_port_number = 9093 headless_alertmanager_internal_url = format("http://%v:%v/", local.alertmanager_internal_hostname, local.alertmanager_internal_port_number) - # ns = try(kubernetes_namespace.ns[0].metadata[0][0].name, data.kubernetes_namespace.existing_ns[0].metadata[0][0].name) - pushgateway_internal_hostname = format("prometheus-prometheus-pushgateway.%v.svc.cluster.local", kubernetes_namespace.ns.metadata[0].name) pushgateway_internal_port_number = 9091 pushgateway_internal_url = format("http://%v:%v/", local.pushgateway_internal_hostname, local.pushgateway_internal_port_number) @@ -27,7 +25,6 @@ resource "kubernetes_namespace" "ns" { } } - resource "helm_release" "prometheus" { depends_on = [ module.images, From 068a242a519ceee3f9176c2f380ed005a1c05b1c Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Wed, 21 Aug 2024 18:29:09 -0400 Subject: [PATCH 8/8] update precommit --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6bfca7a..23556c8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -38,7 +38,7 @@ repos: # Terraform Hooks - repo: https://github.com/antonbabenko/pre-commit-terraform - rev: v1.92.1 # Get the latest from: https://github.com/antonbabenko/pre-commit-terraform/releases + rev: v1.92.2 # Get the latest from: https://github.com/antonbabenko/pre-commit-terraform/releases hooks: - id: terraform_fmt args: @@ -94,6 +94,6 @@ repos: # - --hook-config=--parallelism-ci-cpu-cores=2 - repo: https://github.com/ljnsn/cz-conventional-gitmoji - rev: v0.3.2 + rev: v0.3.3 hooks: - id: conventional-gitmoji