From b1c43cce4311c19bddb3ff737272f4da74148b2c Mon Sep 17 00:00:00 2001 From: hermann90 Date: Tue, 5 Nov 2024 22:46:52 +0100 Subject: [PATCH] test commit --- .github/workflows/deploy.yml | 92 ++++++++++++++++++++++++++++++++---- 1 file changed, 83 insertions(+), 9 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 1b87316..ea0ddcc 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,3 +1,52 @@ +name: Deploy Static Website + +on: + push: + branches: + - main + #workflow_dispatch: # Permet de déclencher manuellement pour le destroy + +jobs: + deploy: + runs-on: ubuntu-latest + if: ${{ github.event_name == 'push' }} # Exécute ce job uniquement sur les pushs, pas sur les dispatch manuels + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Terraform + uses: hashicorp/setup-terraform@v3 + with: + terraform_version: 1.9.8 + + - name: Install AWS CLI + uses: unfor19/install-aws-cli-action@v1 + with: + version: 2 + verbose: false + arch: amd64 + + - name: Terraform Init + run: terraform init + + - name: Terraform Apply + run: terraform apply -auto-approve + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_REGION: us-west-2 + + - name: Output website URL + run: echo "Website URL is $(terraform output INFO)" + + - name: Cache Terraform State # Enregistre l'état entre les jobs apply et destroy + uses: actions/cache@v4 + with: + path: .terraform + key: ${{ runner.os }}-terraform-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-terraform- on: workflow_dispatch: inputs: @@ -19,15 +68,40 @@ on: type: environment required: true -jobs: - log-the-inputs: + destroy: runs-on: ubuntu-latest + #if: ${{ github.event_name == 'workflow_dispatch' }} # S'exécute uniquement en cas de déclenchement manuel + if: github.event_name == 'workflow_dispatch' steps: - - run: | - echo "Log level: $LEVEL" - echo "Tags: $TAGS" - echo "Environment: $ENVIRONMENT" + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Terraform + uses: hashicorp/setup-terraform@v3 + with: + terraform_version: 1.9.8 + + - name: Restore Terraform State # Restaure l'état sauvegardé + uses: actions/cache@v4 + with: + path: .terraform + key: ${{ runner.os }}-terraform-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-terraform- + + - name: Terraform Init + run: terraform init + + - name: Install AWS CLI + uses: unfor19/install-aws-cli-action@v1 + with: + version: 2 + verbose: false + arch: amd64 + + - name: Terraform Destroy + run: terraform destroy -auto-approve env: - LEVEL: ${{ inputs.logLevel }} - TAGS: ${{ inputs.tags }} - ENVIRONMENT: ${{ inputs.environment }} \ No newline at end of file + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_REGION: us-west-2