diff --git a/.github/workflows/terraform.yaml b/.github/workflows/terraform.yaml new file mode 100644 index 0000000..f161c71 --- /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 9a421a2..0000000 --- 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 52f4669..1e5697c 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` @@ -23,7 +23,7 @@ sudo microk8s enable hostpath-storage Add a Juju model: ```console -juju add model +juju add-model ``` Initialise the provider: @@ -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 545a7bb..4f60bb4 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 c825ef1..938b7bf 100644 --- a/terraform/terraform.tfvars +++ b/terraform/terraform.tfvars @@ -1,10 +1,10 @@ # Mandatory Config Options model_name = "put your model-name here" -# Optional Configuration -channel = "put the charm channel here" -metrics_remote_write_offer_url = "Put the URL here" -logging_offer_url = "Put the URL here" -grafana-config = { - tls_insecure_skip_verify = "put True not to skip the TLS verification" -} \ No newline at end of file +# Optional Configuration. +# channel = "put the Charm channel here" +# metrics_remote_write_offer_url = "Put the URL here" +# logging_offer_url = "Put the URL here" +# grafana-config = { +# tls_insecure_skip_verify = "put True not to skip the TLS verification" +# } \ No newline at end of file