Skip to content

Commit

Permalink
feat: vultr terraform pipeline (#4)
Browse files Browse the repository at this point in the history
* ci: create reusable workflow for tf-setup

* ci: terraform check and plan

* ci: terraform apply
  • Loading branch information
levisingularity authored Nov 8, 2023
1 parent fb477ed commit ec654b0
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 2 deletions.
28 changes: 28 additions & 0 deletions .github/reusable-workflows/tf-setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Terraform Setup

on:
workflow_call:
inputs:
tf-version:
description: Terraform version
required: true
type: number
tf-secret:
description: Terraform secret file content
required: true
type: string

jobs:
terraform-setup:
runs-on: ubuntu-latest
steps:
- name: Setup Terrafrom
uses: hashicorp/setup-terraform@v2
with:
terraform_version: ${{ inputs.tf-version }}

- name: Create Secret File
run: echo ${{ inputs.tf-secret }} > secret.tf

- name: Terraform Init
run: terraform init
31 changes: 31 additions & 0 deletions .github/workflows/tf-apply.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Terraform Apply Workflow

on:
workflow_dispatch:
inputs:

env:
TF_SECRET_FILE: ${{ secrets.TF_SECRET_FILE }}
TF_VERSION: 1.6.3
TF_PLAN_NAME: tfplan

jobs:
apply:
name: Terraform Apply
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Download Plan Artifact
run: s3 cp s3://${{ secrets.AWS_S3_BUCKET }}/das-pre-infra-vultr/${{ env.TF_PLAN_NAME }}-latest ${{ env.TF_PLAN_NAME }}

- name: Setup Terraform
uses: ./.github/reusable-workflows/tf-setup.yml
with:
tf-version: ${{ env.TF_VERSION }}
tf-secret: ${{ env.TF_SECRET_FILE }}

# TODO: check if file exists fist
- name: Apply Changes To The Cloud
run: terraform apply tfplan
61 changes: 61 additions & 0 deletions .github/workflows/tf-plan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Terraform Plan Workflow

on:
workflow_dispatch:
inputs:

env:
TF_SECRET_FILE: ${{ secrets.TF_SECRET_FILE }}
TF_VERSION: 1.6.3
TF_PLAN_NAME: tfplan

AWS_S3_BUCKET: das.singularitynet.io
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}

jobs:
- name: Setup AWS
run: |-
pip3 install awscli
aws configure set aws_access_key_id ${{ env.AWS_ACCESS_KEY_ID }}
aws configure set aws_secret_access_key ${{ env.AWS_SECRET_ACCESS_KEY }}
aws configure set region ${{ env.AWS_REGION }}
validate:
name: Validate Terraform Code
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Terraform
uses: ./.github/reusable-workflows/tf-setup.yml
with:
tf-version: ${{ env.TF_VERSION }}
tf-secret: ${{ env.TF_SECRET_FILE }}

- name: Check Configuration Files Format
run: terraform fmt -check -diff -recursive .

- name: Validate Configuration
run: terraform validate

plan:
name: Terrafrom Plan
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Terraform
uses: ./.github/reusable-workflows/tf-setup.yml
with:
tf-version: ${{ env.TF_VERSION }}
tf-secret: ${{ env.TF_SECRET_FILE }}

- name: Create Infrastructure Plan
run: terraform plan -var-file=config.tfvars -out ${{ env.TF_PLAN_NAME }}

- name: Upload Plan Artifact
run: s3 cp ${{ env.TF_PLAN_NAME }} s3://${{ secrets.AWS_S3_BUCKET }}/das-pre-infra-vultr/${{ env.TF_PLAN_NAME }}-latest
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Version Tagging
name: Version

on:
workflow_dispatch:
inputs:
version:
description: "Version to tag"
description: "Version"
required: true

jobs:
Expand Down

0 comments on commit ec654b0

Please sign in to comment.