name: Deploy Lambda (Terraform) on: workflow_call: inputs: lambda_name: required: true type: string lambda_path: required: true type: string stage: required: true type: string ecr_repo: required: true type: string image_digest: required: true type: string secrets: AWS_ACCESS_KEY_ID: required: true AWS_SECRET_ACCESS_KEY: required: true AWS_REGION: required: true jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Debug inputs run: | echo "lambda_name=${{ inputs.lambda_name }}" echo "lambda_path=${{ inputs.lambda_path }}" echo "stage=${{ inputs.stage }}" echo "ecr_repo_url=${{ inputs.ecr_repo_url }}" echo "image_digest=${{ inputs.image_digest }}" - uses: aws-actions/configure-aws-credentials@v4 with: aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} aws-region: ${{ secrets.AWS_REGION }} - uses: hashicorp/setup-terraform@v3 - uses: aws-actions/amazon-ecr-login@v2 - name: Resolve ECR repo URL id: repo env: AWS_REGION: ${{ secrets.AWS_REGION }} run: | AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text) ECR_REPO_URL="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${{ inputs.ecr_repo }}" echo "ecr_repo_url=$ECR_REPO_URL" >> "$GITHUB_OUTPUT" - name: Terraform Init working-directory: ${{ inputs.lambda_path }} run: terraform init -reconfigure - name: Terraform Workspace working-directory: ${{ inputs.lambda_path }} run: | terraform workspace select ${{ inputs.stage }} \ || terraform workspace new ${{ inputs.stage }} - name: Terraform Plan working-directory: ${{ inputs.lambda_path }} run: | terraform plan \ -var="stage=${{ inputs.stage }}" \ -var="lambda_name=${{ inputs.lambda_name }}" \ -var="ecr_repo_url=${{ steps.repo.outputs.ecr_repo_url }}" \ -var="image_digest=${{ inputs.image_digest }}" \ -out=lambdaplan - name: Wait for Approval uses: trstringer/manual-approval@v1 with: secret: ${{ secrets.GITHUB_TOKEN }} approvers: developers issue-title: "Click to approve Terraform Apply for ${{ inputs.lambda_name }} (${{ inputs.stage }})" issue-body: "Press approve to proceed with Terraform Apply" - name: Terraform Apply working-directory: ${{ inputs.lambda_path }} run: terraform apply -auto-approve lambdaplan