Skip to content

Add IPv6 support to cloudstack_network resource#282

Open
bhouse-nexthop wants to merge 1 commit intoapache:mainfrom
bhouse-nexthop:ipv6
Open

Add IPv6 support to cloudstack_network resource#282
bhouse-nexthop wants to merge 1 commit intoapache:mainfrom
bhouse-nexthop:ipv6

Conversation

@bhouse-nexthop
Copy link

@bhouse-nexthop bhouse-nexthop commented Mar 6, 2026

This commit adds comprehensive IPv6 support to the cloudstack_network resource,
allowing users to configure IPv6 CIDR blocks, gateways, and IP ranges for
CloudStack networks.

Fixes #232

New Features

Schema Fields

  • ip6cidr: IPv6 CIDR block for the network (e.g., "2001:db8::/64")
  • ip6gateway: IPv6 gateway address (optional, defaults to network address + 1)
  • startipv6: Starting IPv6 address for the IP range (optional)
  • endipv6: Ending IPv6 address for the IP range (optional)

Implementation Details

Network Creation (resourceCloudStackNetworkCreate)

  • Added IPv6 CIDR parsing and validation using parseCIDRv6() helper
  • Automatically calculates IPv6 gateway (defaults to network address + 1, e.g., 2001:db8::1)
  • Automatically generates IPv6 IP range when specifyiprange is enabled
  • Properly sets IPv6 parameters on CloudStack API calls

Network Read (resourceCloudStackNetworkRead)

  • Reads IPv6 CIDR and gateway from CloudStack API
  • Only sets IPv6 fields in state when they have non-empty values
  • Prevents unwanted plan diffs when IPv6 is not configured

Helper Function: parseCIDRv6

  • Parses IPv6 CIDR notation using Go's net.ParseCIDR
  • Calculates default gateway (network address + 1, e.g., prefix::1)
  • Generates start IP (network address + 2)
  • Generates end IP (last address in CIDR range using bitwise operations)
  • Supports custom gateway and IP range specification

Test Coverage

Acceptance Tests (3 new tests)

  • TestAccCloudStackNetwork_ipv6: Basic IPv6 network with ip6cidr
  • TestAccCloudStackNetwork_ipv6_vpc: IPv6 network within a VPC
  • TestAccCloudStackNetwork_ipv6_custom_gateway: IPv6 with custom gateway

Note: These tests skip gracefully on CloudStack simulator (error 4350) because
the simulator only supports IPv6 with advanced shared network offerings. Tests
will work correctly on real CloudStack environments with proper IPv6 support.

Unit Tests (5 new tests in resource_cloudstack_network_unit_test.go)

  • TestParseCIDRv6_DefaultGateway: Verifies default gateway calculation (network + 1)
  • TestParseCIDRv6_CustomGateway: Tests custom gateway specification
  • TestParseCIDRv6_WithIPRange: Tests automatic IP range generation
  • TestParseCIDRv6_CustomIPRange: Tests custom start/end IP specification
  • TestParseCIDRv6_SmallerPrefix: Tests different prefix lengths (/48, /64)

All unit tests pass and validate the IPv6 CIDR parsing logic independently
of the CloudStack API.

Documentation

Updated website/docs/r/network.html.markdown

  • Added IPv6 usage example showing ip6cidr configuration
  • Added ip6gateway to exported attributes reference with clear default behavior
  • Added gateway to exported attributes reference for completeness

Test Documentation

  • Added comments explaining IPv6 test limitations with simulator
  • Referenced unit tests for developers wanting to verify IPv6 logic

Usage Example

resource "cloudstack_network" "ipv6" {
  name             = "test-network-ipv6"
  cidr             = "10.0.0.0/16"
  ip6cidr          = "2001:db8::/64"
  network_offering = "Default Network"
  zone             = "zone-1"
}

The above example will create a network with:

  • IPv4: 10.0.0.0/16
  • IPv6: 2001:db8::/64
  • IPv6 Gateway: 2001:db8::1 (automatically calculated)

