Update demoterraform.yml #30
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: 'Terraform Deploy to AWS with Security Scanning' | |
on: | |
push: | |
branches: | |
- main # Set to the branch that triggers the deployment. | |
jobs: | |
terraform: | |
name: 'Terraform' | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: terraform | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up Terraform | |
uses: hashicorp/setup-terraform@v1 | |
- name: Set up AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: us-east-1 # Replace with your AWS region | |
- name: Create Private Key File | |
run: | | |
echo "${{ secrets.CICD_PRIVATE_KEY_BASE64 }}" | base64 --decode > ${{ github.workspace }}/terraform/CICDKey.pem | |
- name: Terraform Initialize | |
run: terraform init | |
- name: Terraform Format and Write Changes | |
run: terraform fmt -recursive | |
- name: Commit any format changes | |
uses: EndBug/add-and-commit@v7 | |
with: | |
message: 'Apply Terraform formatting changes' | |
add: '*.tf' | |
- name: Terraform Plan | |
run: terraform plan | |
- name: Terraform Apply | |
run: terraform apply -auto-approve | |
- name: Terrascan Security Scan | |
run: terrascan scan -d . |