From 103adec167c56eb8fc9a60a8dfa2c675c6dd35f3 Mon Sep 17 00:00:00 2001 From: Samyak Rout Date: Sun, 17 Nov 2024 21:48:42 +1100 Subject: [PATCH] Test the generate the visualiser architecture. --- .../manual: Generate-TF-Plan-Diagram.yaml | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 .github/workflows/manual: Generate-TF-Plan-Diagram.yaml diff --git a/.github/workflows/manual: Generate-TF-Plan-Diagram.yaml b/.github/workflows/manual: Generate-TF-Plan-Diagram.yaml new file mode 100644 index 0000000..3fb127e --- /dev/null +++ b/.github/workflows/manual: Generate-TF-Plan-Diagram.yaml @@ -0,0 +1,86 @@ +# Description: This workflow is used to build the infrastructure for the Dashboard Service +name: Generate Terraform Plan Diagram + +on: + workflow_dispatch: # Allow manual trigger + push: + branches: + - main + - "feature/**" # Include feature branches for init and plan only + - "bugfix/**" + - "hotfix/**" + pull_request: + branches: + - main # Validate PRs to main with init and plan + +jobs: + terraform: + runs-on: ubuntu-latest + + steps: + # Step 1: Check out the repository + - name: Checkout Repository + uses: actions/checkout@v3 + + # Step 2: Set up HashiCorp Terraform + - name: Set up Terraform + uses: hashicorp/setup-terraform@v2 + with: + terraform_wrapper: false + + # Step 3: Set up Azure CLI for authentication + - name: Azure Login + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + # Step 4: Set up Azure Storage Backend if it doesn't already exist + - name: Set Up Azure Storage Backend for Terraform State + id: setup_azure_storage + run: | + if ! az group show --name "dashboard-state-rg" &>/dev/null; then + echo "Creating resource group: dashboard-state-rg" + az group create --name "dashboard-state-rg" --location "eastus" + fi + + if ! az storage account show --name "dashboardstatestg" --resource-group "dashboard-state-rg" &>/dev/null; then + echo "Creating storage account: dashboardstatestg" + az storage account create --name "dashboardstatestg" --resource-group "dashboard-state-rg" --location "eastus" --sku Standard_LRS + fi + + AZURE_STORAGE_KEY=$(az storage account keys list --resource-group "dashboard-state-rg" --account-name "dashboardstatestg" --query "[0].value" --output tsv) + echo "::set-output name=AZURE_STORAGE_KEY::$AZURE_STORAGE_KEY" + + if ! az storage container show --name "dashboard-tfstate" --account-name "dashboardstatestg" --account-key "$AZURE_STORAGE_KEY" &>/dev/null; then + echo "Creating blob container: dashboard-tfstate" + az storage container create --name "dashboard-tfstate" --account-name "dashboardstatestg" --account-key "$AZURE_STORAGE_KEY" + fi + + az vm image terms accept --publisher openvpn --offer openvpnas --plan openvpnas --subscription ${{ secrets.ARM_SUBSCRIPTION_ID }} || true + az vm image terms show --publisher openvpn --offer openvpnas --plan openvpnas --subscription ${{ secrets.ARM_SUBSCRIPTION_ID }} || true + + # Step 5: Initialize Terraform with remote backend configuration + - name: Terraform Init + run: terraform init -input=false -backend-config="storage_account_name=dashboardstatestg" -backend-config="container_name=dashboard-tfstate" -backend-config="key=terraform.tfstate" -backend-config="access_key=${{ steps.setup_azure_storage.outputs.AZURE_STORAGE_KEY }}" + working-directory: infra_env_dashboard/infra-automation + env: + TF_VAR_client_id: ${{ secrets.ARM_CLIENT_ID }} + TF_VAR_client_secret: ${{ secrets.ARM_CLIENT_SECRET }} + TF_VAR_subscription_id: ${{ secrets.ARM_SUBSCRIPTION_ID }} + TF_VAR_tenant_id: ${{ secrets.ARM_TENANT_ID }} + + # Step 6: Terraform Plan (Run on all branches) + - name: Terraform Plan + run: + terraform plan -input=false -lock=true -refresh=true -out /tmp/plan.out + terraform show -json /tmp/plan.out > plan.json + docker run --rm -it -p 9000:9000 -v /tmp/plan.json:/src/plan.json im2nguyen/rover:latest -planJSONPath=plan.json + working-directory: infra_env_dashboard/infra-automation + env: + TF_VAR_client_id: ${{ secrets.ARM_CLIENT_ID }} + TF_VAR_client_secret: ${{ secrets.ARM_CLIENT_SECRET }} + TF_VAR_subscription_id: ${{ secrets.ARM_SUBSCRIPTION_ID }} + TF_VAR_tenant_id: ${{ secrets.ARM_TENANT_ID }} + TF_VAR_admin_password: ${{ secrets.ADMIN_PASSWORD }} + TF_VAR_vm_admin_password: ${{ secrets.ADMIN_PASSWORD }} + TF_VAR_resource_group_name: "dashboard-service-rg" \ No newline at end of file