bhouse-nexthop commented on code in PR #280:
URL:
https://github.com/apache/cloudstack-terraform-provider/pull/280#discussion_r3783568011
##########
cloudstack/resource_cloudstack_network_acl.go:
##########
@@ -70,9 +71,25 @@ func resourceCloudStackNetworkACLCreate(d
*schema.ResourceData, meta interface{}
cs := meta.(*cloudstack.CloudStackClient)
name := d.Get("name").(string)
+ vpcID := d.Get("vpc_id").(string)
+
+ // If no project is explicitly set, try to inherit it from the VPC
+ // and set it in the state so the Read function can use it
+ if _, ok := d.GetOk("project"); !ok {
+ // Get the VPC to retrieve its project
+ // Use projectid=-1 to search across all projects
+ vpc, count, err := cs.VPC.GetVPCByID(vpcID,
cloudstack.WithProject("-1"))
+ if err == nil && count > 0 && vpc.Projectid != "" {
+ log.Printf("[DEBUG] Inheriting project %s from VPC %s",
vpc.Projectid, vpcID)
+ // Set the project in the resource data for state
management
+ d.Set("project", vpc.Project)
+ }
Review Comment:
Fixed in 1be6cbb.
Rather than changing what the create path writes, I fixed the actual failure
mode in `resourceCloudStackNetworkACLRead`: it now retries
`GetNetworkACLListByID` with `WithProject("-1")` when the state `project` is
empty and the first lookup found nothing, matching the fallback already used by
the network/instance/ipaddress resources in this PR. That covers the
ID-without-name case you describe as well as pre-existing state and imports,
and the existing derive-project-from-VPC block then populates `project` from
the real object.
##########
cloudstack/resource_cloudstack_port_forward.go:
##########
@@ -234,10 +249,11 @@ func resourceCloudStackPortForwardRead(d
*schema.ResourceData, meta interface{})
cs := meta.(*cloudstack.CloudStackClient)
// First check if the IP address is still associated
- _, count, err := cs.Address.GetPublicIpAddressByID(
+ ip, count, err := cs.Address.GetPublicIpAddressByID(
d.Id(),
cloudstack.WithProject(d.Get("project").(string)),
)
Review Comment:
Good catch - fixed in 1be6cbb. `resourceCloudStackPortForwardRead` now
retries the IP lookup with `WithProject("-1")` when the state `project` is
empty and the first lookup returned nothing, same as the
network/instance/ipaddress resources. The existing `setValueOrID(d, "project",
ip.Project, ip.Projectid)` then backfills the project into state.
--
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]