Add IPv6 support to cloudstack_network resource#282
Open
bhouse-nexthop wants to merge 1 commit intoapache:mainfrom
Open
Add IPv6 support to cloudstack_network resource#282bhouse-nexthop wants to merge 1 commit intoapache:mainfrom
bhouse-nexthop wants to merge 1 commit intoapache:mainfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Implementation Details
Network Creation (resourceCloudStackNetworkCreate)
Network Read (resourceCloudStackNetworkRead)
Helper Function: parseCIDRv6
Test Coverage
Acceptance Tests (3 new tests)
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)
All unit tests pass and validate the IPv6 CIDR parsing logic independently
of the CloudStack API.
Documentation
Updated website/docs/r/network.html.markdown
Test Documentation
Usage Example
The above example will create a network with:
Verification