From 7c5e35312c621be23fd81eedd2c80a5f652649c1 Mon Sep 17 00:00:00 2001 From: gatici Date: Mon, 12 Feb 2024 15:39:16 +0300 Subject: [PATCH] Adressing review comments Signed-off-by: gatici --- .github/workflows/terraform.yaml | 33 +++++-------------- terraform/README.md | 54 +++++++++++++++----------------- terraform/main.tf | 2 +- terraform/outputs.tf | 4 +++ terraform/variables.tf | 7 +++-- 5 files changed, 43 insertions(+), 57 deletions(-) diff --git a/.github/workflows/terraform.yaml b/.github/workflows/terraform.yaml index f161c71..9f5be9c 100644 --- a/.github/workflows/terraform.yaml +++ b/.github/workflows/terraform.yaml @@ -1,30 +1,13 @@ -name: Check the Terraform Module +# Copyright 2024 Canonical Ltd. +# See LICENSE file for licensing details. + +name: Check Terraform Module on: pull_request: - paths: - - '**.tf' jobs: - build: - name: Terraform Checks and Plans - runs-on: ubuntu-latest - steps: - - name: Checkout the repository to the runner - uses: actions/checkout@v3 - - - name: HashiCorp - Setup Terraform - uses: hashicorp/setup-terraform@v3 - - - name: Terraform Format - id: fmt - run: terraform fmt -recursive -check - continue-on-error: true - - - name: Terraform Init - id: init - run: terraform init - - - name: Terraform Validate - id: validate - run: terraform validate -no-color \ No newline at end of file + check-terraform-module: + name: Check Terraform Module + uses: canonical/observability/.github/workflows/terraform.yaml@main + secrets: inherit \ No newline at end of file diff --git a/terraform/README.md b/terraform/README.md index 63dcf93..1afe77a 100644 --- a/terraform/README.md +++ b/terraform/README.md @@ -1,24 +1,27 @@ -# Grafana-agent-k8s Terraform Module +# Grafana-agent-k8s Terraform module -This Grafana-agent-k8s Terraform module aims to deploy the [grafana-agent-k8s charm](https://charmhub.io/grafana-agent-k8s) via Terraform. +This folder contains a base [Terraform][Terraform] module for the grafana-agent-k8s charm. -## Getting Started +The module uses the [Terraform Juju provider][Terraform Juju provider] to model the charm deployment onto any Kubernetes environment managed by [Juju][Juju]. -### Prerequisites +The base module is not intended to be deployed in separation (it is possible though), but should rather serve as a building block for higher level modules. -The following software and tools needs to be installed and should be running in the local environment. Please [set up your environment](https://discourse.charmhub.io/t/set-up-your-development-environment-with-microk8s-for-juju-terraform-provider/13109) before deployment. - -- `microk8s` -- `juju 3.x` -- `terrafom` - -### Module structure +## Module structure - **main.tf** - Defines the Juju application to be deployed. - **variables.tf** - Allows customization of the deployment. Except for exposing the deployment options (Juju model name, channel or application name) also models the charm configuration. - **output.tf** - Responsible for integrating the module with other Terraform modules, primarily by defining potential integration endpoints (charm integrations), but also by exposing the application name. - **terraform.tf** - Defines the Terraform provider. +## Pre-requisites + +The following tools needs to be installed and should be running in the environment. Please [set up your environment][set-up-environment] before deployment. + +- A Kubernetes cluster +- Juju +- Juju controller bootstrapped onto the K8s cluster +- Terraform + ## Using Grafana-agent-k8s base module in higher level modules If you want to use `grafana-agent-k8s` base module as part of your Terraform module, import it like shown below. @@ -28,38 +31,33 @@ module "grafana-agent-k8s" { source = "git::https://github.com/canonical/grafana-agent-k8s-operator//terraform" model_name = "juju_model_name" - # Optional Configurations - # channel = "put the Charm channel here" - # grafana-config = { - # tls_insecure_skip_verify = "put True not to skip the TLS verification" - # } + (Customize configuration variables here if needed) } ``` -Please see the link to customize the Grafana configuration variables if needed. - -- [Grafana configuration option](https://charmhub.io/grafana-agent-k8s/configure) - Create the integrations, for instance: ```text -resource "juju_integration" "amf-metrics" { +resource "juju_integration" "prometheus-metrics" { model = var.model_name application { - name = module.amf.app_name - endpoint = module.grafana.metrics_endpoint + name = module.prometheus.app_name + endpoint = module.prometheus.metrics_endpoint } application { - name = module.grafana.app_name - endpoint = module.grafana.metrics_endpoint + name = module.grafana-agent.app_name + endpoint = module.grafana-agent.metrics_endpoint } } ``` -Please check the available [integration pairs](https://charmhub.io/grafana-agent-k8s/integrations). +The complete list of available integrations can be found [here][grafana-agent-integrations]. -[Terraform](https://www.terraform.io/) +[Terraform]: https://www.terraform.io/ +[Terraform Juju provider]: https://registry.terraform.io/providers/juju/juju/latest +[Juju]: https://juju.is +[grafana-agent-integrations]: https://charmhub.io/grafana-agent-k8s/integrations +[set-up-environment]: [https://discourse.charmhub.io/t/set-up-your-development-environment-with-microk8s-for-juju-terraform-provider/13109] -[Terraform Juju provider](https://registry.terraform.io/providers/juju/juju/latest) diff --git a/terraform/main.tf b/terraform/main.tf index 964331b..30e2f9e 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -9,7 +9,7 @@ resource "juju_application" "grafana-agent-k8s" { name = "grafana-agent-k8s" channel = var.channel } - config = var.grafana_config + config = var.config units = 1 trust = true } diff --git a/terraform/outputs.tf b/terraform/outputs.tf index 0019184..9fffe42 100644 --- a/terraform/outputs.tf +++ b/terraform/outputs.tf @@ -6,6 +6,8 @@ output "app_name" { value = juju_application.grafana-agent-k8s.name } +# Required integration endpoints + output "certificates_endpoint" { description = "Name of the endpoint to get the X.509 certificate using tls-certificates interface." value = "certificates" @@ -41,6 +43,8 @@ output "receive_ca_cert_endpoint" { value = "receive-ca-cert" } +# Provided integration endpoints + output "logging_provider_endpoint" { description = "Name of the endpoint provided by Grafana to receive logs from any charm that supports the loki_push_api relation interface." value = "logging-provider" diff --git a/terraform/variables.tf b/terraform/variables.tf index 1fb7d2c..b164f8b 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -10,7 +10,7 @@ variable "model_name" { variable "app_name" { description = "Name of the application in the Juju model" type = string - default = "grafana" + default = "grafana-agent" } variable "channel" { @@ -19,7 +19,8 @@ variable "channel" { default = "latest/stable" } -variable "grafana_config" { - description = "Additional configurations for the Grafana. Please see the available options: https://charmhub.io/grafana-agent-k8s/configure" +variable "config" { + description = "Additional configurations for the Grafana Agent. Please see the available options: https://charmhub.io/grafana-agent-k8s/configure" + type = map(string) default = {} }