Skip to content

Commit

Permalink
check if server supports network zones
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis Mandravellos committed Oct 10, 2023
1 parent eb4e59f commit 7c2e577
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lxd/resource_lxd_network_zone.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package lxd

import (
"fmt"
"log"

"github.com/canonical/lxd/shared/api"
Expand Down Expand Up @@ -58,6 +59,14 @@ func resourceLxdNetworkZoneCreate(d *schema.ResourceData, meta interface{}) erro
return err
}

netZoneExt := "projects_networks_zones"
if !server.HasExtension(netZoneExt) {
return fmt.Errorf(
"Network zones cannot be used because LXD server does not support %q extension",
netZoneExt,
)
}

if v, ok := d.GetOk("project"); ok && v != "" {
project := v.(string)
server = server.UseProject(project)
Expand Down Expand Up @@ -92,6 +101,14 @@ func resourceLxdNetworkZoneRead(d *schema.ResourceData, meta interface{}) error
return err
}

netZoneExt := "projects_networks_zones"
if !server.HasExtension(netZoneExt) {
return fmt.Errorf(
"Network zones cannot be used because LXD server does not support %q extension",
netZoneExt,
)
}

if v, ok := d.GetOk("project"); ok && v != "" {
project := v.(string)
server = server.UseProject(project)
Expand Down

0 comments on commit 7c2e577

Please sign in to comment.