Creating self-references in new security group rule resource types

Context - I want to move my aws_security_group_rule resources to aws_vpc_security_group_ingress_rule/ aws_vpc_security_group_egress_rule so I can start tagging my rules.

The older resource type has a handy property for creating a self-reference (the SG accepts from its own SG ID) Terraform Registry

However I don’t see such a thing for Terraform Registry

My first thought was to supply

referenced_security_group_id = resource.aws_vpc_security_group_ingress_rule.ec2_self_1.id

However as I expected, terraform did not like me referencing something in its self.

My question is, how can I achieve a self referential rule using the new resource types?

It helps when you don’t try to put a rule ID where a security group ID ought be - it’s what I meant but not what I wrote. disregard :slight_smile:

@fabien.delpierre Your solution works if you write the Terraform module yourself.

But there are modules out there that you could reference in your code, and are useful, but have no provision to reflect the security group ID back to the rule itself, to simulate the self argument. Getting those modules to change is not always feasible, as the code is controlled by someone else.

For this reason, having an explicit self argument for the new SG rule resources (both ingress and egress) would be very useful.