Copilot commented on code in PR #280:
URL:
https://github.com/apache/cloudstack-terraform-provider/pull/280#discussion_r3636090467
##########
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:
`resourceCloudStackPortForwardRead` scopes the IP lookup to
`WithProject(d.Get("project"))`. For existing state where `project` is empty
(common when upgrading from older state or after import), project-scoped IPs
will return count==0 and the resource will be dropped from state. Other
resources (instance/network/ipaddress) handle this by retrying with
`WithProject("-1")` when no project is set.
##########
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:
Project inheritance checks `vpc.Projectid != ""` but then writes
`vpc.Project` to state. If the VPC lookup returns an ID but not a name,
`project` remains empty and the Read call that scopes by `project` can fail to
find the ACL list, clearing it from state.
This issue also appears on line 116 of the same file.
--
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]