# Creating self-references in new security group rule resource types

**URL:** <https://discuss.hashicorp.com/t/creating-self-references-in-new-security-group-rule-resource-types/51188>\
**Category:** AWS\
**Tags:** hcp-terraform\
**Created:** [March 8, 2023, 9:58pm UTC](https://discuss.hashicorp.com/t/creating-self-references-in-new-security-group-rule-resource-types/51188 "2023-03-08T21:58:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gilesvessey](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/gilesvessey/32/34402_2.png) [@gilesvessey](https://discuss.hashicorp.com/u/gilesvessey)\
**Post date:** [March 8, 2023, 9:58pm UTC](https://discuss.hashicorp.com/t/creating-self-references-in-new-security-group-rule-resource-types/51188/1 "2023-03-08T21:58:55Z")

</div>

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](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule#self)

However I don’t see such a thing for [Terraform Registry](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_security_group_ingress_rule)

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?

---

<div class="post-metadata">

**Author:** ![gilesvessey](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/gilesvessey/32/34402_2.png) [@gilesvessey](https://discuss.hashicorp.com/u/gilesvessey)\
**Post date:** [March 28, 2023, 1:08am UTC](https://discuss.hashicorp.com/t/creating-self-references-in-new-security-group-rule-resource-types/51188/2 "2023-03-28T01:08:43Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![FlorinAndrei](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/florinandrei/32/23565_2.png) [@FlorinAndrei](https://discuss.hashicorp.com/u/FlorinAndrei)\
**Post date:** [September 19, 2025, 7:43pm UTC](https://discuss.hashicorp.com/t/creating-self-references-in-new-security-group-rule-resource-types/51188/4 "2025-09-19T19:43:16Z")

</div>

@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.
