Supported Cloud Providers:
- Azure: VNets with subnets, optional hub-spoke peering
- AWS: VPCs with subnets distributed across AZs
- GCP: VPCs with subnets (hub-spoke supported)
- Oracle Cloud: VCNs with subnets
- AliCloud: VPCs with subnets
- On-Premises: Basic IP calculations
Output Formats by Provider:
- Azure: info, JSON, Terraform, Bicep, ARM, PowerShell, Azure CLI
- AWS: info, JSON, Terraform, CloudFormation, AWS CLI
- GCP: info, JSON, Terraform, gcloud
- Oracle: info, JSON, Terraform, OCI CLI
- AliCloud: info, JSON, Terraform, Aliyun CLI
- On-Premises: info, JSON
Uses Python for deterministic IP calculations matching the TypeScript CLI implementation.
Show network information:
/ipcalc-for-cloud "azure, 10.0.0.0/16, 4 subnets"
Generate Terraform for AWS:
/ipcalc-for-cloud "aws, 10.0.0.0/16, 3 subnets, output: terraform"
Custom subnet prefix (to avoid filling entire network):
/ipcalc-for-cloud "azure, 172.16.1.0/24, 4 subnets, prefix: /26"
Hub-spoke topology for Azure:
/ipcalc-for-cloud "azure, 10.0.0.0/16, 2 subnets, spokes: 10.1.0.0/16,10.2.0.0/16, spoke-subnets: 2,2, output: terraform"
The skill will:
- Calculate optimal CIDR splits based on provider constraints
- Distribute subnets across availability zones (AWS/GCP)
- Apply provider-specific reserved IP calculations
- Validate IP allocations
- Output in requested format
Accept user input specifying:
- Cloud provider: azure, aws, gcp, oracle, alicloud, onpremises
- Base CIDR: Network CIDR block (e.g., "10.0.0.0/16")
- Number of subnets: How many subnets to create (1-256)
- Output format: info (default), json, terraform, bicep, arm, powershell, cloudformation, cli, gcloud, oci, aliyun
- Optional - Custom prefix: Desired subnet prefix (e.g., /26) to override auto-calculation
- Optional - Hub-spoke: Spoke network CIDRs and subnet counts for hub-spoke topology
Extract:
- Cloud provider selection
- Base IP range (CIDR notation)
- Number of subnets for primary network
- Output format
- Custom subnet prefix (if specified)
- Spoke network specifications (if hub-spoke topology)
Step 2: Run IP Calculations
Execute the IP calculation script with cloud provider configuration:
python ~/.claude/skills/ipcalc-for-cloud/scripts/ipcalc.py \
--provider azure \
--cidr "10.0.0.0/16" \
--subnets 4 \
--output terraform
With custom subnet prefix:
python ~/.claude/skills/ipcalc-for-cloud/scripts/ipcalc.py \
--provider azure \
--cidr "172.16.1.0/24" \
--subnets 4 \
--prefix 26 \
--output info
With hub-spoke topology:
python ~/.claude/skills/ipcalc-for-cloud/scripts/ipcalc.py \
--provider azure \
--cidr "10.0.0.0/16" \
--subnets 2 \
--spoke-cidrs "10.1.0.0/16,10.2.0.0/16,10.3.0.0/16" \
--spoke-subnets "2,2,2" \
--output terraform
The script will:
- Validate base CIDR against provider constraints
- Calculate optimal subnet prefix OR use custom prefix
- Check capacity (can the network accommodate requested subnets?)
- Generate subnet CIDR assignments
- Distribute subnets across availability zones (AWS, GCP)
- Calculate provider-specific reserved IPs (Azure: 5, AWS: 5, GCP: 4, Oracle: 3)
- Calculate usable IP ranges
- Detect any overlaps or invalid ranges
- For hub-spoke: Calculate spoke networks and configure peering
- Output structured data for template rendering
Step 3: Output Results
Based on requested output format and provider:
Info format (default):
- Human-readable formatted table
- Network details (CIDR, total IPs, address range)
- Subnet details with availability zones
- Reserved and usable IP information
- Provider-specific formatting
JSON format:
- Structured JSON data
- Complete network and subnet information
- Availability zone assignments
- Reserved IP lists
- Machine-readable for integration
Terraform format:
Generate HCL code with:
- Provider configuration (azurerm, aws, google, etc.)
- Variables for customization
- Network resource (VNet/VPC)
- Subnet resources with AZ distribution
- Outputs for resource IDs
- Hub-spoke peering resources (if applicable)
- Comments with IP allocation table
Other IaC formats:
- Bicep: Azure Bicep template with inline subnets
- ARM: Azure Resource Manager JSON template
- PowerShell: Azure PowerShell script with cmdlets
- CloudFormation: AWS YAML template with intrinsic functions
- CLI Scripts: Bash scripts with az/aws/gcloud commands
Step 4: Validate Output
Run validation checks:
- IP range validation (no overlaps, proper nesting)
- Provider constraint validation (prefix limits)
- Capacity validation (requested subnets fit in network)
- For Terraform: syntax validation (if terraform CLI available)
- For hub-spoke: peering configuration correctness
IP Range Validation:
- Verify all subnets fit within parent network
- Confirm no overlapping ranges
- Validate CIDR notation
- Check provider constraints (min/max prefix)
Provider Constraint Validation:
- Azure: /8 to /29
- AWS: /16 to /28
- GCP: /8 to /29
- Oracle: /16 to /30
- AliCloud: /8 to /29
Capacity Validation:
- Requested subnets fit in network
- Custom prefix (if specified) allows requested subnet count
- No address space exhaustion
Manual Review Checklist:
Additional validation for IaC output:
Syntax Validation (if CLI tools available):
# Terraform
terraform init && terraform validate
# Azure Bicep
az bicep build --file output.bicep
# AWS CloudFormation
aws cloudformation validate-template --template-body file://output.yaml
IaC Checklist:
Hub-Spoke Topology (Azure, GCP):
Create centralized hub network with multiple spoke networks:
/ipcalc-for-cloud "azure, 10.0.0.0/16, 2 subnets, spokes: 10.1.0.0/16,10.2.0.0/16,10.3.0.0/16, spoke-subnets: 2,3,2, output: terraform"
Generates bidirectional peering between hub and each spoke
Multi-Provider Support:
Same IP calculations work across all cloud providers with provider-specific adjustments:
- Reserved IP counts
- CIDR prefix constraints
- Availability zone naming
- Output format availability
Availability Zone Distribution (AWS, GCP):
Automatic round-robin distribution of subnets across AZs for high availability
Legacy Compatibility:
Old command-line options still supported for backward compatibility:
python ipcalc.py --base-cidr "10.0.0.0/16" --vnets 3 --subnets-per-vnet 4
(Creates multiple VNets instead of single VNet with subnets)
scripts/ipcalc.py
Main IP calculator script supporting multiple cloud providers and output formats.
Key Functions:
calculate_subnets(cidr, num_subnets, provider, desired_prefix) - Calculate subnet allocations
generate_hub_spoke_topology(hub_cidr, hub_subnets, spoke_cidrs, spoke_subnets, provider) - Hub-spoke networks
calculate_network_info(network, provider_config) - Detailed network information
format_network_info(cidr, subnets, provider) - Human-readable output
Usage:
python scripts/ipcalc.py --provider PROVIDER --cidr CIDR --subnets N [OPTIONS]
Options:
--provider: Cloud provider (azure, aws, gcp, oracle, alicloud, onpremises)
--cidr: Network CIDR block
--subnets: Number of subnets (1-256)
--prefix: Optional custom subnet prefix
--output: Output format (info, json, terraform, bicep, arm, powershell, cloudformation, cli, gcloud, oci, aliyun)
--file: Write output to file
--spoke-cidrs: Comma-separated spoke VNet/VPC CIDRs
--spoke-subnets: Comma-separated subnet counts per spoke
Output Format (JSON):
{
"vnetCidr": "10.0.0.0/16",
"provider": "azure",
"subnets": [
{
"name": "subnet1",
"cidr": "10.0.0.0/18",
"network": "10.0.0.0",
"mask": "255.255.192.0",
"total_ips": 16384,
"usable_ips": 16379,
"usable_range": "10.0.0.3 - 10.0.63.253",
"availabilityZone": "1",
"reserved": ["10.0.0.0", "10.0.0.1", "10.0.0.2", "10.0.63.254", "10.0.63.255"]
}
],
"peeringEnabled": false
}
scripts/cloud_provider_config.py
Cloud provider configuration module defining provider-specific settings.
Configurations:
- Reserved IP counts (Azure: 5, AWS: 5, GCP: 4, Oracle: 3, etc.)
- CIDR prefix limits (min/max)
- Availability zone lists
- Supported output formats
Functions:
get_cloud_provider_config(provider) - Get provider configuration
validate_output_format(provider, output_format) - Validate output format support
get_availability_zone(provider, index) - Get AZ for subnet index (round-robin)
scripts/ipcalc_legacy.py
Legacy version supporting old multi-VNet split behavior. Use for backward compatibility:
python scripts/ipcalc_legacy.py --base-cidr "10.0.0.0/16" --vnets 3 --subnets-per-vnet 4
Creates 3 separate VNets instead of 1 VNet with subnets.
Templates are organized by provider and format:
templates/
├── azure/
│ ├── terraform.template.tf
│ ├── bicep.template.bicep
│ ├── arm.template.json
│ ├── powershell.template.ps1
│ └── cli.template.sh
├── aws/
│ ├── terraform.template.tf
│ ├── cloudformation.template.yaml
│ └── cli.template.sh
└── ...
Template Placeholders:
Common across all templates:
{{vnetCidr}} / {{vpcCidr}} - Network CIDR
{{subnetVariables}} - Subnet variable declarations
{{subnetResources}} - Subnet resource definitions
{{subnetOutputs}} - Output definitions
{{spokeVnetResources}} / {{spokeVpcResources}} - Spoke network resources
{{vnetPeeringResources}} / {{vpcPeeringResources}} - Peering configurations
Template Processor:
The template processor module (template_processor.py) generates placeholder content:
- Variable/parameter declarations
- Resource definitions with proper syntax
- Hub-spoke peering logic
- Provider-specific formatting
Templates use simple string replacement for placeholders, maintaining exact output compatibility with TypeScript CLI.
For all providers and outputs:
For AWS and GCP:
For hub-spoke topologies:
For IaC template outputs:
Compatibility:
1---2name: ipcalc-for-cloud3description: Calculates IP ranges, CIDR blocks, and subnet allocations for cloud networks (Azure, AWS, GCP, Oracle, AliCloud). Supports single VNet/VPC or hub-spoke topologies with automatic AZ distribution. Outputs as info tables, JSON, or IaC templates (Terraform, Bicep, ARM, PowerShell, CloudFormation). Use for network planning, IP calculations, CIDR notation, or infrastructure as code generation.4---5
6<objective>
7Calculate IP ranges, CIDR blocks, and subnet allocations for cloud network planning. This skill:
8- Performs CIDR subnet calculations and splitting for cloud providers
9- Creates single VNet/VPC with multiple subnets OR hub-spoke topologies
10- Validates IP ranges and detects overlaps
11- Automatically assigns optimal CIDR blocks or uses custom subnet prefixes
12- Distributes subnets across availability zones (AWS, GCP)
13- Calculates provider-specific reserved IPs and usable ranges
14- Outputs results as formatted tables, JSON, or IaC templates
15
16Supported Cloud Providers:
17- **Azure**: VNets with subnets, optional hub-spoke peering
18- **AWS**: VPCs with subnets distributed across AZs
19- **GCP**: VPCs with subnets (hub-spoke supported)
20- **Oracle Cloud**: VCNs with subnets
21- **AliCloud**: VPCs with subnets
22- **On-Premises**: Basic IP calculations
23
24Output Formats by Provider:
25- **Azure**: info, JSON, Terraform, Bicep, ARM, PowerShell, Azure CLI
26- **AWS**: info, JSON, Terraform, CloudFormation, AWS CLI
27- **GCP**: info, JSON, Terraform, gcloud
28- **Oracle**: info, JSON, Terraform, OCI CLI
29- **AliCloud**: info, JSON, Terraform, Aliyun CLI
30- **On-Premises**: info, JSON
31
32Uses Python for deterministic IP calculations matching the TypeScript CLI implementation.
33</objective>
34
35<quick_start>
36Basic usage - calculate subnets for a single VNet/VPC:
37
38**Show network information**:
39```
40/ipcalc-for-cloud "azure, 10.0.0.0/16, 4 subnets"
41```
42
43**Generate Terraform for AWS**:
44```
45/ipcalc-for-cloud "aws, 10.0.0.0/16, 3 subnets, output: terraform"
46```
47
48**Custom subnet prefix** (to avoid filling entire network):
49```
50/ipcalc-for-cloud "azure, 172.16.1.0/24, 4 subnets, prefix: /26"
51```
52
53**Hub-spoke topology for Azure**:
54```
55/ipcalc-for-cloud "azure, 10.0.0.0/16, 2 subnets, spokes: 10.1.0.0/16,10.2.0.0/16, spoke-subnets: 2,2, output: terraform"
56```
57
58The skill will:
59- Calculate optimal CIDR splits based on provider constraints
60- Distribute subnets across availability zones (AWS/GCP)
61- Apply provider-specific reserved IP calculations
62- Validate IP allocations
63- Output in requested format
64</quick_start>
65
66<workflow>
67## Step 1: Parse Input Specifications
68
69Accept user input specifying:
70- **Cloud provider**: azure, aws, gcp, oracle, alicloud, onpremises
71- **Base CIDR**: Network CIDR block (e.g., "10.0.0.0/16")
72- **Number of subnets**: How many subnets to create (1-256)
73- **Output format**: info (default), json, terraform, bicep, arm, powershell, cloudformation, cli, gcloud, oci, aliyun
74- **Optional - Custom prefix**: Desired subnet prefix (e.g., /26) to override auto-calculation
75- **Optional - Hub-spoke**: Spoke network CIDRs and subnet counts for hub-spoke topology
76
77Extract:
78- Cloud provider selection
79- Base IP range (CIDR notation)
80- Number of subnets for primary network
81- Output format
82- Custom subnet prefix (if specified)
83- Spoke network specifications (if hub-spoke topology)
84
85## Step 2: Run IP Calculations
86
87Execute the IP calculation script with cloud provider configuration:
88
89```bash
90python ~/.claude/skills/ipcalc-for-cloud/scripts/ipcalc.py \
91 --provider azure \
92 --cidr "10.0.0.0/16" \
93 --subnets 4 \
94 --output terraform
95```
96
97**With custom subnet prefix**:
98```bash
99python ~/.claude/skills/ipcalc-for-cloud/scripts/ipcalc.py \
100 --provider azure \
101 --cidr "172.16.1.0/24" \
102 --subnets 4 \
103 --prefix 26 \
104 --output info
105```
106
107**With hub-spoke topology**:
108```bash
109python ~/.claude/skills/ipcalc-for-cloud/scripts/ipcalc.py \
110 --provider azure \
111 --cidr "10.0.0.0/16" \
112 --subnets 2 \
113 --spoke-cidrs "10.1.0.0/16,10.2.0.0/16,10.3.0.0/16" \
114 --spoke-subnets "2,2,2" \
115 --output terraform
116```
117
118The script will:
119- Validate base CIDR against provider constraints
120- Calculate optimal subnet prefix OR use custom prefix
121- Check capacity (can the network accommodate requested subnets?)
122- Generate subnet CIDR assignments
123- Distribute subnets across availability zones (AWS, GCP)
124- Calculate provider-specific reserved IPs (Azure: 5, AWS: 5, GCP: 4, Oracle: 3)
125- Calculate usable IP ranges
126- Detect any overlaps or invalid ranges
127- For hub-spoke: Calculate spoke networks and configure peering
128- Output structured data for template rendering
129
130## Step 3: Output Results
131
132Based on requested output format and provider:
133
134**Info format** (default):
135- Human-readable formatted table
136- Network details (CIDR, total IPs, address range)
137- Subnet details with availability zones
138- Reserved and usable IP information
139- Provider-specific formatting
140
141**JSON format**:
142- Structured JSON data
143- Complete network and subnet information
144- Availability zone assignments
145- Reserved IP lists
146- Machine-readable for integration
147
148**Terraform format**:
149Generate HCL code with:
150- Provider configuration (azurerm, aws, google, etc.)
151- Variables for customization
152- Network resource (VNet/VPC)
153- Subnet resources with AZ distribution
154- Outputs for resource IDs
155- Hub-spoke peering resources (if applicable)
156- Comments with IP allocation table
157
158**Other IaC formats**:
159- **Bicep**: Azure Bicep template with inline subnets
160- **ARM**: Azure Resource Manager JSON template
161- **PowerShell**: Azure PowerShell script with cmdlets
162- **CloudFormation**: AWS YAML template with intrinsic functions
163- **CLI Scripts**: Bash scripts with az/aws/gcloud commands
164
165## Step 4: Validate Output
166
167Run validation checks:
168- IP range validation (no overlaps, proper nesting)
169- Provider constraint validation (prefix limits)
170- Capacity validation (requested subnets fit in network)
171- For Terraform: syntax validation (if terraform CLI available)
172- For hub-spoke: peering configuration correctness
173</workflow>
174
175<examples>
176<example number="1">
177<input>
178User: "Calculate IP allocation for Azure with 10.0.0.0/16 and 4 subnets"
179</input>
180<process>
1811. Parse: provider=azure, cidr=10.0.0.0/16, subnets=4, output=info (default)
1822. Calculate:
183 - VNet: 10.0.0.0/16 (65,536 IPs)
184 - Auto-calculate subnet prefix: /18 (4 subnets need 2 bits)
185 - Subnet 1: 10.0.0.0/18 (16,384 IPs, Azure AZ 1)
186 - Subnet 2: 10.0.64.0/18 (16,384 IPs, Azure AZ 2)
187 - Subnet 3: 10.0.128.0/18 (16,384 IPs, Azure AZ 3)
188 - Subnet 4: 10.0.192.0/18 (16,384 IPs, Azure AZ 1)
189 - Apply Azure reserved IPs (5 per subnet)
1903. Display formatted table with network info and subnet details
191</process>
192<output>
193Formatted table showing:
194- Network address, CIDR, total IPs
195- Each subnet with CIDR, network, mask, usable IPs, usable range, AZ, reserved IPs
196</output>
197</example>
198
199<example number="2">
200<input>
201User: "Generate Terraform for AWS with 172.16.0.0/12, 6 subnets"
202</input>
203<process>
2041. Parse: provider=aws, cidr=172.16.0.0/12, subnets=6, output=terraform
2052. Calculate:
206 - VPC: 172.16.0.0/12 (1,048,576 IPs)
207 - Auto-calculate subnet prefix: /15 (6 subnets need 3 bits = /15)
208 - Generate 6 subnets distributed round-robin across AWS AZs
209 - Apply AWS reserved IPs (5 per subnet)
2103. Generate Terraform code with AWS provider, VPC, subnets with AZ distribution, outputs
211</process>
212<output>
213Terraform file with:
214- AWS provider ~> 5.0
215- VPC resource with DNS enabled
216- 6 subnet resources, each with availability_zone from round-robin distribution
217- Internet gateway and route table
218- Output blocks for VPC ID and subnet IDs
219- IP allocation table in comments
220</output>
221</example>
222
223<example number="3">
224<input>
225User: "Azure hub-spoke with hub 10.0.0.0/16 (2 subnets), spokes 10.1.0.0/16 and 10.2.0.0/16 (2 subnets each), Terraform output"
226</input>
227<process>
2281. Parse: provider=azure, hub_cidr=10.0.0.0/16, hub_subnets=2, spoke_cidrs=[10.1.0.0/16, 10.2.0.0/16], spoke_subnets=[2,2], output=terraform
2292. Calculate hub network:
230 - Hub VNet: 10.0.0.0/16
231 - 2 subnets (/17 each)
2323. Calculate spoke networks:
233 - Spoke 1: 10.1.0.0/16 with 2 subnets (/17 each)
234 - Spoke 2: 10.2.0.0/16 with 2 subnets (/17 each)
2354. Generate Terraform with peering configuration
236</process>
237<output>
238Terraform file with:
239- Hub VNet and subnets
240- Spoke VNet resources
241- Spoke subnet resources
242- Bidirectional peering: hub-to-spoke1, spoke1-to-hub, hub-to-spoke2, spoke2-to-hub
243- Peering properties: allowVirtualNetworkAccess, allowForwardedTraffic
244- Outputs for all network and peering IDs
245</output>
246</example>
247
248<example number="4">
249<input>
250User: "Calculate 172.16.1.0/24 with 4 subnets using /26 prefix for Azure"
251</input>
252<process>
2531. Parse: provider=azure, cidr=172.16.1.0/24, subnets=4, prefix=26
2542. Validate:
255 - /24 network can fit 4 × /26 subnets? Yes (256 IPs ÷ 64 IPs = 4)
256 - /26 meets Azure minimum (/29)? Yes
2573. Calculate using /26 prefix:
258 - Subnet 1: 172.16.1.0/26 (64 IPs)
259 - Subnet 2: 172.16.1.64/26 (64 IPs)
260 - Subnet 3: 172.16.1.128/26 (64 IPs)
261 - Subnet 4: 172.16.1.192/26 (64 IPs)
262 - This uses exactly the full /24 network
2634. Display info
264</process>
265<output>
266Formatted table showing 4 subnets with /26 prefix, each with 59 usable IPs (64 - 5 Azure reserved)
267</output>
268</example>
269</examples>
270
271<validation>
272For all output formats:
273
2741. **IP Range Validation**:
275 - Verify all subnets fit within parent network
276 - Confirm no overlapping ranges
277 - Validate CIDR notation
278 - Check provider constraints (min/max prefix)
279
2802. **Provider Constraint Validation**:
281 - Azure: /8 to /29
282 - AWS: /16 to /28
283 - GCP: /8 to /29
284 - Oracle: /16 to /30
285 - AliCloud: /8 to /29
286
2873. **Capacity Validation**:
288 - Requested subnets fit in network
289 - Custom prefix (if specified) allows requested subnet count
290 - No address space exhaustion
291
2924. **Manual Review Checklist**:
293 - [ ] Subnets properly sized for intended use
294 - [ ] Availability zone distribution is appropriate
295 - [ ] Reserved IPs calculated correctly for provider
296 - [ ] Usable IP counts are accurate
297 - [ ] Hub-spoke peering configured correctly (if applicable)
298
299**Additional validation for IaC output**:
300
3015. **Syntax Validation** (if CLI tools available):
302 ```bash
303 # Terraform
304 terraform init && terraform validate
305
306 # Azure Bicep
307 az bicep build --file output.bicep
308
309 # AWS CloudFormation
310 aws cloudformation validate-template --template-body file://output.yaml
311 ```
312
3136. **IaC Checklist**:
314 - [ ] Provider configuration present and correct version
315 - [ ] Resource naming follows conventions
316 - [ ] Variables defined for customization
317 - [ ] Output variables defined for resource IDs
318 - [ ] Hub-spoke peering resources complete (if applicable)
319 - [ ] IP allocation documented in comments
320</validation>
321
322<advanced_features>
323**Custom Subnet Prefix**:
324Specify exact subnet size instead of auto-calculation:
325```
326/ipcalc-for-cloud "azure, 172.16.1.0/24, 4 subnets, prefix: /26"
327```
328Use case: Avoid filling entire network, leave room for future expansion
329
330**Hub-Spoke Topology** (Azure, GCP):
331Create centralized hub network with multiple spoke networks:
332```
333/ipcalc-for-cloud "azure, 10.0.0.0/16, 2 subnets, spokes: 10.1.0.0/16,10.2.0.0/16,10.3.0.0/16, spoke-subnets: 2,3,2, output: terraform"
334```
335Generates bidirectional peering between hub and each spoke
336
337**Multi-Provider Support**:
338Same IP calculations work across all cloud providers with provider-specific adjustments:
339- Reserved IP counts
340- CIDR prefix constraints
341- Availability zone naming
342- Output format availability
343
344**Availability Zone Distribution** (AWS, GCP):
345Automatic round-robin distribution of subnets across AZs for high availability
346
347**Legacy Compatibility**:
348Old command-line options still supported for backward compatibility:
349```bash
350python ipcalc.py --base-cidr "10.0.0.0/16" --vnets 3 --subnets-per-vnet 4
351```
352(Creates multiple VNets instead of single VNet with subnets)
353</advanced_features>
354
355<scripts_reference>
356## scripts/ipcalc.py
357
358Main IP calculator script supporting multiple cloud providers and output formats.
359
360**Key Functions**:
361- `calculate_subnets(cidr, num_subnets, provider, desired_prefix)` - Calculate subnet allocations
362- `generate_hub_spoke_topology(hub_cidr, hub_subnets, spoke_cidrs, spoke_subnets, provider)` - Hub-spoke networks
363- `calculate_network_info(network, provider_config)` - Detailed network information
364- `format_network_info(cidr, subnets, provider)` - Human-readable output
365
366**Usage**:
367```bash
368python scripts/ipcalc.py --provider PROVIDER --cidr CIDR --subnets N [OPTIONS]
369```
370
371**Options**:
372- `--provider`: Cloud provider (azure, aws, gcp, oracle, alicloud, onpremises)
373- `--cidr`: Network CIDR block
374- `--subnets`: Number of subnets (1-256)
375- `--prefix`: Optional custom subnet prefix
376- `--output`: Output format (info, json, terraform, bicep, arm, powershell, cloudformation, cli, gcloud, oci, aliyun)
377- `--file`: Write output to file
378- `--spoke-cidrs`: Comma-separated spoke VNet/VPC CIDRs
379- `--spoke-subnets`: Comma-separated subnet counts per spoke
380
381**Output Format** (JSON):
382```json
383{
384 "vnetCidr": "10.0.0.0/16",
385 "provider": "azure",
386 "subnets": [
387 {
388 "name": "subnet1",
389 "cidr": "10.0.0.0/18",
390 "network": "10.0.0.0",
391 "mask": "255.255.192.0",
392 "total_ips": 16384,
393 "usable_ips": 16379,
394 "usable_range": "10.0.0.3 - 10.0.63.253",
395 "availabilityZone": "1",
396 "reserved": ["10.0.0.0", "10.0.0.1", "10.0.0.2", "10.0.63.254", "10.0.63.255"]
397 }
398 ],
399 "peeringEnabled": false
400}
401```
402
403## scripts/cloud_provider_config.py
404
405Cloud provider configuration module defining provider-specific settings.
406
407**Configurations**:
408- Reserved IP counts (Azure: 5, AWS: 5, GCP: 4, Oracle: 3, etc.)
409- CIDR prefix limits (min/max)
410- Availability zone lists
411- Supported output formats
412
413**Functions**:
414- `get_cloud_provider_config(provider)` - Get provider configuration
415- `validate_output_format(provider, output_format)` - Validate output format support
416- `get_availability_zone(provider, index)` - Get AZ for subnet index (round-robin)
417
418## scripts/ipcalc_legacy.py
419
420Legacy version supporting old multi-VNet split behavior. Use for backward compatibility:
421```bash
422python scripts/ipcalc_legacy.py --base-cidr "10.0.0.0/16" --vnets 3 --subnets-per-vnet 4
423```
424Creates 3 separate VNets instead of 1 VNet with subnets.
425</scripts_reference>
426
427<templates_reference>
428## Template Architecture
429
430Templates are organized by provider and format:
431```
432templates/
433├── azure/
434│ ├── terraform.template.tf
435│ ├── bicep.template.bicep
436│ ├── arm.template.json
437│ ├── powershell.template.ps1
438│ └── cli.template.sh
439├── aws/
440│ ├── terraform.template.tf
441│ ├── cloudformation.template.yaml
442│ └── cli.template.sh
443└── ...
444```
445
446**Template Placeholders**:
447Common across all templates:
448- `{{vnetCidr}}` / `{{vpcCidr}}` - Network CIDR
449- `{{subnetVariables}}` - Subnet variable declarations
450- `{{subnetResources}}` - Subnet resource definitions
451- `{{subnetOutputs}}` - Output definitions
452- `{{spokeVnetResources}}` / `{{spokeVpcResources}}` - Spoke network resources
453- `{{vnetPeeringResources}}` / `{{vpcPeeringResources}}` - Peering configurations
454
455**Template Processor**:
456The template processor module (`template_processor.py`) generates placeholder content:
457- Variable/parameter declarations
458- Resource definitions with proper syntax
459- Hub-spoke peering logic
460- Provider-specific formatting
461
462Templates use simple string replacement for placeholders, maintaining exact output compatibility with TypeScript CLI.
463</templates_reference>
464
465<anti_patterns>
466<pitfall name="filling_entire_network">
467❌ Auto-calculating subnet size fills entire network, no room for growth
468✅ Use `--prefix` option to specify smaller subnets, leave address space for future
469</pitfall>
470
471<pitfall name="ignoring_provider_constraints">
472❌ Requesting /30 subnets in AWS (minimum is /28)
473✅ Check provider min/max CIDR prefixes before planning
474</pitfall>
475
476<pitfall name="uneven_az_distribution">
477❌ All subnets in single availability zone
478✅ Use automatic AZ distribution (AWS, GCP) for high availability
479</pitfall>
480
481<pitfall name="incorrect_reserved_ips">
482❌ Assuming standard 2 reserved IPs (network + broadcast)
483✅ Use provider-specific reserved counts (Azure: 5, AWS: 5, GCP: 4)
484</pitfall>
485
486<pitfall name="missing_hub_spoke_peering">
487❌ Creating hub and spoke VNets without peering configuration
488✅ Use `--spoke-cidrs` option to automatically generate peering
489</pitfall>
490
491<pitfall name="hardcoded_values">
492❌ Generated IaC templates with hardcoded names and regions
493✅ Templates include variables for customization
494</pitfall>
495</anti_patterns>
496
497<success_criteria>
498The skill successfully completes when:
499
500**For all providers and outputs**:
501- [ ] IP calculations are mathematically correct and deterministic
502- [ ] Provider constraints are enforced (CIDR prefix limits)
503- [ ] Reserved IPs calculated correctly for provider
504- [ ] Subnets fit within parent network
505- [ ] No CIDR blocks overlap
506- [ ] Multiple invocations with same input produce identical output
507- [ ] Output format matches user request
508
509**For AWS and GCP**:
510- [ ] Subnets distributed across availability zones using round-robin
511- [ ] AZ names match provider conventions
512
513**For hub-spoke topologies**:
514- [ ] Hub network calculated correctly
515- [ ] All spoke networks calculated correctly
516- [ ] Bidirectional peering configured for each spoke
517- [ ] No overlapping CIDRs between hub and spokes or between spokes
518
519**For IaC template outputs**:
520- [ ] Generated code passes syntax validation
521- [ ] Provider configuration is present and correct
522- [ ] Resource naming follows cloud provider conventions
523- [ ] Variables defined for customization
524- [ ] Outputs defined for resource IDs
525- [ ] Documentation included (IP allocation table in comments)
526- [ ] Hub-spoke peering resources complete (if applicable)
527
528**Compatibility**:
529- [ ] Output matches TypeScript CLI output for same inputs
530- [ ] Legacy compatibility maintained via `ipcalc_legacy.py`
531</success_criteria>