This commit is contained in:
Toby
2026-01-27 17:35:45 -05:00
commit 2639af6531
176 changed files with 27104 additions and 0 deletions
@@ -0,0 +1,58 @@
---
name: arm-templates
description: Deploy Azure resources with ARM templates and Bicep. Create modular deployments and manage dependencies. Use when deploying Azure-native IaC.
license: MIT
metadata:
author: devops-skills
version: "1.0"
---
# ARM Templates & Bicep
Deploy Azure infrastructure with ARM templates and Bicep.
## Bicep Example
```bicep
param location string = resourceGroup().location
param vmName string
resource vm 'Microsoft.Compute/virtualMachines@2023-03-01' = {
name: vmName
location: location
properties: {
hardwareProfile: {
vmSize: 'Standard_B2s'
}
osProfile: {
computerName: vmName
adminUsername: 'azureuser'
}
}
}
output vmId string = vm.id
```
## Deployment
```bash
# Deploy Bicep
az deployment group create \
--resource-group mygroup \
--template-file main.bicep \
--parameters vmName=myvm
# Deploy ARM
az deployment group create \
--resource-group mygroup \
--template-file template.json \
--parameters @parameters.json
```
## Best Practices
- Use Bicep over JSON ARM
- Implement modules for reusability
- Use parameter files per environment
- Validate before deployment
@@ -0,0 +1,108 @@
# ARM Template Syntax Reference
## Template Structure
```json
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"environment": {
"type": "string",
"allowedValues": ["dev", "staging", "prod"]
}
},
"variables": {
"storageAccountName": "[concat('storage', uniqueString(resourceGroup().id))]"
},
"resources": [],
"outputs": {}
}
```
## Functions
```json
// Concatenation
"[concat('prefix-', parameters('name'), '-suffix')]"
// Unique string
"[uniqueString(resourceGroup().id)]"
// Resource ID
"[resourceId('Microsoft.Storage/storageAccounts', variables('storageName'))]"
// Reference (runtime)
"[reference(resourceId('Microsoft.Storage/storageAccounts', variables('storageName'))).primaryEndpoints.blob]"
// Conditions
"[if(equals(parameters('environment'), 'prod'), 'Standard_GRS', 'Standard_LRS')]"
```
## Resource Example
```json
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2021-09-01",
"name": "[variables('storageAccountName')]",
"location": "[resourceGroup().location]",
"sku": {
"name": "[variables('storageSku')]"
},
"kind": "StorageV2",
"properties": {
"supportsHttpsTrafficOnly": true,
"minimumTlsVersion": "TLS1_2"
}
}
```
## Dependencies
```json
{
"type": "Microsoft.Web/sites",
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]"
]
}
```
## Deployment
```bash
# Create resource group
az group create --name myRG --location eastus
# Deploy template
az deployment group create \
--resource-group myRG \
--template-file template.json \
--parameters @parameters.json
# What-if (preview changes)
az deployment group what-if \
--resource-group myRG \
--template-file template.json
```
## Bicep (Recommended)
```bicep
param location string = resourceGroup().location
param environment string
var storageAccountName = 'st${uniqueString(resourceGroup().id)}'
resource storageAccount 'Microsoft.Storage/storageAccounts@2021-09-01' = {
name: storageAccountName
location: location
sku: {
name: environment == 'prod' ? 'Standard_GRS' : 'Standard_LRS'
}
kind: 'StorageV2'
}
output storageEndpoint string = storageAccount.properties.primaryEndpoints.blob
```
@@ -0,0 +1,62 @@
---
name: azure-aks
description: Deploy and manage Azure Kubernetes Service clusters. Configure node pools, networking, and integrations. Use when running Kubernetes workloads on Azure.
license: MIT
metadata:
author: devops-skills
version: "1.0"
---
# Azure Kubernetes Service
Deploy managed Kubernetes clusters on Azure.
## Create Cluster
```bash
az aks create \
--resource-group mygroup \
--name myakscluster \
--node-count 3 \
--node-vm-size Standard_B2s \
--enable-managed-identity \
--generate-ssh-keys
# Get credentials
az aks get-credentials --resource-group mygroup --name myakscluster
```
## Node Pools
```bash
az aks nodepool add \
--resource-group mygroup \
--cluster-name myakscluster \
--name gpupool \
--node-count 1 \
--node-vm-size Standard_NC6
```
## Enable Add-ons
```bash
# Enable monitoring
az aks enable-addons \
--resource-group mygroup \
--name myakscluster \
--addons monitoring
# Enable Azure Policy
az aks enable-addons \
--resource-group mygroup \
--name myakscluster \
--addons azure-policy
```
## Best Practices
- Use managed identity
- Enable Azure CNI for networking
- Implement pod identity
- Use node pools for workload isolation
- Enable cluster autoscaler
@@ -0,0 +1,54 @@
---
name: azure-functions
description: Build serverless applications on Azure Functions. Configure triggers, bindings, and deployment. Use when implementing serverless workloads on Azure.
license: MIT
metadata:
author: devops-skills
version: "1.0"
---
# Azure Functions
Build serverless applications with Azure Functions.
## Create Function App
```bash
az functionapp create \
--resource-group mygroup \
--consumption-plan-location eastus \
--runtime python \
--runtime-version 3.11 \
--functions-version 4 \
--name myfunctionapp \
--storage-account mystorageaccount
```
## Function Code
```python
import azure.functions as func
def main(req: func.HttpRequest) -> func.HttpResponse:
return func.HttpResponse("Hello, World!")
```
## Deployment
```bash
# Deploy using Core Tools
func azure functionapp publish myfunctionapp
# Deploy using ZIP
az functionapp deployment source config-zip \
--resource-group mygroup \
--name myfunctionapp \
--src function.zip
```
## Best Practices
- Use consumption plan for variable workloads
- Implement Durable Functions for orchestration
- Use managed identity for authentication
- Monitor with Application Insights
@@ -0,0 +1,60 @@
---
name: azure-networking
description: Configure Azure VNets, NSGs, and Azure Firewall. Implement hub-spoke topology and private endpoints. Use when designing Azure network infrastructure.
license: MIT
metadata:
author: devops-skills
version: "1.0"
---
# Azure Networking
Design and implement Azure network infrastructure.
## Create VNet
```bash
az network vnet create \
--resource-group mygroup \
--name myvnet \
--address-prefix 10.0.0.0/16 \
--subnet-name default \
--subnet-prefix 10.0.1.0/24
```
## Network Security Group
```bash
az network nsg create \
--resource-group mygroup \
--name mynsg
az network nsg rule create \
--resource-group mygroup \
--nsg-name mynsg \
--name AllowHTTPS \
--priority 100 \
--destination-port-ranges 443 \
--access Allow
```
## Private Endpoint
```bash
az network private-endpoint create \
--resource-group mygroup \
--name myendpoint \
--vnet-name myvnet \
--subnet default \
--private-connection-resource-id /subscriptions/.../sql/... \
--group-id sqlServer \
--connection-name myconnection
```
## Best Practices
- Implement hub-spoke topology
- Use NSGs and Azure Firewall
- Enable DDoS protection
- Use private endpoints
- Implement VNet peering
@@ -0,0 +1,58 @@
---
name: azure-sql
description: Provision Azure SQL Database and Cosmos DB. Configure security, backups, and replication. Use when deploying managed databases on Azure.
license: MIT
metadata:
author: devops-skills
version: "1.0"
---
# Azure SQL
Deploy managed databases on Azure.
## Create SQL Database
```bash
# Create server
az sql server create \
--name myserver \
--resource-group mygroup \
--admin-user sqladmin \
--admin-password SecureP@ss123
# Create database
az sql db create \
--resource-group mygroup \
--server myserver \
--name mydb \
--service-objective S1
```
## Firewall Rules
```bash
az sql server firewall-rule create \
--resource-group mygroup \
--server myserver \
--name AllowAzure \
--start-ip-address 0.0.0.0 \
--end-ip-address 0.0.0.0
```
## Cosmos DB
```bash
az cosmosdb create \
--name mycosmosdb \
--resource-group mygroup \
--default-consistency-level Session
```
## Best Practices
- Enable transparent data encryption
- Use Azure AD authentication
- Implement geo-replication
- Configure automated backups
- Use private endpoints
@@ -0,0 +1,45 @@
---
name: azure-vms
description: Manage Azure Virtual Machines and scale sets. Configure availability sets and managed disks. Use when deploying compute resources on Azure.
license: MIT
metadata:
author: devops-skills
version: "1.0"
---
# Azure Virtual Machines
Deploy and manage Azure VMs and scale sets.
## Create VM
```bash
az vm create \
--resource-group mygroup \
--name myvm \
--image Ubuntu2204 \
--size Standard_B2s \
--admin-username azureuser \
--generate-ssh-keys \
--nsg-rule SSH
```
## Scale Sets
```bash
az vmss create \
--resource-group mygroup \
--name myvmss \
--image Ubuntu2204 \
--instance-count 2 \
--vm-sku Standard_B2s \
--upgrade-policy-mode automatic
```
## Best Practices
- Use managed disks
- Implement availability zones
- Use scale sets for auto-scaling
- Enable Azure Backup
- Use spot instances for cost savings
@@ -0,0 +1,99 @@
# Azure VM Operations Reference
## VM Management
```bash
# Create VM
az vm create \
--resource-group myRG \
--name myVM \
--image Ubuntu2204 \
--admin-username azureuser \
--generate-ssh-keys \
--size Standard_B2s
# Start/Stop/Delete
az vm start --resource-group myRG --name myVM
az vm stop --resource-group myRG --name myVM
az vm deallocate --resource-group myRG --name myVM
az vm delete --resource-group myRG --name myVM --yes
# List VMs
az vm list --resource-group myRG -o table
az vm list-ip-addresses --resource-group myRG -o table
```
## VM Sizes
| Size | vCPU | Memory | Use Case |
|------|------|--------|----------|
| Standard_B1s | 1 | 1 GB | Dev/Test |
| Standard_B2s | 2 | 4 GB | Light workloads |
| Standard_D2s_v3 | 2 | 8 GB | General |
| Standard_F2s_v2 | 2 | 4 GB | Compute |
| Standard_E2s_v3 | 2 | 16 GB | Memory |
```bash
# List available sizes
az vm list-sizes --location eastus -o table
# Resize VM
az vm resize --resource-group myRG --name myVM --size Standard_D4s_v3
```
## Images
```bash
# List images
az vm image list --output table
az vm image list --publisher Canonical --all --output table
# Create image from VM
az vm deallocate --resource-group myRG --name myVM
az vm generalize --resource-group myRG --name myVM
az image create --resource-group myRG --name myImage --source myVM
```
## Custom Script Extension
```bash
az vm extension set \
--resource-group myRG \
--vm-name myVM \
--name customScript \
--publisher Microsoft.Azure.Extensions \
--settings '{"commandToExecute":"apt-get update && apt-get install -y nginx"}'
```
## Terraform
```hcl
resource "azurerm_linux_virtual_machine" "main" {
name = "myVM"
resource_group_name = azurerm_resource_group.main.name
location = azurerm_resource_group.main.location
size = "Standard_B2s"
admin_username = "azureuser"
admin_ssh_key {
username = "azureuser"
public_key = file("~/.ssh/id_rsa.pub")
}
os_disk {
caching = "ReadWrite"
storage_account_type = "Premium_LRS"
}
source_image_reference {
publisher = "Canonical"
offer = "0001-com-ubuntu-server-jammy"
sku = "22_04-lts"
version = "latest"
}
network_interface_ids = [
azurerm_network_interface.main.id,
]
}
```
@@ -0,0 +1,59 @@
---
name: terraform-azure
description: Provision Azure infrastructure with Terraform. Configure providers, manage state, and deploy resources. Use when implementing IaC for Azure.
license: MIT
metadata:
author: devops-skills
version: "1.0"
---
# Terraform Azure
Provision Azure infrastructure with Terraform.
## Provider Configuration
```hcl
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 3.0"
}
}
backend "azurerm" {
resource_group_name = "tfstate"
storage_account_name = "tfstate12345"
container_name = "tfstate"
key = "prod.terraform.tfstate"
}
}
provider "azurerm" {
features {}
}
```
## Example Resources
```hcl
resource "azurerm_resource_group" "main" {
name = "myapp-rg"
location = "East US"
}
resource "azurerm_virtual_network" "main" {
name = "myapp-vnet"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
}
```
## Best Practices
- Use remote state in Azure Storage
- Implement resource naming conventions
- Use data sources for existing resources
- Tag all resources
- Use modules for reusability
@@ -0,0 +1,80 @@
# Azure Virtual Network Module Template
variable "address_space" {
description = "VNet address space"
type = list(string)
default = ["10.0.0.0/16"]
}
# Virtual Network
resource "azurerm_virtual_network" "main" {
name = "${var.project_name}-${var.environment}-vnet"
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
address_space = var.address_space
tags = local.common_tags
}
# Public Subnet
resource "azurerm_subnet" "public" {
name = "public-subnet"
resource_group_name = azurerm_resource_group.main.name
virtual_network_name = azurerm_virtual_network.main.name
address_prefixes = ["10.0.1.0/24"]
}
# Private Subnet
resource "azurerm_subnet" "private" {
name = "private-subnet"
resource_group_name = azurerm_resource_group.main.name
virtual_network_name = azurerm_virtual_network.main.name
address_prefixes = ["10.0.2.0/24"]
}
# AKS Subnet
resource "azurerm_subnet" "aks" {
name = "aks-subnet"
resource_group_name = azurerm_resource_group.main.name
virtual_network_name = azurerm_virtual_network.main.name
address_prefixes = ["10.0.10.0/23"]
}
# Network Security Group
resource "azurerm_network_security_group" "main" {
name = "${var.project_name}-${var.environment}-nsg"
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
security_rule {
name = "SSH"
priority = 1001
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = "*"
destination_address_prefix = "*"
}
tags = local.common_tags
}
# NSG Association
resource "azurerm_subnet_network_security_group_association" "public" {
subnet_id = azurerm_subnet.public.id
network_security_group_id = azurerm_network_security_group.main.id
}
output "vnet_id" {
value = azurerm_virtual_network.main.id
}
output "subnet_ids" {
value = {
public = azurerm_subnet.public.id
private = azurerm_subnet.private.id
aks = azurerm_subnet.aks.id
}
}
@@ -0,0 +1,130 @@
#!/bin/bash
# Terraform Azure Project Initialization Script
# Usage: ./tf-init-azure.sh <project-name> [location]
set -euo pipefail
PROJECT_NAME="${1:-}"
LOCATION="${2:-eastus}"
if [ -z "$PROJECT_NAME" ]; then
echo "Usage: $0 <project-name> [location]"
exit 1
fi
echo "========================================="
echo "Terraform Azure Project Setup"
echo "Project: $PROJECT_NAME"
echo "Location: $LOCATION"
echo "========================================="
echo ""
mkdir -p "$PROJECT_NAME"
cd "$PROJECT_NAME"
# Create main.tf
cat > main.tf << EOF
terraform {
required_version = ">= 1.0"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 3.0"
}
}
# Uncomment for remote state
# backend "azurerm" {
# resource_group_name = "${PROJECT_NAME}-tfstate-rg"
# storage_account_name = "${PROJECT_NAME}tfstate"
# container_name = "tfstate"
# key = "terraform.tfstate"
# }
}
provider "azurerm" {
features {}
}
# Resource Group
resource "azurerm_resource_group" "main" {
name = "\${var.project_name}-\${var.environment}-rg"
location = var.location
tags = local.common_tags
}
locals {
common_tags = {
Project = var.project_name
Environment = var.environment
ManagedBy = "terraform"
}
}
EOF
# Create variables.tf
cat > variables.tf << EOF
variable "project_name" {
description = "Project name for resource naming"
type = string
default = "${PROJECT_NAME}"
}
variable "environment" {
description = "Environment (dev, staging, prod)"
type = string
default = "dev"
}
variable "location" {
description = "Azure region"
type = string
default = "${LOCATION}"
}
EOF
# Create outputs.tf
cat > outputs.tf << EOF
output "resource_group_name" {
description = "Resource group name"
value = azurerm_resource_group.main.name
}
output "location" {
description = "Azure region"
value = azurerm_resource_group.main.location
}
EOF
# Create terraform.tfvars
cat > terraform.tfvars << EOF
project_name = "${PROJECT_NAME}"
environment = "dev"
location = "${LOCATION}"
EOF
# Create .gitignore
cat > .gitignore << EOF
.terraform/
*.tfstate
*.tfstate.*
*.tfvars.json
crash.log
*.tfplan
!terraform.tfvars.example
.idea/
*.swp
.vscode/
EOF
# Initialize Terraform
echo ""
echo "Initializing Terraform..."
terraform init
echo ""
echo "========================================="
echo "Project created successfully!"
echo "========================================="