iac/.forgejo/workflows/tofu.yml

49 lines
1.2 KiB
YAML
Raw Normal View History

2024-10-12 21:08:38 -04:00
name: OpenTofu Automation
2024-10-12 16:35:50 -04:00
on:
push:
paths:
- 'terraform/**'
jobs:
2024-10-12 21:08:38 -04:00
deploy:
2024-10-12 21:11:41 -04:00
runs-on: docker
2024-10-12 21:15:36 -04:00
container:
2024-10-12 21:43:53 -04:00
image: node:22
2024-10-12 16:35:50 -04:00
steps:
2024-10-12 21:38:31 -04:00
- name: Checkout code
uses: actions/checkout@v4
2024-10-12 22:12:41 -04:00
- name: Create AWS Credentials Directory
run: mkdir -p ~/.aws
2024-10-12 22:11:31 -04:00
- name: Set AWS Credentials
run: |
echo "[default]" > ~/.aws/credentials
echo "aws_access_key_id=${{ secrets.AWS_ACCESS_KEY_ID }}" >> ~/.aws/credentials
echo "aws_secret_access_key=${{ secrets.AWS_SECRET_ACCESS_KEY }}" >> ~/.aws/credentials
2024-10-12 16:35:50 -04:00
2024-10-12 21:08:38 -04:00
- name: Setup OpenTofu
uses: https://github.com/opentofu/setup-opentofu@v1
2024-10-12 22:41:30 -04:00
with:
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
2024-10-12 21:08:38 -04:00
- name: Run OpenTofu Init
2024-10-12 22:21:52 -04:00
working-directory: ./terraform
run: tofu init
2024-10-12 16:35:50 -04:00
2024-10-12 21:08:38 -04:00
- name: Run OpenTofu Plan
id: plan
2024-10-12 22:21:52 -04:00
working-directory: ./terraform
run: tofu plan -no-color
2024-10-12 21:08:38 -04:00
- name: Display Plan Output
run: |
echo "Plan output:"
echo "${{ steps.plan.outputs.stdout }}"
- name: Apply the Plan
if: success()
2024-10-12 22:21:52 -04:00
working-directory: ./terraform
run: tofu apply -auto-approve