diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml new file mode 100644 index 0000000..9351634 --- /dev/null +++ b/.gitea/workflows/build.yaml @@ -0,0 +1,34 @@ +name: Build + +on: + pull_request: + +jobs: + build: + runs-on: almalinux-8 + container: + image: git.query.consul/unkin/almalinux8-runnerdnd:latest + options: --privileged + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Install Terraform/Terragrunt + run: | + dnf install terraform terragrunt -y + + - name: Run Terraform Plan + run: | + make plan + + - name: Show Plans + run: | + find /workspace -type f -name "*.plan" + + #- name: Upload Artifacts + # uses: actions/upload-artifact@v3 + # with: + # name: plans + # path: /workspace/unkin/rpmbuilder/dist/*/*.rpm + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f57470d --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.terraform +.terraform.lock.hcl +environments/*/*.tf +plans diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..96e8bdb --- /dev/null +++ b/Makefile @@ -0,0 +1,26 @@ +SHELL := /bin/bash +ENVIRONMENT ?= au-syd1 +ENV_DIR = environments/$(ENVIRONMENT) +PLAN_DIR = plans +PLAN_FILE = ../../$(PLAN_DIR)/$(ENVIRONMENT).plan + +.PHONY: clean +clean: + @echo "Cleaning Terraform files..." + find environments -type f -name '*.tf' -exec rm -f "{}" \; && \ + find environments -type f -name '.terraform.lock.hcl' -exec rm -f "{}" \; && \ + find environments -type d -name '.terraform' -exec rm -rf "{}" \; && \ + rm -rf plans + +.PHONY: init +init: + terragrunt --terragrunt-working-dir $(ENV_DIR) init + +.PHONY: plan +plan: init + @mkdir -p $(PLAN_DIR) + terragrunt --terragrunt-working-dir $(ENV_DIR) plan -out=$(PLAN_FILE) + +.PHONY: apply +apply: + terragrunt --terragrunt-working-dir $(ENV_DIR) apply $(PLAN_FILE) diff --git a/environments/au-syd1/terragrunt.hcl b/environments/au-syd1/terragrunt.hcl new file mode 100644 index 0000000..8c1b5e7 --- /dev/null +++ b/environments/au-syd1/terragrunt.hcl @@ -0,0 +1,27 @@ +include "root" { + path = find_in_parent_folders("root.hcl") +} + +inputs = { + job_files = [ + "testapp1", + "testapp2", + ] + policy_files = [] +} + +generate "shared_modules" { + if_exists = "overwrite" + path = "modules.tf" + + # Dynamically include the shared/modules.tf content + contents = file("../../shared/modules.tf") +} + +generate "shared_variables" { + if_exists = "overwrite" + path = "variables.tf" + + # Dynamically include the shared/variables.tf content + contents = file("../../shared/variables.tf") +} diff --git a/environments/root.hcl b/environments/root.hcl new file mode 100644 index 0000000..444457c --- /dev/null +++ b/environments/root.hcl @@ -0,0 +1,47 @@ +locals { + vault_addr = "https://vault.service.consul:8200" + nomad_addr = "https://nomad.service.consul:4646" +} + +generate "backend" { + path = "backend.tf" + if_exists = "overwrite_terragrunt" + contents = <