Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3fe7ea4c36 |
@@ -7,14 +7,20 @@ jobs:
|
||||
build:
|
||||
runs-on: almalinux-8
|
||||
container:
|
||||
image: git.query.consul/unkin/almalinux9-buildrunner:latest
|
||||
image: git.query.consul/unkin/almalinux8-runnerdnd:latest
|
||||
options: --privileged
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install Packages
|
||||
run: |
|
||||
dnf install terraform terragrunt vault jq -y
|
||||
|
||||
- name: Run Terraform Plan
|
||||
env:
|
||||
VAULT_ROLEID: ${{ secrets.TERRAFORM_NOMAD_VAULT_ROLEID }}
|
||||
run: |
|
||||
make plan
|
||||
|
||||
@@ -22,9 +28,9 @@ jobs:
|
||||
run: |
|
||||
find /workspace -type f -name "*.plan"
|
||||
|
||||
#- name: Upload Artifacts
|
||||
# uses: actions/upload-artifact@v3
|
||||
# with:
|
||||
# name: plans
|
||||
# path: /workspace/unkin/rpmbuilder/dist/*/*.rpm
|
||||
- name: Upload Artifacts
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: plans
|
||||
path: /workspace/unkin/terraform-nomad/plans/*.plan
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
name: Deploy
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows:
|
||||
- Build
|
||||
types:
|
||||
- completed
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
if: ${{ github.event.workflow_run.conclusion == 'success' }}
|
||||
runs-on: almalinux-8
|
||||
container:
|
||||
image: git.query.consul/unkin/almalinux8-runnerdnd:latest
|
||||
options: --privileged
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Download Build Artifacts
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: plans
|
||||
path: /workspace/unkin/terraform-nomad/plans
|
||||
|
||||
- name: Install Packages
|
||||
run: |
|
||||
dnf install terraform terragrunt vault jq -y
|
||||
|
||||
- name: Run Terraform Apply
|
||||
env:
|
||||
VAULT_ROLEID: ${{ secrets.TERRAFORM_NOMAD_VAULT_ROLEID }}
|
||||
run: |
|
||||
make apply
|
||||
@@ -2,3 +2,5 @@
|
||||
.terraform.lock.hcl
|
||||
environments/*/*.tf
|
||||
plans
|
||||
.venv
|
||||
env
|
||||
|
||||
@@ -4,7 +4,14 @@ ENV_DIR = environments/$(ENVIRONMENT)
|
||||
PLAN_DIR = plans
|
||||
PLAN_FILE = ../../$(PLAN_DIR)/$(ENVIRONMENT).plan
|
||||
|
||||
.PHONY: clean
|
||||
.PHONY: clean init plan apply
|
||||
|
||||
define vault_env
|
||||
@export VAULT_ADDR="https://vault.service.consul:8200" && \
|
||||
export VAULT_TOKEN=$$(vault write -field=token auth/approle/login role_id=$$VAULT_ROLEID) && \
|
||||
export $$(vault read -format=json kv/data/service/terraform/nomad | jq -r '.data.data | to_entries[] | "\(.key)=\(.value)"')
|
||||
endef
|
||||
|
||||
clean:
|
||||
@echo "Cleaning Terraform files..."
|
||||
find environments -type f -name '*.tf' -exec rm -f "{}" \; && \
|
||||
@@ -12,15 +19,15 @@ clean:
|
||||
find environments -type d -name '.terraform' -exec rm -rf "{}" \; && \
|
||||
rm -rf plans
|
||||
|
||||
.PHONY: init
|
||||
init:
|
||||
$(call vault_env) && \
|
||||
terragrunt --terragrunt-working-dir $(ENV_DIR) init
|
||||
|
||||
.PHONY: plan
|
||||
plan: init
|
||||
@mkdir -p $(PLAN_DIR)
|
||||
$(call vault_env) && \
|
||||
terragrunt --terragrunt-working-dir $(ENV_DIR) plan -out=$(PLAN_FILE)
|
||||
|
||||
.PHONY: apply
|
||||
apply:
|
||||
$(call vault_env) && \
|
||||
terragrunt --terragrunt-working-dir $(ENV_DIR) apply $(PLAN_FILE)
|
||||
|
||||
Reference in New Issue
Block a user