### Setup and Verify Ollama Source: https://github.com/patrickchugh/terravision/blob/main/docs/installation.md Commands to start the Ollama server, pull a model, and verify its running status. ```bash ollama serve ``` ```bash ollama pull llama3 ``` ```bash export OLLAMA_KEEP_ALIVE=1h ``` ```bash curl http://localhost:11434/api/tags ``` -------------------------------- ### Google Compute Instance Template for Web Servers Source: https://github.com/patrickchugh/terravision/blob/main/docs/demo-gcp.html Defines an instance template for web servers. Includes a startup script to install and start Nginx. ```hcl google_compute_instance_template.web: { advanced_machine_features = [] can_ip_forward = false description = null disk = [ { disk_encryption_key = [] source_image_encryption_key = [] source_snapshot_encryption_key = [] } ] guest_accelerator = [] instance_description = null labels = null machine_type = "e2-medium" metadata = null metadata_startup_script = "#!/bin/bash\napt-get update\napt-get install -y nginx\nsystemctl start nginx" min_cpu_platform = null name_prefix = "web-template-" network_interface = [ { access_config = [{} ] alias_ip_range = [] ipv6_access_config = [] } ] network_performance_config = [] project = "my-gcp-project" region = "us-central1" reservation_affinity = [] resource_manager_tags = null resource_policies = null service_account = [] shielded_instance_config = [] tags = [false, false] timeouts = null confidential_instance_config = [] effective_labels = {} id = "Computed (known after apply)" metadata_fingerprint = "Computed (known after apply)" name = "Computed (known after apply)" scheduling = [] self_link = "Computed (known after apply)" self_link_unique = "Computed (known after apply)" tags_fingerprint = "Computed (known after apply)" terraform_labels = {} module = "main" } ``` -------------------------------- ### Install Ollama on Linux Source: https://github.com/patrickchugh/terravision/blob/main/docs/installation.md Use the official installation script to install Ollama on Linux systems. ```bash curl -fsSL https://ollama.com/install.sh | sh ``` -------------------------------- ### Install Terraform on Ubuntu/Debian Source: https://github.com/patrickchugh/terravision/blob/main/docs/installation.md Add the HashiCorp GPG key and repository, then install Terraform on Ubuntu/Debian systems. ```bash wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list sudo apt update && sudo apt install terraform ``` -------------------------------- ### Start Ollama Server Source: https://github.com/patrickchugh/terravision/blob/main/docs/troubleshooting.md If the Ollama server is not running, start it using the 'ollama serve' command. ```bash ollama serve ``` -------------------------------- ### Install Git Hooks Source: https://github.com/patrickchugh/terravision/blob/main/docs/CONTRIBUTING.md Installs the project's git hooks using Poetry. This should be run after cloning the repository. ```bash poetry run pre-commit install ``` -------------------------------- ### Install Project Dependencies with Poetry Source: https://github.com/patrickchugh/terravision/blob/main/docs/CLAUDE.md Use 'poetry install' to set up the project's dependencies for development. This command installs packages defined in the pyproject.toml file. ```bash # Poetry installation (recommended for development) poetry install ``` -------------------------------- ### Install Graphviz Source: https://github.com/patrickchugh/terravision/blob/main/docs/troubleshooting.md Installs Graphviz on macOS, Ubuntu/Debian, or provides instructions for Windows. Verifies installation with `dot -V`. ```bash # macOS brew install graphviz # Ubuntu/Debian sudo apt-get update sudo apt-get install graphviz # Windows # Download from https://graphviz.org/download/ # Verify installation dot -V ``` -------------------------------- ### Install Graphviz on Ubuntu/Debian Source: https://github.com/patrickchugh/terravision/blob/main/docs/installation.md Install Graphviz and its Neato layout plugin on Ubuntu/Debian systems using apt. ```bash sudo apt update sudo apt install graphviz sudo apt install libgvplugin-neato-layout8 ``` -------------------------------- ### Install Project Dependencies with Pip (Legacy) Source: https://github.com/patrickchugh/terravision/blob/main/docs/CLAUDE.md Use 'pip install -r requirements.txt' for legacy installations. This method is not recommended for development. ```bash # Legacy install (global packages) pip install -r requirements.txt ``` -------------------------------- ### Clone and Run TerraVision Examples Source: https://github.com/patrickchugh/terravision/blob/main/docs/usage-guide.md Clone the TerraVision repository and navigate into the directory to run examples using the bundled test fixtures. ```bash git clone https://github.com/patrickchugh/terravision.git cd terravision ``` -------------------------------- ### Install WSL Utilities for Diagram Opening Source: https://github.com/patrickchugh/terravision/blob/main/RELEASE_NOTES.md Install the 'wslu' package on WSL to enable proper handling of diagram opening. This ensures diagrams are displayed correctly in WSL environments. ```bash sudo apt install wslu ``` -------------------------------- ### Install Terraform on macOS Source: https://github.com/patrickchugh/terravision/blob/main/docs/installation.md Add the HashiCorp tap and install Terraform using Homebrew on macOS. ```bash brew tap hashicorp/tap brew install hashicorp/terraform ``` -------------------------------- ### Verify Git Installation Source: https://github.com/patrickchugh/terravision/blob/main/docs/installation.md Confirm Git is installed by checking its version. ```bash git --version ``` -------------------------------- ### Install Terraform Source: https://github.com/patrickchugh/terravision/blob/main/docs/troubleshooting.md Installs Terraform on macOS using Homebrew or on Ubuntu/Debian using apt. Verifies installation with `terraform version`. ```bash # Verify Terraform installation terraform version # If not installed, install Terraform # macOS brew install terraform # Ubuntu/Debian wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list sudo apt update && sudo apt install terraform ``` -------------------------------- ### Install TerraVision from source with Poetry Source: https://github.com/patrickchugh/terravision/blob/main/docs/installation.md Installs TerraVision and its dependencies using Poetry after cloning the repository. This sets up a development environment for contributors. ```bash # Clone repository git clone https://github.com/patrickchugh/terravision.git cd terravision # Install dependencies in an isolated virtual environment poetry install # Activate the venv (drop the `poetry run` prefix for subsequent commands) eval $(poetry env activate) terravision --version # Or use `poetry run` for individual commands without activating poetry run terravision --version ``` -------------------------------- ### Install TerraVision in a Virtual Environment Source: https://github.com/patrickchugh/terravision/blob/main/docs/installation.md Set up and activate a Python virtual environment, then install TerraVision within it. ```bash python -m venv venv ``` ```bash source venv/bin/activate ``` ```bash pip install terravision ``` -------------------------------- ### Install TerraVision with Pip (User Install) Source: https://github.com/patrickchugh/terravision/blob/main/docs/installation.md Install TerraVision for the current user only, useful when sudo access is not available. ```bash pip install --user terravision ``` -------------------------------- ### Install and Run Terravision via pip Source: https://github.com/patrickchugh/terravision/blob/main/docs/cicd-integration.md Install Terravision using pip and then run the draw command. Ensure Python 3.10+ and Graphviz are installed as prerequisites. ```bash # Prerequisites: Python 3.10+, Graphviz, Terraform pip install terravision terravision draw --source ./infrastructure --outfile architecture --format png ``` -------------------------------- ### Install TerraVision Source: https://github.com/patrickchugh/terravision/blob/main/README.md Install TerraVision using pipx. Ensure you have Python 3.10+, Terraform 1.x, Graphviz, and Git installed. ```bash pipx install terravision # or: pip install terravision if in a virtual env ``` -------------------------------- ### Example: Hybrid Handler with 'before' Execution Order Source: https://github.com/patrickchugh/terravision/blob/main/docs/resource-handler-guide.md This example configures a hybrid handler for AWS subnets, ensuring a custom function runs first to prepare metadata needed by subsequent transformations. ```python "aws_subnet": { "handler_execution_order": "before", # Run metadata prep FIRST "additional_handler_function": "aws_prepare_subnet_az_metadata", # Copies metadata "transformations": [ {"operation": "insert_intermediate_node", ...}, # Uses prepared metadata ], } ``` -------------------------------- ### Basic Architecture with Connections Source: https://github.com/patrickchugh/terravision/blob/main/docs/annotations.md Start with a simple title and define basic connections between resources. ```yaml format: 0.1 title: "My Architecture" connect: aws_lambda_function.api: - aws_rds_cluster.db: "Queries" ``` -------------------------------- ### Complete Terravision Configuration Example Source: https://github.com/patrickchugh/terravision/blob/main/docs/annotations.md A comprehensive example demonstrating various Terravision configuration options for diagram customization, including connections, disconnections, additions, removals, updates, and flow definitions. ```yaml format: 0.2 # Main diagram title title: "E-Commerce Platform - Production" # Add connections not apparent from Terraform connect: aws_lambda_function.order_processor: - aws_rds_cluster.orders_db: "Insert orders" - aws_sqs_queue.notifications: "Send notifications" aws_ecs_service.web: - aws_elasticache_cluster.sessions: "Session cache" # Remove noisy connections disconnect: aws_cloudwatch_log_group.*: - aws_lambda_function.* - aws_ecs_service.* # Add external systems add: external_api.payment_gateway: provider: "Stripe" endpoint: "https://api.stripe.com" external_api.shipping_service: provider: "FedEx" endpoint: "https://api.fedex.com" # Remove internal resources from diagram remove: - aws_iam_role.lambda_execution - aws_iam_policy.cloudwatch_logs # Add custom labels update: aws_lambda_function.order_processor: label: "Order Processing Engine" edge_labels: - external_api.payment_gateway: "Process payment" - external_api.shipping_service: "Create shipment" aws_ecs_service.web: label: "Web Application (3 tasks)" edge_labels: - aws_alb.main: "HTTP/HTTPS traffic" aws_cloudfront_distribution.cdn: edge_labels: - aws_s3_bucket.static_assets: "Static content" - aws_alb.main: "Dynamic content" # Define numbered flow sequences (format 0.2) flows: checkout-flow: description: "Checkout Flow" steps: - resource: aws_cloudfront_distribution.cdn xlabel: "Browse" detail: "Customer browses product catalogue" - resource: aws_ecs_service.web xlabel: "Add to cart" detail: "Items added to shopping cart" - resource: aws_lambda_function.order_processor xlabel: "Place order" detail: "Order submitted for processing" - resource: "aws_lambda_function.order_processor -> aws_sqs_queue.notifications" xlabel: "Queue" detail: "Fulfilment notification queued" ``` -------------------------------- ### Example Commit Message Source: https://github.com/patrickchugh/terravision/blob/main/docs/CONTRIBUTING.md Provides an example of a descriptive commit message for new feature additions. ```text Add support for GCP Cloud Run resources - Implement Cloud Run handler in resource_handlers_gcp.py - Add Cloud Run icons to resource_classes/gcp/ - Update cloud_config_gcp.py with special resources - Add integration tests for Cloud Run ``` -------------------------------- ### Install Ollama on macOS Source: https://github.com/patrickchugh/terravision/blob/main/docs/installation.md Use Homebrew to install Ollama on macOS systems. ```bash brew install ollama ``` -------------------------------- ### Install Python 3.10+ Source: https://github.com/patrickchugh/terravision/blob/main/docs/troubleshooting.md Installs Python 3.10+ on macOS using Homebrew or Ubuntu. Installs Terravision using a specific Python version. ```bash # Check Python version python --version # Install Python 3.10+ # macOS brew install python@3.10 # Ubuntu sudo apt-get install python3.10 # Install TerraVision with a specific Python version python3.10 -m pip install terravision ``` -------------------------------- ### Install Graphviz on macOS Source: https://github.com/patrickchugh/terravision/blob/main/docs/installation.md Use Homebrew to install Graphviz on macOS systems. ```bash brew install graphviz ``` -------------------------------- ### Install Python 3.10 on Ubuntu Source: https://github.com/patrickchugh/terravision/blob/main/docs/installation.md Install Python version 3.10 using apt-get on Ubuntu systems. ```bash sudo apt-get install python3.10 ``` -------------------------------- ### Pure Config-Driven Handler Example: VPC Endpoint Source: https://github.com/patrickchugh/terravision/blob/main/docs/resource-handler-guide.md This example demonstrates a pure config-driven handler for AWS VPC endpoints, using only transformation building blocks to move endpoints and delete nodes. ```python "aws_vpc_endpoint": { "description": "Move VPC endpoints into VPC parent and delete endpoint nodes", "transformations": [ { "operation": "move_to_parent", "params": { "resource_pattern": "aws_vpc_endpoint", "from_parent_pattern": "aws_subnet", "to_parent_pattern": "aws_vpc.", }, }, { "operation": "delete_nodes", "params": { "resource_pattern": "aws_vpc_endpoint", "remove_from_parents": False, }, }, ], } ``` -------------------------------- ### List and Pull Ollama Models Source: https://github.com/patrickchugh/terravision/blob/main/docs/troubleshooting.md Verify that the configured Ollama model is installed. Use 'ollama list' to see installed models and 'ollama pull ' to download a model. ```bash ollama list ollama pull llama3 ``` -------------------------------- ### Verify Terraform Installation Source: https://github.com/patrickchugh/terravision/blob/main/docs/installation.md Check the installed Terraform version. Ensure it is v1.0.0 or higher. ```bash terraform version # Must show v1.0.0 or higher ``` -------------------------------- ### Pure Config-Driven Handler Example Source: https://github.com/patrickchugh/terravision/blob/main/docs/resource-handler-guide.md Example of a pure config-driven handler for 'aws_vpc_endpoint'. This configuration uses 'move_to_parent' and 'delete_nodes' operations for resource management. Suitable for simple, repetitive operations. ```python "aws_vpc_endpoint": { "transformations": [ {"operation": "move_to_parent", "params": {...}}, {"operation": "delete_nodes", "params": {...}}, ], } ``` -------------------------------- ### Install Poetry on Windows Source: https://github.com/patrickchugh/terravision/blob/main/docs/installation.md Installs the Poetry dependency manager using PowerShell. This is required for contributors who plan to modify TerraVision's code. ```powershell (Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py - ``` -------------------------------- ### Get Start Angle Property Source: https://github.com/patrickchugh/terravision/blob/main/docs/demo-azure.html Returns the 'startAngle' property of an object. ```javascript function Ha(t){return t.startAngle} ``` -------------------------------- ### Install Poetry on macOS/Linux Source: https://github.com/patrickchugh/terravision/blob/main/docs/installation.md Installs the Poetry dependency manager using a curl script. This is the first step for contributors who plan to modify TerraVision's code. ```bash curl -sSL https://install.python-poetry.org | python3 - ``` -------------------------------- ### Initialize Search Functionality Source: https://github.com/patrickchugh/terravision/blob/main/docs/demo-gcp.html Sets up the search input and builds a searchable list from node and cluster maps. ```javascript function initSearch() { var searchInput = document.getElementById('search-input'); var searchResults = document.getElementById('search-results'); if (!searchInput) return; // Build searchable list from node_id_map and cluster_id_map var allResources = []; var nmap = TERRAVISION_DATA.node_id_map || {}; var cmap = TERRAVISION_DATA.cluster_id_map || {}; for (var gvId in nmap) { allResources.push({ gvId: gvId, tfName: nmap[gvId], type: 'node' }); } for (var cId in cmap) { allResources.push({ gvId: cId, tfName: cmap[cId], type: 'cluster' }); } searchInput.addEventListener('inp ``` -------------------------------- ### Get Terravision Version Source: https://github.com/patrickchugh/terravision/blob/main/docs/troubleshooting.md Retrieve the installed Terravision version, which is often required for bug reports. ```bash terravision --version ``` -------------------------------- ### Verify Terravision and Dependency Installation Source: https://github.com/patrickchugh/terravision/blob/main/docs/troubleshooting.md Check if Terravision and its core dependencies like Terraform, Python, Graphviz, and Git are installed and meet the minimum version requirements. This helps ensure a correct setup. ```bash # Check all dependencies terraform version # Should be v1.0.0+ python --version # Should be 3.10+ dot -V # Should show Graphviz version git --version # Should show Git version # Test Terravision terravision --version terravision --help ``` -------------------------------- ### Handle Touch Start for Zooming Source: https://github.com/patrickchugh/terravision/blob/main/docs/demo-aws.html Initiates zoom behavior on touch start. Detects single or double taps and sets up touch identifiers for multi-touch gestures. Includes a timeout for tap detection. ```javascript function E(e,...i){if(r.apply(this,arguments)){var o,a,u,c,f=e.touches,s=f.length,l=w(this,i,e.changedTouches.length===s).event(e);for(Aw(e),a=0;a=4||0===n?Ay(t):Ay.ceil(t)} ``` -------------------------------- ### Get UTC Week of Year (ISO 8601) Source: https://github.com/patrickchugh/terravision/blob/main/docs/demo-azure.html Calculates the ISO 8601 UTC week number for a given date. Weeks start on Monday. ```javascript function b_(t){var n=t.getUTCDay();return n>=4||0===n?Oy(t):Oy.ceil(t)} ``` -------------------------------- ### Brush Interaction Start Source: https://github.com/patrickchugh/terravision/blob/main/docs/demo-azure.html Initiates brush interaction, handling mouse and touch events. It determines the brush mode (selection, scale, translate) based on modifier keys and touch events. Requires setup for event listeners. ```javascript function h(e){if((!n||e.touches)&&r.apply(this,arguments)){var i,a,u,c,l,h,d,p,g,y,v,_=this,b=e.target.__data__.type,m="selection"===(o&&e.metaKey?b="overlay":b)?ta:o&&e.altKey?ra:ea,x=t===sa?null:ga[b],w=t===fa?null:ya[b],M=xa(_),T=M.extent,A=M.selection,S=T[0][0],E=T[0][1],N=T[1][0],k=T[1][1],C=0,P=0,z=$Array.from(e.touches||[e],(t=>{const n=t.identifier;return(t=ne(t,_)).point0=t.slice(),t.identifier=n,t}));Gi(_);var D=s(_,arguments,!0).beforestart();if("overlay"===b){A&&(g=!0);const n=[$[0],$[1]||$[0]] M.selection=A=[[i=t===sa?S:aa(n[0][0],n[1][0]),u=t===fa?E:aa(n[0][1],n[1][1])],[l=t===sa?N:oa(n[0][0],n[1][0]),d=t===fa?k:oa(n[0][1],n[1][1])]] $.length>1&&I(e)}else i=A[0][0],u=A[0][1],l=A[1][0],d=A[1][1];a=i,c=u,h=l,p=d;var R=Zn(_).attr("pointer-events","none"),F=R.selectAll(".overlay").attr("cursor",ha[b]);if(e.touches)D.moved=U,D.ended=O;else{var q=Zn(e.view).on("mousemove.brush",U,!0).on("mouseup.brush",O,!0);o&&q.on("keydown.brush",(function(t){switch(t.keyCode){case 16:z=x&&w;break;case 18:m===ea&&(x&&(l=h-C*x,i=a+C*x),w&&(d=p-P*w,u=c+P*w),m=ra,I(t));break;case 32:m!==ea&&m!==ra||(x<0?l=h-C:x>0&&(i=a+C),w<0?d=p-P:w>0&&(u=c+P),m=na,F.attr("cursor",ha.selection),I(t));break;default:return}Jo(t)}),!0).on("keyup.brush",(function(t){switch(t.keyCode){case 16:z&&(y=v=z=!1,I(t));break;case 18:m===ra&&(x&&(l=h-C*x,i=a+C*x),w&&(d=p-P*w,u=c+P*w),m=ea,I(t));break;case 32:m===na&&(t.altKey?(x&&(l=h-C*x,i=a+C*x),w&&(d=p-P*w,u=c+P*w),m=ra):(x<0?l=h:x>0&&(i=a),w<0?d=p:w>0&&(u=c),m=ea),F.attr("cursor",ha[b]),I(t));break;default:return}Jo(t)}),!0),ae(e.view)}f.call(_),D.start(e,m.name)}} ``` -------------------------------- ### Initialize Modal View Source: https://github.com/patrickchugh/terravision/blob/main/docs/demo-gcp.html Sets up the modal display with item key and value. Ensures the modal is visible. ```javascript ue = function(uid) { var item = rawValues[uid]; if (!item) return; document.getElementById('modal-field-name').textContent = item.key; document.getElementById('modal-content').textContent = item.value; document.getElementById('expand-modal').style.display = 'flex'; }; ``` -------------------------------- ### Show Services to Verify Resource Names Source: https://github.com/patrickchugh/terravision/blob/main/docs/troubleshooting.md Use this command to list all available services and verify that resource names in your annotations exist. ```bash terravision graphdata --source . --show_services ``` -------------------------------- ### Install Graphviz for pip Installs Source: https://github.com/patrickchugh/terravision/blob/main/docs/cicd-integration.md Install Graphviz on Ubuntu/Debian, macOS, or Alpine systems if you are using `pip install` for TerraVision and Graphviz is not already available. This is required for diagram rendering. ```bash # Ubuntu/Debian sudo apt-get install -y graphviz ``` ```bash # macOS brew install graphviz ``` ```bash # Alpine apg add graphviz ``` -------------------------------- ### Initialize Search Functionality Source: https://github.com/patrickchugh/terravision/blob/main/modules/templates/interactive.html Sets up the search input and results display. It builds a searchable list from node and cluster ID maps. ```javascript function initSearch() { var searchInput = document.getElementById('search-input'); var searchResults = document.getElementById('search-results'); if (!searchInput) return; var allResources = []; var nmap = TERRAVISION_DATA.node_id_map || {}; var cmap = TERRAVISION_DATA.cluster_id_map || {}; for (var gvId in nmap) { allResources.push({ gvId: gvId, tfName: nmap[gvId], type: 'node' }); } for (var cId in cmap) { ``` -------------------------------- ### Check Current Infrastructure Diagram Source: https://github.com/patrickchugh/terravision/blob/main/docs/usage-guide.md Quickly view the current infrastructure diagram. No setup required. ```bash # Quick check of current infrastructure terravision draw --show ``` -------------------------------- ### Install TerraVision with pipx Source: https://github.com/patrickchugh/terravision/blob/main/docs/installation.md Installs TerraVision in an isolated environment using pipx. Ensure pipx is installed and its bin directory is on your PATH first. ```bash # Install pipx first if you don't have it # macOS: brew install pipx && pipx ensurepath # Ubuntu/Debian: sudo apt install pipx && pipx ensurepath # Windows: python -m pip install --user pipx && python -m pipx ensurepath pipx install terravision terravision --version ``` -------------------------------- ### Pure Configuration-Driven Handler Example Source: https://github.com/patrickchugh/terravision/blob/main/docs/developer-guide.md Use this pattern for simple operations where transformations can be fully defined in the configuration. It specifies a resource type and a list of transformation operations with their parameters. ```python "aws_vpc_endpoint": { "transformations": [ {"operation": "move_to_parent", "params": {...}}, {"operation": "delete_nodes", "params": {...}}, ], } ``` -------------------------------- ### Initialize Search Functionality Source: https://github.com/patrickchugh/terravision/blob/main/docs/demo-azure.html Sets up the search input and results display. It builds a searchable list from node and cluster maps, filters results based on user input, and handles clicks on search results to open the corresponding diagram element. ```javascript function initSearch() { var searchInput = document.getElementById('search-input'); var searchResults = document.getElementById('search-results'); if (!searchInput) return; // Build searchable list from node_id_map and cluster_id_map var allResources = []; var nmap = TERRAVISION_DATA.node_id_map || {}; var cmap = TERRAVISION_DATA.cluster_id_map || {}; for (var gvId in nmap) { allResources.push({ gvId: gvId, tfName: nmap[gvId], type: 'node' }); } for (var cId in cmap) { allResources.push({ gvId: cId, tfName: cmap[cId], type: 'cluster' }); } searchInput.addEventListener('input', function() { var query = this.value.toLowerCase().trim(); searchResults.innerHTML = ''; if (query.length < 2) { searchResults.style.display = 'none'; return; } var matches = allResources.filter(function(r) { return r.tfName.toLowerCase().indexOf(query) >= 0; }).slice(0, 10); if (matches.length === 0) { searchResults.style.display = 'none'; return; } searchResults.style.display = 'block'; matches.forEach(function(r) { var div = document.createElement('div'); div.className = 'search-result-item'; div.textContent = r.tfName; div.addEventListener('click', function() { searchInput.value = ''; searchResults.style.display = 'none'; // Find the SVG element and open panel var selector = r.type === 'node' ? '.node' : '.cluster'; var targetEl = null; svg.selectAll(selector).each(function() { var t = this.querySelector('title'); if (t && t.textContent.trim() === r.gvId) targetEl = this; }); if (targetEl) { addHighlight(targetEl); if (!allEdgesMode) startFlowAnimationForNode(r.gvId); openPanel(r.gvId, targetEl); } }); searchResults.appendChild(div); }); }); // Close results on outside click document.addEventListener('click', function(e) { if (!searchInput.contains(e.target) && !searchResults.contains(e.target)) { searchResults.style.display = 'none'; } }); } initSearch(); ``` -------------------------------- ### Default Start Angle Source: https://github.com/patrickchugh/terravision/blob/main/docs/demo-azure.html Returns a default start angle of 0. ```javascript function Ga(){return 0} ``` -------------------------------- ### Verify Graphviz Installation Source: https://github.com/patrickchugh/terravision/blob/main/docs/installation.md Check if Graphviz is installed and accessible by verifying its version. ```bash dot -V ``` -------------------------------- ### Initialize Terraform Source: https://github.com/patrickchugh/terravision/blob/main/docs/troubleshooting.md Ensure Terraform can initialize successfully. This step is crucial for downloading providers and setting up the backend. ```bash terraform init ``` -------------------------------- ### Start Transition Source: https://github.com/patrickchugh/terravision/blob/main/docs/demo-aws.html Initiates a transition on the selected elements. It can accept a transition object or a name, and allows specifying custom configurations. ```javascript Wn.prototype.transition=function(t){var n,e;t instanceof po?(n=t._id,t=t._name):(n=yo(),(e=Vo).time=Ai(),t=null==t?null:t+"");for(var r=this._groups,i=r.length,o=0;o1?this.each((null==n?bn:"function"==typeof n?xn:mn)(t,n)):this.node()[t]} ``` -------------------------------- ### Google Compute Instance Template for Application Servers Source: https://github.com/patrickchugh/terravision/blob/main/docs/demo-gcp.html Defines an instance template for application servers. Includes a startup script to update packages and install OpenJDK 11. ```hcl google_compute_instance_template.app: { advanced_machine_features = [] can_ip_forward = false description = null disk = [ { disk_encryption_key = [] source_image_encryption_key = [] source_snapshot_encryption_key = [] } ] guest_accelerator = [] instance_description = null labels = null machine_type = "e2-medium" metadata = null metadata_startup_script = "#!/bin/bash\napt-get update\napt-get install -y openjdk-11-jre" min_cpu_platform = null name_prefix = "app-template-" network_interface = [ { access_config = [] alias_ip_range = [] ipv6_access_config = [] } ] network_performance_config = [] project = "my-gcp-project" region = "us-central1" reservation_affinity = [] resource_manager_tags = null resource_policies = null service_account = [] shielded_instance_config = [] tags = [false, false] timeouts = null confidential_instance_config = [] effective_labels = {} id = "Computed (known after apply)" metadata_fingerprint = "Computed (known after apply)" name = "Computed (known after apply)" scheduling = [] self_link = "Computed (known after apply)" self_link_unique = "Computed (known after apply)" tags_fingerprint = "Computed (known after apply)" terraform_labels = {} module = "main" } ``` -------------------------------- ### Generate Diagram with Local AI Annotations Source: https://github.com/patrickchugh/terravision/blob/main/README.md Enable AI-powered annotations using a local LLM via Ollama. No data leaves your machine. ```bash terravision draw --source ./path-to-your-terraform --ai-annotate ollama ``` -------------------------------- ### Install Python 3.10 on macOS Source: https://github.com/patrickchugh/terravision/blob/main/docs/installation.md Install Python version 3.10 using Homebrew if an older version is detected. ```bash brew install python@3.10 ``` -------------------------------- ### Provide Required Arguments for Planfile Source: https://github.com/patrickchugh/terravision/blob/main/docs/troubleshooting.md When using `--planfile`, you must also provide `--graphfile` and `--source`. This ensures all necessary components are specified for diagram generation. ```bash terravision draw \ --planfile plan.json \ --graphfile graph.dot \ --source ./path-to-your-terraform ``` -------------------------------- ### Testing Provider Detection and Configuration Loading Source: https://github.com/patrickchugh/terravision/blob/main/docs/developer-guide.md Run these commands to test provider-specific code, including detection logic and configuration loading, ensuring changes do not break existing functionality. ```bash poetry run pytest tests/test_provider_detection.py -v poetry run pytest tests/test_config_loader.py -v poetry run pytest tests/test__resources.py -v ``` -------------------------------- ### Get or Set Datum Source: https://github.com/patrickchugh/terravision/blob/main/docs/demo-azure.html Gets the data bound to the first element in the selection, or binds data to all elements in the selection. ```javascript datum:function(t){return arguments.length?this.property("__data__",t):this.node().__data__} ``` -------------------------------- ### Install Terravision Source: https://github.com/patrickchugh/terravision/blob/main/docs/index.md Install the Terravision package using pip or pipx. This command is used for setting up the tool on your local machine. ```bash pip install terravision # or: pipx install terravision ``` -------------------------------- ### Transition interrupt and transition setup Source: https://github.com/patrickchugh/terravision/blob/main/docs/demo-azure.html Handles interrupting existing transitions and initiating new ones with customizable parameters like duration, delay, and easing. ```javascript Wn.prototype.interrupt=function(t){return this.each((function(){Gi(this,t)}))},Wn.prototype.transition=function(t){var n,e;t instanceof po?(n=t._id,t=t._name):(n=yo(),(e=Vo).time=Ai(),t=null==t?null:t+"");for(var r=this._groups,i=r.length,o=0;o()=>t ``` ```javascript function Wo(t,n){for(var e;!(e=t.__transition)||!(e=e[n]);)if(!(t=t.parentNode))throw new Error(`transition ${n} not found`);return e} ``` -------------------------------- ### Get or Set Attribute Source: https://github.com/patrickchugh/terravision/blob/main/docs/demo-azure.html Gets the value of a specified attribute for the first element in the selection, or sets the attribute for all elements. Handles namespaced attributes. ```javascript attr:function(t,n){var e=It(t);if(arguments.length<2){var r=this.node();return e.local?r.getAttributeNS(e.space,e.local):r.getAttribute(e)}return this.each((null==n?e.local?fn:cn:"function"==typeof n?e.local?dn:hn:e.local?ln:sn)(e,n))} ``` -------------------------------- ### Configure Linux Virtual Machine Backend 1 Source: https://github.com/patrickchugh/terravision/blob/main/docs/demo-azure.html Defines the first backend Linux virtual machine with specified size, location, and admin credentials. Ensure SSH key is properly configured. ```hcl azurerm_linux_virtual_machine.backend[0]~1: { "additional_capabilities": [], "admin_password": "Computed (known after apply)", "admin_ssh_key": [{}], "admin_username": "adminuser", "allow_extension_operations": "Computed (known after apply)", "availability_set_id": null, "boot_diagnostics": [], "bypass_platform_safety_checks_on_user_schedule_enabled": false, "capacity_reservation_group_id": null, "custom_data": "Computed (known after apply)", "dedicated_host_group_id": null, "dedicated_host_id": null, "disable_password_authentication": "Computed (known after apply)", "edge_zone": null, "encryption_at_host_enabled": null, "eviction_policy": null, "extensions_time_budget": "PT1H30M", "gallery_application": [], "identity": [], "license_type": null, "location": "eastus", "max_bid_price": -1, "name": "vm-backend-1", "os_disk": [{"diff_disk_settings": []}], "os_image_notification": [], "patch_assessment_mode": "ImageDefault", "patch_mode": "ImageDefault", "plan": [], "platform_fault_domain": -1, "priority": "Regular", "provision_vm_agent": "Computed (known after apply)", "proximity_placement_group_id": null, "reboot_setting": null, "resource_group_name": "rg-terravision-lb-test", "secret": [], "secure_boot_enabled": null, "size": "Standard_B1s", "source_image_id": null, "source_image_reference": [{}], "tags": null, "timeouts": null, "user_data": null, "virtual_machine_scale_set_id": null, "vm_agent_platform_updates_enabled": false, "vtpm_enabled": null, "zone": "1", "computer_name": "Computed (known after apply)", "disk_controller_type": "Computed (known after apply)", "id": "Computed (known after apply)", "network_interface_ids": [], "private_ip_address": "Computed (known after apply)", "private_ip_addresses": [], "public_ip_address": "Computed (known after apply)", "public_ip_addresses": [], "termination_notification": [], "virtual_machine_id": "Computed (known after apply)", "module": "main" } ``` -------------------------------- ### Data Path Normalization Source: https://github.com/patrickchugh/terravision/blob/main/docs/demo-aws.html Normalizes data paths by ensuring they start with a '/'. Handles cases where the path might be empty or already starts with a '/'. ```javascript function(t){t=\`${t}\ `;let n=t.length;zp(t,n-1)&&!zp(t,n-2)&&(t=t.slice(0,-1));return"/"===t[0]?t:\`/${t}\`} ``` -------------------------------- ### Detect Provider and Load Configuration Source: https://github.com/patrickchugh/terravision/blob/main/docs/CONTRIBUTING.md This snippet shows how to dynamically detect the cloud provider from resource prefixes and load its specific configuration. It's used in multi-cloud environments. ```python # Detect provider from resource prefixes provider = get_primary_provider_or_default(tfdata) # Load provider-specific configuration config = load_config(provider) # Use provider-specific constants icons = config.ICON_LIBRARY special_resources = config.SPECIAL_RESOURCES ``` -------------------------------- ### Publish Diagrams to Documentation Site Source: https://github.com/patrickchugh/terravision/blob/main/docs/cicd-integration.md Generate diagrams and trigger your documentation build and deployment process. ```bash terravision draw --source ./infrastructure --outfile docs/source/_static/architecture --format svg # Trigger documentation build/deploy ``` -------------------------------- ### Draw.io Direct Shape Example Source: https://github.com/patrickchugh/terravision/blob/main/docs/LEARNINGS_DRAWIO_NATIVE.md Example of a direct shape in draw.io, such as an EC2 instance. The `fillColor` attribute is crucial for rendering the monochrome SVG icon. ```xml shape=mxgraph.aws4.instance2;fillColor=#ED7100;strokeColor=none;... ``` -------------------------------- ### Get or Set Style Source: https://github.com/patrickchugh/terravision/blob/main/docs/demo-azure.html Gets the computed value of a style property for the first element, or sets the style property for all elements. Optionally accepts a unit. ```javascript style:function(t,n,e){return arguments.length>1?this.each((null==n?gn:"function"==typeof n?vn:yn)(t,n,null==e?"":e)):_n(this.node(),t)} ``` -------------------------------- ### Verify Project Dependencies Source: https://github.com/patrickchugh/terravision/blob/main/docs/CLAUDE.md Check the versions of essential tools like Graphviz, Terraform, and Git before building or releasing. Terraform must be v1.x. ```bash # Verify dependencies dot --version # Graphviz terraform version # Must be v1.x git --version ``` -------------------------------- ### Install TerraVision with pip Source: https://github.com/patrickchugh/terravision/blob/main/docs/installation.md Installs TerraVision directly into the current Python virtual environment using pip. Useful if you are already managing dependencies within a virtualenv. ```bash pip install terravision terravision --version ``` -------------------------------- ### Documenting External Systems Source: https://github.com/patrickchugh/terravision/blob/main/docs/annotations.md Include descriptive attributes when adding external resources to provide context. ```yaml add: external_api.payment: provider: "Stripe" endpoint: "https://api.stripe.com" purpose: "Payment processing" ``` -------------------------------- ### Adjust Date to Week Start Source: https://github.com/patrickchugh/terravision/blob/main/docs/demo-aws.html Adjusts a date to the beginning of its week, considering specific day-of-week logic for week start calculation. This is used for week-based calculations. ```javascript function Jv(t){var n=t.getDay();return n>=4||0===n?Ay(t):Ay.ceil(t)} ``` ```javascript function b_(t){var n=t.getUTCDay();return n>=4||0===n?Oy(t):Oy.ceil(t)} ``` -------------------------------- ### Hybrid Handler Example Source: https://github.com/patrickchugh/terravision/blob/main/docs/developer-guide.md Combine configuration-driven transformations with custom logic for complex resources. This pattern allows for both predefined operations and specific handler functions. ```python "aws_complex_resource": { "transformations": [{"operation": "expand_to_numbered_instances", "params": {...}}], "additional_handler_function": "aws_handle_complex_custom", } ``` -------------------------------- ### Brush Interaction Logic Source: https://github.com/patrickchugh/terravision/blob/main/docs/demo-azure.html Handles brush interactions, including starting, ending, and updating selections. It manages event listeners for 'start', 'interrupt', and 'end' events. ```javascript function d(t){s(this,arguments).moved(t)}function p(t){s(this,arguments).ended(t)}function g(){var n=this.__brush||{selection:null};return n.extent=ca(e.apply(this,arguments)),n.dim=t,n}return c.move=function(n,e,r){n.tween?n.on("start.brush",(function(t){s(this,arguments).beforestart().start(t)})).on("interrupt.brush end.brush",(function(t){s(this,arguments).end(t)})).tween("brush",(function(){var n=this,r=n.__brush,i=s(n,arguments),o=r.selection,a=t.input("function"==typeof e?e.apply(this,arguments):e,r.extent),u=Gr(o,a);function c(t){r.selection=1===t&&null===a?null:u(t),f.call(n),i.brush()}return null!==o&&null!==a?c:c(1)})):n.each((function(){var n=this,i=arguments,o=n.__brush,a=t.input("function"==typeof e?e.apply(n,i):e,o.extent),u=s(n,i).beforestart();Gi(n),o.selection=null===a?null:a,f.call(n),u.start(r).brush(r).end(r)}))},c.clear=function(t,n){c.move(t,null,n)},l.prototype={beforestart:function(){return 1==++this.active&&(this.state.emitter=this,this.starting=!0),this},start:function(t,n){return this.starting?(this.starting=!1,this.emit("start",t,n)):this.emit("brush",t),this},brush:function(t,n){return this.emit("brush",t,n),this},end:function(t,n){return 0==--this.active&&(delete this.state.emitter,this.emit("end",t,n)),this},emit:function(n,e,r){var i=Zn(this.that).datum();a.call(n,this.that,new Qo(n,{sourceEvent:e,target:c,selection:t.output(this.state.selection),mode:r,dispatch:a}),i)}},c.extent=function(t){return arguments.length?(e="function"==typeof t?t:Ko(ca(t)),c):e},c.filter=function(t){return arguments.length?(r="function"==typeof t?t:Ko(!!t),c):r},c.touchable=function(t){return arguments.length?(i="function"==typeof t?t:Ko(!!t),c):i},c.handleSize=function(t){return arguments.length?(u=+t,c):u},c.keyModifiers=function(t){return arguments.length?(o=!!t,c):o},c.on=function(){var t=a.on.apply(a,arguments);return t===a?c:t},c} ``` -------------------------------- ### Get or Set HTML Content Source: https://github.com/patrickchugh/terravision/blob/main/docs/demo-azure.html Gets the inner HTML of the first element in the selection, or sets the inner HTML for all elements. Handles null to clear content. ```javascript html:function(t){return arguments.length?this.each(null==t?$n:("function"==typeof t?Rn:Dn)(t)):this.node().innerHTML} ``` -------------------------------- ### Get or Set Text Content Source: https://github.com/patrickchugh/terravision/blob/main/docs/demo-azure.html Gets the text content of the first element in the selection, or sets the text content for all elements. Handles null to remove text. ```javascript text:function(t){return arguments.length?this.each(null==t?Cn:("function"==typeof t?zn:Pn)(t)):this.node().textContent} ```