-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test the generate the visualiser architecture.
- Loading branch information
Samyak Rout
committed
Nov 17, 2024
1 parent
ea90fca
commit 103adec
Showing
1 changed file
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |