-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds the typical workflow for Packer / TF to compare
Signed-off-by: Mo Figueroa <[email protected]>
- Loading branch information
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
CICD/Packer_triggers_Terraform/Typical_Packer_TF_Workflow.yml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
name: Typical Packerr and Terraform Workflow | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
|
||
jobs: | ||
|
||
build: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
ami_id: ${{ steps.extract.outputs.ami_id }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Configure AWS Credentials | ||
uses: aws-actions/configure-aws-credentials@v2 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: us-east-1 | ||
- name: Setup HashiCorp Packer | ||
uses: hashicorp/[email protected] | ||
- name: Packer Init | ||
run: packer init . | ||
- name: Build AMI | ||
run: packer build . | ||
- id: extract | ||
name: Extract AMI ID | ||
run: | | ||
ami_id=$(jq -r '.builds[0].artifact_id|split(":")[1]' ./manifest.json) | ||
echo "ami_id=$ami_id" >> "$GITHUB_OUTPUT" | ||
deploy: | ||
runs-on: ubuntu-latest | ||
needs: [ build ] | ||
environment: | ||
name: production | ||
url: ${{ steps.terraform.outputs.url }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Configure AWS Credentials | ||
uses: aws-actions/configure-aws-credentials@v2 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: us-east-1 | ||
- name: Terraform Init | ||
working-directory: terraform | ||
run: terraform init | ||
- name: Terraform Plan | ||
working-directory: terraform | ||
run: terraform plan -no-color -var="ami_id=${{ needs.build.outputs.ami_id }}" | ||
- name: Terraform Apply | ||
if: github.ref == 'refs/heads/main' && github.event_name == 'push' | ||
working-directory: terraform | ||
run: terraform apply -auto-approve -var="ami_id=${{ needs.build.outputs.ami_id }}" | ||
- id: terraform | ||
name: Output URL to GitHub | ||
run: echo "url=$(terraform output -raw url)" >> "$GITHUB_OUTPUT" |