Skip to content

Commit 8fa8d12

Browse files
committed
fix test
1 parent ed26472 commit 8fa8d12

3 files changed

Lines changed: 16 additions & 12 deletions

File tree

cloudstack/data_source_cloudstack_network_offering.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,12 @@ func datasourceCloudStackNetworkOfferingRead(d *schema.ResourceData, meta interf
149149
}
150150
log.Printf("[DEBUG] Selected network offerings: %s\n", networkOffering.Displaytext)
151151

152-
return networkOfferingDescriptionAttributes(d, networkOffering)
152+
fullNetworkOffering, _, err := cs.NetworkOffering.GetNetworkOfferingByName(networkOffering.Name)
153+
if err != nil {
154+
return fmt.Errorf("Error retrieving full network offering details: %s", err)
155+
}
156+
157+
return networkOfferingDescriptionAttributes(d, fullNetworkOffering)
153158
}
154159

155160
func networkOfferingDescriptionAttributes(d *schema.ResourceData, networkOffering *cloudstack.NetworkOffering) error {
@@ -169,7 +174,10 @@ func networkOfferingDescriptionAttributes(d *schema.ResourceData, networkOfferin
169174
d.Set("specify_as_number", networkOffering.Specifyasnumber)
170175
d.Set("internet_protocol", networkOffering.Internetprotocol)
171176
d.Set("routing_mode", networkOffering.Routingmode)
172-
d.Set("max_connections", networkOffering.Maxconnections)
177+
178+
if networkOffering.Maxconnections > 0 {
179+
d.Set("max_connections", networkOffering.Maxconnections)
180+
}
173181

174182
// Set supported services
175183
if len(networkOffering.Service) > 0 {

cloudstack/data_source_cloudstack_network_offering_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ resource "cloudstack_network_offering" "net-off-resource"{
205205
guest_ip_type = "Isolated"
206206
traffic_type = "Guest"
207207
enable = true
208-
max_connections = 256
209208
supported_services = ["Dhcp", "Dns", "Firewall", "Lb", "SourceNat", "StaticNat", "PortForwarding"]
210209
service_provider_list = {
211210
Dhcp = "VirtualRouter"

cloudstack/resource_cloudstack_network_offering.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,6 @@ func resourceCloudStackNetworkOfferingRead(d *schema.ResourceData, meta interfac
350350
d.Set("guest_ip_type", n.Guestiptype)
351351
d.Set("traffic_type", n.Traffictype)
352352

353-
// Only set optional attributes if they were specified in the configuration
354353
if _, ok := d.GetOk("network_rate"); ok {
355354
d.Set("network_rate", n.Networkrate)
356355
}
@@ -384,15 +383,14 @@ func resourceCloudStackNetworkOfferingRead(d *schema.ResourceData, meta interfac
384383
if _, ok := d.GetOk("routing_mode"); ok {
385384
d.Set("routing_mode", n.Routingmode)
386385
}
387-
// Set max_connections if it was specified in the configuration
388-
// Note: CloudStack may return 0 even when a value was set, so we preserve the configured value
389-
if configuredMaxConn := d.Get("max_connections").(int); configuredMaxConn != 0 {
390-
d.Set("max_connections", configuredMaxConn)
391-
} else if n.Maxconnections != 0 {
392-
d.Set("max_connections", n.Maxconnections)
386+
if _, ok := d.GetOk("max_connections"); ok {
387+
log.Printf("[DEBUG] Max connections configured: %d, CloudStack returned: %d", d.Get("max_connections").(int), n.Maxconnections)
388+
389+
if n.Maxconnections > 0 {
390+
d.Set("max_connections", n.Maxconnections)
391+
}
393392
}
394393

395-
// Set supported services if specified
396394
if _, ok := d.GetOk("supported_services"); ok && len(n.Service) > 0 {
397395
services := make([]string, len(n.Service))
398396
for i, service := range n.Service {
@@ -401,7 +399,6 @@ func resourceCloudStackNetworkOfferingRead(d *schema.ResourceData, meta interfac
401399
d.Set("supported_services", services)
402400
}
403401

404-
// Set service provider list if specified
405402
if _, ok := d.GetOk("service_provider_list"); ok && len(n.Service) > 0 {
406403
serviceProviders := make(map[string]string)
407404
for _, service := range n.Service {

0 commit comments

Comments
 (0)