Skip to content

Commit

Permalink
Adressing review comments
Browse files Browse the repository at this point in the history
Signed-off-by: gatici <[email protected]>
  • Loading branch information
gatici committed Feb 12, 2024
1 parent 487c323 commit 1954f0a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 57 deletions.
32 changes: 7 additions & 25 deletions .github/workflows/terraform.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,12 @@
name: Check the Terraform Module
name: Check Terraform Module

on:
pull_request:
paths:
- '**.tf'
branches:
- main

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
check-terraform-module:
name: Check Terraform Module
uses: canonical/observability/.github/workflows/terraform.yaml@main
secrets: inherit
54 changes: 26 additions & 28 deletions terraform/README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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)
2 changes: 1 addition & 1 deletion terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions terraform/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
7 changes: 4 additions & 3 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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 = {}
}

0 comments on commit 1954f0a

Please sign in to comment.