From 6b335f09bcf4343a62770072adfb06456e657c21 Mon Sep 17 00:00:00 2001 From: gatici Date: Mon, 5 Feb 2024 15:35:05 +0300 Subject: [PATCH] Add the Github workflow for the Terraform checks Signed-off-by: gatici --- .github/workflows/terraform.yaml | 30 +++++++++++ terraform/CONTRIBUTING.md | 86 -------------------------------- terraform/README.md | 8 +-- terraform/terraform.tf | 2 +- terraform/terraform.tfvars | 2 +- 5 files changed, 36 insertions(+), 92 deletions(-) create mode 100644 .github/workflows/terraform.yaml delete mode 100644 terraform/CONTRIBUTING.md diff --git a/.github/workflows/terraform.yaml b/.github/workflows/terraform.yaml new file mode 100644 index 00000000..f161c712 --- /dev/null +++ b/.github/workflows/terraform.yaml @@ -0,0 +1,30 @@ +name: Check the 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 diff --git a/terraform/CONTRIBUTING.md b/terraform/CONTRIBUTING.md deleted file mode 100644 index 9a421a2f..00000000 --- a/terraform/CONTRIBUTING.md +++ /dev/null @@ -1,86 +0,0 @@ -# Contributing - -## Development environment - -### Prerequisites - -Make sure the following software and tools are installed in the development -environment. - -- `microk8s` -- `juju` -- `terraform` - -### Prepare Development Environment - -Install Microk8s: - -```console -sudo snap install microk8s --channel=1.27-strict/stable -sudo usermod -a -G snap_microk8s $USER -newgrp snap_microk8s -``` - -Enable `storage` plugin for Microk8s: - -```console -sudo microk8s enable hostpath-storage -``` - -Install Juju: - -```console -sudo snap install juju --channel=3.1/stable -``` - -Install Terraform: - -```console -sudo snap install --classic terraform -``` - -Bootstrap the Juju Controller using Microk8s: - -```console -juju bootstrap microk8s -``` - -Add a Juju model: - -```console -juju add model -```` - -### Terraform provider - -The Terraform module uses the Juju provider to provision Juju resources. Please refer to the [Juju provider documentation](https://registry.terraform.io/providers/juju/juju/latest/docs) for more information. - -A Terraform working directory needs to be initialized at the beginning. - -Initialise the provider: - -```console -terraform init -``` - -## Testing - -Terraform CLI provides various ways to do formatting and validation. - -Formats to a canonical format and style: - -```console -terraform fmt -``` - -Check the syntactical validation: - -```console -terraform validate -``` - -Preview the changes: - -```console -terraform plan -``` diff --git a/terraform/README.md b/terraform/README.md index 52f4669a..76467e2a 100644 --- a/terraform/README.md +++ b/terraform/README.md @@ -6,7 +6,7 @@ This Grafana-agent-k8s Terraform module aims to deploy the [grafana-agent-k8s ch ### Prerequisites -The following software and tools needs to be installed and should be running in the local environment. +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` @@ -41,13 +41,13 @@ Replace the values in the `terraform.tfvars` file: model_name = "put your model-name here" ``` -Run Terraform Plan by providing var-file: +Create the Terraform Plan: ```console terraform plan -var-file="terraform.tfvars" ``` -Deploy the resources, skip the approval: +Deploy the resources: ```console terraform apply -auto-approve @@ -63,7 +63,7 @@ juju status --relations ### Clean Up -Remove the application: +Destroy the deployment: ```console terraform destroy -auto-approve diff --git a/terraform/terraform.tf b/terraform/terraform.tf index 545a7bb5..4f60bb46 100644 --- a/terraform/terraform.tf +++ b/terraform/terraform.tf @@ -1,4 +1,4 @@ -# Copyright 2023 Canonical Ltd. +# Copyright 2024 Canonical Ltd. # See LICENSE file for licensing details. terraform { diff --git a/terraform/terraform.tfvars b/terraform/terraform.tfvars index c825ef1c..ce13cb66 100644 --- a/terraform/terraform.tfvars +++ b/terraform/terraform.tfvars @@ -2,7 +2,7 @@ model_name = "put your model-name here" # Optional Configuration -channel = "put the charm channel here" +channel = "put the Charm channel here" metrics_remote_write_offer_url = "Put the URL here" logging_offer_url = "Put the URL here" grafana-config = {