diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 83afe7018..01fa9e4be 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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='=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 diff --git a/.gitignore b/.gitignore index 5460d3af7..b42f19aea 100644 --- a/.gitignore +++ b/.gitignore @@ -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 - diff --git a/terraform/tests/preamble.tf b/terraform/tests/preamble.tf new file mode 100644 index 000000000..ec1d964ce --- /dev/null +++ b/terraform/tests/preamble.tf @@ -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 + } + +} + diff --git a/terraform/tests/providers.tf b/terraform/tests/providers.tf new file mode 100644 index 000000000..3be3d8566 --- /dev/null +++ b/terraform/tests/providers.tf @@ -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" + } + } +} diff --git a/terraform/tests/simple_deployment.tf b/terraform/tests/simple_deployment.tf new file mode 100644 index 000000000..fff1e98a1 --- /dev/null +++ b/terraform/tests/simple_deployment.tf @@ -0,0 +1,19 @@ +module "mongodb" { + source = "../" + app_name = var.app_name + juju_model_name = var.juju_model_name + units = var.simple_mongodb_units + config = { + profile = "testing" + } + + channel = "6/edge" + +} + +resource "null_resource" "simple_deployment_juju_wait_deployment" { + provisioner "local-exec" { + command = <<-EOT + EOT + } +} diff --git a/terraform/tests/variables.tf b/terraform/tests/variables.tf new file mode 100644 index 000000000..17c3af34a --- /dev/null +++ b/terraform/tests/variables.tf @@ -0,0 +1,16 @@ +variable "juju_model_name" { + description = "Model name" + type = string +} + +variable "app_name" { + description = "mongodb app name" + type = string + default = "mongodb" +} + +variable "simple_mongodb_units" { + description = "Node count" + type = number + default = 1 +}