Terraform Infrastructure #14
This file contains hidden or 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 Infrastructure | |
| on: | |
| workflow_dispatch: | |
| workflow_call: | |
| inputs: | |
| terraform-action: | |
| description: 'Terraform action to perform (plan/apply/destroy)' | |
| required: false | |
| default: 'apply' | |
| type: string | |
| outputs: | |
| terraform-result: | |
| description: "Terraform execution result" | |
| value: ${{ jobs.terraform.outputs.result }} | |
| jobs: | |
| terraform: | |
| name: Terraform Deployment | |
| runs-on: ubuntu-latest | |
| environment: production | |
| outputs: | |
| result: ${{ steps.terraform-apply.outcome }} | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v5 | |
| - name: Login to AWS | |
| uses: aws-actions/[email protected] | |
| 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 Terraform | |
| uses: hashicorp/[email protected] | |
| with: | |
| terraform_version: 1.5.7 | |
| - name: Terraform Init | |
| run: terraform init | |
| working-directory: ./Terraform | |
| - name: Terraform Plan | |
| run: terraform plan | |
| working-directory: ./Terraform | |
| - name: Terraform Apply | |
| id: terraform-apply | |
| if: ${{ inputs.terraform-action == 'apply' || inputs.terraform-action == '' }} | |
| run: terraform apply -auto-approve | |
| working-directory: ./Terraform | |
| # --------------------------- | |
| # Install ArgoCD with Helm | |
| # --------------------------- | |
| - name: Update kubeconfig | |
| if: ${{ inputs.terraform-action == 'apply' || inputs.terraform-action == '' }} | |
| run: | | |
| aws eks update-kubeconfig --name otel-cluster --region us-east-1 | |
| - name: Install Helm | |
| if: ${{ inputs.terraform-action == 'apply' || inputs.terraform-action == '' }} | |
| uses: azure/[email protected] | |
| with: | |
| version: v3.14.0 | |
| - name: Add ArgoCD Helm Repo | |
| if: ${{ inputs.terraform-action == 'apply' || inputs.terraform-action == '' }} | |
| run: | | |
| helm repo add argo https://argoproj.github.io/argo-helm | |
| helm repo update | |
| - name: Install/Upgrade ArgoCD | |
| if: ${{ inputs.terraform-action == 'apply' || inputs.terraform-action == '' }} | |
| run: | | |
| helm upgrade --install argocd argo/argo-cd \ | |
| --namespace argocd \ | |
| --create-namespace \ | |
| --version 6.7.2 \ | |
| --wait | |
| # --------------------------- | |
| # Get ArgoCD Server URL | |
| # --------------------------- | |
| - name: Get ArgoCD URL | |
| if: ${{ inputs.terraform-action == 'apply' || inputs.terraform-action == '' }} | |
| run: | | |
| echo "Waiting for ArgoCD LoadBalancer..." | |
| kubectl wait --for=condition=available deployment/argocd-server -n argocd --timeout=300s || true | |
| ARGOCD_URL=$(kubectl get svc argocd-server -n argocd -o jsonpath='{.status.loadBalancer.ingress[0].hostname}') | |
| if [ -z "$ARGOCD_URL" ]; then | |
| ARGOCD_URL=$(kubectl get svc argocd-server -n argocd -o jsonpath='{.status.loadBalancer.ingress[0].ip}') | |
| fi | |
| echo "ArgoCD URL: http://$ARGOCD_URL" |