Verification

  • Build: Clean (no compilation errors)
  • Vet: Clean (no warnings)
  • Unit Tests: 5/5 passing
  • Acceptance Tests: 6/6 passing (existing), 3/3 skipping appropriately (IPv6)
  • All existing network tests continue to pass without regression

This was referenced Mar 6, 2026
This commit adds comprehensive IPv6 support to the cloudstack_network resource,
allowing users to configure IPv6 CIDR blocks, gateways, and IP ranges for
CloudStack networks.

## New Features

### Schema Fields
- ip6cidr: IPv6 CIDR block for the network (e.g., "2001:db8::/64")
- ip6gateway: IPv6 gateway address (optional, defaults to network address + 1)
- startipv6: Starting IPv6 address for the IP range (optional)
- endipv6: Ending IPv6 address for the IP range (optional)

### Implementation Details

#### Network Creation (resourceCloudStackNetworkCreate)
- Added IPv6 CIDR parsing and validation using parseCIDRv6() helper
- Automatically calculates IPv6 gateway (defaults to network address + 1, e.g., 2001:db8::1)
- Automatically generates IPv6 IP range when specifyiprange is enabled
- Properly sets IPv6 parameters on CloudStack API calls

#### Network Read (resourceCloudStackNetworkRead)
- Reads IPv6 CIDR and gateway from CloudStack API
- Only sets IPv6 fields in state when they have non-empty values
- Prevents unwanted plan diffs when IPv6 is not configured

#### Helper Function: parseCIDRv6
- Parses IPv6 CIDR notation using Go's net.ParseCIDR
- Calculates default gateway (network address + 1, e.g., prefix::1)
- Generates start IP (network address + 2)
- Generates end IP (last address in CIDR range using bitwise operations)
- Supports custom gateway and IP range specification

## Test Coverage

### Acceptance Tests (3 new tests)
- TestAccCloudStackNetwork_ipv6: Basic IPv6 network with ip6cidr
- TestAccCloudStackNetwork_ipv6_vpc: IPv6 network within a VPC
- TestAccCloudStackNetwork_ipv6_custom_gateway: IPv6 with custom gateway

Note: These tests skip gracefully on CloudStack simulator (error 4350) because
the simulator only supports IPv6 with advanced shared network offerings. Tests
will work correctly on real CloudStack environments with proper IPv6 support.

### Unit Tests (5 new tests in resource_cloudstack_network_unit_test.go)
- TestParseCIDRv6_DefaultGateway: Verifies default gateway calculation (network + 1)
- TestParseCIDRv6_CustomGateway: Tests custom gateway specification
- TestParseCIDRv6_WithIPRange: Tests automatic IP range generation
- TestParseCIDRv6_CustomIPRange: Tests custom start/end IP specification
- TestParseCIDRv6_SmallerPrefix: Tests different prefix lengths (/48, /64)

All unit tests pass and validate the IPv6 CIDR parsing logic independently
of the CloudStack API.

## Documentation

### Updated website/docs/r/network.html.markdown
- Added IPv6 usage example showing ip6cidr configuration
- Added ip6gateway to exported attributes reference with clear default behavior
- Added gateway to exported attributes reference for completeness

### Test Documentation
- Added comments explaining IPv6 test limitations with simulator
- Referenced unit tests for developers wanting to verify IPv6 logic

## Usage Example

```hcl
resource "cloudstack_network" "ipv6" {
  name             = "test-network-ipv6"
  cidr             = "10.0.0.0/16"
  ip6cidr          = "2001:db8::/64"
  network_offering = "Default Network"
  zone             = "zone-1"
}
```

The above example will create a network with:
- IPv4: 10.0.0.0/16
- IPv6: 2001:db8::/64
- IPv6 Gateway: 2001:db8::1 (automatically calculated)

## Verification

- Build: Clean (no compilation errors)
- Vet: Clean (no warnings)
- Unit Tests: 5/5 passing
- Acceptance Tests: 6/6 passing (existing), 3/3 skipping appropriately (IPv6)
- All existing network tests continue to pass without regression
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IPv6 Support

1 participant