Skip to content

fix: make cidr optional for L2 network creation#289

Open
Damans227 wants to merge 1 commit intoapache:mainfrom
Damans227:fix-l2-network-cidr-optional
Open

fix: make cidr optional for L2 network creation#289
Damans227 wants to merge 1 commit intoapache:mainfrom
Damans227:fix-l2-network-cidr-optional

Conversation

@Damans227
Copy link
Copy Markdown
Contributor

The cidr field was marked as Required in the Terraform provider's schema for cloudstack_network, but the CloudStack createNetwork API only requires name, networkOfferingId, and zoneId. gateway and netmask are optional and unnecessary for L2 networks.

This change makes cidr optional and conditionally applies the CIDR/gateway/netmask logic only when a CIDR is provided.

An acceptance test has been added to verify L2 network creation without CIDR.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the cloudstack_network Terraform resource to support creating L2 networks without requiring a CIDR, aligning the provider schema with CloudStack’s createNetwork API requirements.

Changes:

  • Made cidr optional in the cloudstack_network schema.
  • Applied gateway/netmask/IP-range parameter logic only when cidr is provided.
  • Added an acceptance test that creates an L2 network without specifying cidr.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
cloudstack/resource_cloudstack_network.go Makes cidr optional and gates CIDR-derived network parameter setting behind a presence check.
cloudstack/resource_cloudstack_network_test.go Adds an acceptance test for L2 network creation without CIDR.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +193 to +197
if _, ok := d.GetOk("cidr"); ok {
m, err := parseCIDR(d, no.Specifyipranges)
if err != nil {
return err
}
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that cidr is optional, users can set gateway/startip/endip without setting cidr. In that case this block is skipped and those arguments are silently ignored, which can lead to confusing behavior and perpetual diffs (e.g., config sets gateway but API/state stays empty). Consider validating that gateway, startip, and endip may only be set when cidr is also set (e.g., schema RequiredWith/ConflictsWith or an explicit check in Create returning a clear error).

Copilot uses AI. Check for mistakes.
Comment on lines +193 to +195
if _, ok := d.GetOk("cidr"); ok {
m, err := parseCIDR(d, no.Specifyipranges)
if err != nil {
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With cidr optional, GetNetworkOfferingByID is only needed when cidr is present (to read Specifyipranges for parseCIDR). To avoid an extra API call on L2/no-cidr networks, consider moving the network-offering lookup inside the cidr conditional block.

Copilot uses AI. Check for mistakes.
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.

2 participants