-
Notifications
You must be signed in to change notification settings - Fork 58
fix: make cidr optional for L2 network creation #289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -74,7 +74,8 @@ func resourceCloudStackNetwork() *schema.Resource { | |||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| "cidr": { | ||||||||||||||||||||||||||||||||
| Type: schema.TypeString, | ||||||||||||||||||||||||||||||||
| Required: true, | ||||||||||||||||||||||||||||||||
| Optional: true, | ||||||||||||||||||||||||||||||||
| Computed: true, | ||||||||||||||||||||||||||||||||
|
Damans227 marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||
| ForceNew: true, | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
@@ -190,23 +191,25 @@ func resourceCloudStackNetworkCreate(d *schema.ResourceData, meta interface{}) e | |||||||||||||||||||||||||||||||
| return err | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| m, err := parseCIDR(d, no.Specifyipranges) | ||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||
| return err | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| if _, ok := d.GetOk("cidr"); ok { | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
| if _, ok := d.GetOk("cidr"); ok { | |
| _, cidrConfigured := d.GetOk("cidr") | |
| if !cidrConfigured { | |
| if _, ok := d.GetOk("gateway"); ok { | |
| return fmt.Errorf("cidr must be specified when gateway is configured") | |
| } | |
| if _, ok := d.GetOk("startip"); ok { | |
| return fmt.Errorf("cidr must be specified when startip is configured") | |
| } | |
| if _, ok := d.GetOk("endip"); ok { | |
| return fmt.Errorf("cidr must be specified when endip is configured") | |
| } | |
| } | |
| if cidrConfigured { |
Copilot
AI
Apr 2, 2026
There was a problem hiding this comment.
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
AI
Apr 2, 2026
There was a problem hiding this comment.
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).
Uh oh!
There was an error while loading. Please reload this page.