Create VM now #45
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Create VM now | |
on: | |
workflow_dispatch: | |
inputs: | |
vm_sku: | |
description: 'Virtual Machine SKU' | |
required: true | |
default: 'g5.2xlarge' | |
max_bid: | |
description: 'Maximum spot bid amount' | |
required: true | |
default: '0.60' | |
cloud-init-template: | |
description: 'Cloud-Init template to apply' | |
required: true | |
default: 'user-data.yaml' | |
vm_username: | |
description: 'VM user name' | |
required: true | |
default: 'friend' | |
github_username: | |
description: 'Github user with ssh-key to provision' | |
required: true | |
default: '' | |
jobs: | |
create-vm-now: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Terraform fmt | |
id: fmt | |
run: | | |
docker run --platform linux/amd64 \ | |
-v $(pwd):/terraform -w /terraform \ | |
hashicorp/terraform fmt | |
continue-on-error: false | |
shell: bash | |
- name: Terraform Init | |
id: init | |
run: | | |
docker run --platform linux/amd64 \ | |
-e "AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }}" \ | |
-e "AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }}" \ | |
-v $(pwd):/terraform -w /terraform hashicorp/terraform init -upgrade | |
continue-on-error: false | |
shell: bash | |
- name: Terraform Validate | |
id: validate | |
run: | | |
docker run --platform linux/amd64 \ | |
-v $(pwd):/terraform -w /terraform \ | |
hashicorp/terraform validate -no-color | |
continue-on-error: false | |
shell: bash | |
- name: Terraform Plan | |
id: plan | |
run: | | |
docker run --platform linux/amd64 \ | |
-e "AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }}" \ | |
-e "AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }}" \ | |
-v $(pwd):/terraform -w /terraform \ | |
-var="ec2_instance_type=$VM_SKU" \ | |
-var="max_spot_price=$MAX_BID" \ | |
-var="cloud-init-template=$CLOUD_INIT" \ | |
-var="username=$VM_USERNAME" \ | |
-var="github_username=$GH_USERNAME" \ | |
hashicorp/terraform plan | |
continue-on-error: false | |
shell: bash | |
env: | |
VM_SKU: ${{ github.event.inputs.vm_sku }} | |
MAX_BID: ${{ github.event.inputs.max_bid }} | |
CLOUD_INIT: ${{ github.event.inputs.cloud-init-template }} | |
VM_USERNAME: ${{ github.event.inputs.vm_username }} | |
GH_USERNAME: ${{ github.event.inputs.github_username }} | |
AWS_ACCESS_KEY_ID: ${{ github.event.inputs.github_username }} | |
AWS_SECRET_ACCESS_KEY: ${{ github.event.inputs.github_username }} | |
- name: Terraform Apply | |
id: apply | |
run: | | |
docker run --platform linux/amd64 \ | |
-e "AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }}" \ | |
-e "AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }}" \ | |
-v $(pwd):/terraform -w /terraform \ | |
hashicorp/terraform apply \ | |
-var="ec2_instance_type=$VM_SKU" \ | |
-var="max_spot_price=$MAX_BID" \ | |
-var="cloud-init-template=$CLOUD_INIT" \ | |
-var="username=$VM_USERNAME" \ | |
-var="github_username=$GH_USERNAME" \ | |
-no-color -auto-approve -input=false | |
continue-on-error: false | |
shell: bash | |
env: | |
VM_SKU: ${{ github.event.inputs.vm_sku }} | |
MAX_BID: ${{ github.event.inputs.max_bid }} | |
CLOUD_INIT: ${{ github.event.inputs.cloud-init-template }} | |
VM_USERNAME: ${{ github.event.inputs.vm_username }} | |
GH_USERNAME: ${{ github.event.inputs.github_username }} | |
AWS_ACCESS_KEY_ID: ${{ github.event.inputs.github_username }} | |
AWS_SECRET_ACCESS_KEY: ${{ github.event.inputs.github_username }} |