Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: vultr terraform pipeline #4

Merged
merged 3 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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