touljaboy commented on code in PR #362:
URL:
https://github.com/apache/cloudstack-terraform-provider/pull/362#discussion_r4754089514
##########
cloudstack/resource_cloudstack_network.go:
##########
@@ -407,31 +431,58 @@ func resourceCloudStackNetworkCreate(d
*schema.ResourceData, meta interface{}) e
func resourceCloudStackNetworkRead(d *schema.ResourceData, meta interface{})
error {
cs := meta.(*cloudstack.CloudStackClient)
- // Get the network details
- // First try with the project from state (if any)
- project := d.Get("project").(string)
- n, count, err := cs.Network.GetNetworkByID(
- d.Id(),
- cloudstack.WithProject(project),
- )
-
- // If not found and no explicit project was set, try with projectid=-1
- // This handles the case where the project was inherited from VPC
- if count == 0 && project == "" {
+ var n *cloudstack.Network
+ var count int
+ var err error
+
+ if account, ok := d.GetOk("account"); ok {
+ // GetNetworkByID's plain listNetworks call only returns
resources
+ // visible to the caller's own default scope - a network created
+ // (e.g. by a root admin) under a different account is
invisible to
+ // it unless account/domainid/listall are set explicitly.
+ p := cs.Network.NewListNetworksParams()
+ p.SetId(d.Id())
+ p.SetAccount(account.(string))
+ if domainID, ok := d.GetOk("domain_id"); ok {
+ p.SetDomainid(domainID.(string))
+ }
+ p.SetListall(true)
+
+ l, listErr := cs.Network.ListNetworks(p)
+ if listErr != nil {
+ return listErr
+ }
Review Comment:
Fixed in 2fdaab4 - the account-scoped read now checks for the same not-found
error string GetNetworkByID normalizes, and clears the ID instead of returning
the error.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]