touljaboy commented on code in PR #362:
URL:
https://github.com/apache/cloudstack-terraform-provider/pull/362#discussion_r4754096089
##########
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
+ }
+ count = l.Count
+ if count > 0 {
+ n = l.Networks[0]
+ }
+ } else {
+ // 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("-1"),
+ cloudstack.WithProject(project),
Review Comment:
Fixed in 2fdaab4 - added WithListall(true) to both GetNetworkByID attempts.
Also added TestAccCloudStackNetwork_importAccount in fbe976d, which imports a
network owned by an account in a non-root child domain by ID only, to cover
this path.
--
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]