Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions cloudstack/resource_cloudstack_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ func resourceCloudStackInstance() *schema.Resource {
Optional: true,
Computed: true,
ForceNew: true,
ConflictsWith: []string{"network_ids"},
},

"network_ids": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
ConflictsWith: []string{"network_id"},
},

"ip_address": {
Expand Down Expand Up @@ -307,6 +315,14 @@ func resourceCloudStackInstanceCreate(d *schema.ResourceData, meta interface{})
p.SetNetworkids([]string{d.Get("network_id").(string)})
}

if networks, ok := d.GetOk("network_ids"); ok {
var networkIds []string
for _, nw := range networks.([]interface{}) {
networkIds = append(networkIds, fmt.Sprintf("%v", nw))
Copy link
Preview

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

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

Using fmt.Sprintf with %v is unnecessary and potentially unsafe for type conversion. Since the schema defines the element type as TypeString, cast directly to string: networkIds = append(networkIds, nw.(string))

Suggested change
networkIds = append(networkIds, fmt.Sprintf("%v", nw))
networkIds = append(networkIds, nw.(string))

Copilot uses AI. Check for mistakes.

}
p.SetNetworkids(networkIds);
Copy link
Preview

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

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

Remove the semicolon at the end of the line. Go does not require semicolons at the end of statements.

Suggested change
p.SetNetworkids(networkIds);
p.SetNetworkids(networkIds)

Copilot uses AI. Check for mistakes.

}

// If there is a ipaddres supplied, add it to the parameter struct
if ipaddress, ok := d.GetOk("ip_address"); ok {
p.SetIpaddress(ipaddress.(string))
Expand Down