Skip to content

Commit

Permalink
terraform tests + infra
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaAltieri committed Dec 4, 2024
1 parent 3778b22 commit c72bd98
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 2 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,54 @@ jobs:
- name: Run tests
run: tox run -e unit

terraform-test:
name: Terraform - Lint and Simple Deployment
runs-on: ubuntu-latest
timeout-minutes: 120
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: lint charm module
run: |
pushd ./terraform
terraform init
terraform fmt
terraform validate
pushd ./tests
terraform init
terraform fmt
terraform validate
popd
popd
- name: run checks - prepare
run: |
sudo snap install juju --channel=3.6/beta --classic
sudo snap install juju-wait --channel=latest/stable --classic
sudo snap install jq
- name: LXD setup
run: |
sudo snap refresh lxd --channel=latest/stable
sudo adduser "$USER" 'lxd'
# `newgrp` does not work in GitHub Actions; use `sg` instead
sg 'lxd' -c "lxd waitready"
sg 'lxd' -c "lxd init --auto"
sg 'lxd' -c "lxc network set lxdbr0 ipv6.address none"
sudo iptables -F FORWARD
sudo iptables -P FORWARD ACCEPT
- name: Juju setup
run: |
sg 'lxd' -c "juju bootstrap 'localhost' --config model-logs-size=10G"
juju model-defaults logging-config='<root>=INFO; unit=DEBUG'
juju add-model test
- name: Terraform deploy
run: |
pushd ./terraform/tests/
TF_VAR_model_name="test" terraform apply -target null_resource.simple_deployment_juju_wait_deployment -auto-approve
popd
lib-check:
name: Check libraries
runs-on: ubuntu-latest
Expand Down
48 changes: 46 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,52 @@ override.tf.json
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*

# Ignore CLI configuration files


########################################################
#
# Terraform .gitignore
#
########################################################


# Local .terraform directories
**/.terraform/*
*.terraform.lock.hcl

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log
crash.*.log

# Generated files
*.key
credentials*

# 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
.terraform.lock.hcl

10 changes: 10 additions & 0 deletions terraform/tests/preamble.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
resource "null_resource" "preamble" {
provisioner "local-exec" {
command = <<-EOT
sudo snap install juju-wait --classic || true
sudo sysctl -w vm.max_map_count=262144 vm.swappiness=0 net.ipv4.tcp_retries2=5
EOT
}

}

16 changes: 16 additions & 0 deletions terraform/tests/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
terraform {
required_providers {
juju = {
source = "juju/juju"
version = "~> 0.14.0"
}
http = {
source = "hashicorp/http"
version = "~> 3.4.5"
}
external = {
source = "hashicorp/external"
version = "~> 2.3.4"
}
}
}
20 changes: 20 additions & 0 deletions terraform/tests/simple_deployment.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module "mongob" {
source = "../"
app_name = var.app_name
model = var.juju_model_name
units = var.simple_mongob_units
config = {
profile = "testing"
}

channel = "6/edge"

}

resource "null_resource" "simple_deployment_juju_wait_deployment" {
provisioner "local-exec" {
command = <<-EOT
juju-wait -v --model ${var.juju_model_name}
EOT
}
}
16 changes: 16 additions & 0 deletions terraform/tests/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
variable "juju_model_name" {
description = "Model name"
type = string
}

variable "app_name" {
description = "mongob app name"
type = string
default = "mongob"
}

variable "simple_mongob_units" {
description = "Node count"
type = number
default = 1
}

0 comments on commit c72bd98

Please sign in to comment.