<p>You can use the <em>terraform import</em> command to import the security group so you can reference it as a created Terraform resource. </p>

<p><a href="https://www.terraform.io/docs/providers/aws/r/security_group.html" rel="nofollow noreferrer">https://www.terraform.io/docs/providers/aws/r/security_group.html</a></p>

CC BY-SA 4.0
2019-03-15T00:19:06.720Z
2019-03-15T00:19:06.720Z
myron-semack
<p>I didn't use list square brackets, the functionality is there as documented, just list brackets and group id.
e.g.:
vpc_security_group_ids          = [ "sg-dfe8e2bf" ]</p>

CC BY-SA 4.0
2019-03-14T04:22:52.033Z
2019-03-14T04:22:52.033Z
Daniel Johns
<p>You can retrieve security group from <a href="https://www.terraform.io/docs/providers/aws/d/security_group.html" rel="nofollow noreferrer">data source</a></p>

<pre><code>variable "security_group_id" {}

data "aws_security_group" "selected" {
  id = "${var.security_group_id}"
}
</code></pre>

CC BY-SA 4.0
2019-03-14T10:14:45.720Z
2019-03-14T10:14:45.720Z
Vasiliy  Shakhunov
<p>Is there a way I can associate existing security group to RDS that is going to be created or the only way is to recreate the security group so it can be added to the state file?</p>

<terraform>
Terraform - referencing existing security group
Daniel Johns
# Terraform - referencing existing security group

(Asked by: username_0 on 2019-03-14)

Is there a way I can associate existing security group to RDS that is going to be created or the only way is to recreate the security group so it can be added to the state file?

**Tags:** terraform


---

## 3 answers

### Answer by username_2 on 2019-03-14. Score: 3 | Accepted answer

You can retrieve security group from data source
variable "security_group_id" {}

data "aws_security_group" "selected" {
  id = "${var.security_group_id}"
}


---

### Answer by username_1 on 2019-03-15. Score: 0

You can use the *terraform import* command to import the security group so you can reference it as a created Terraform resource.

<https://www.terraform.io/docs/providers/aws/r/security_group.html>


---

### Answer by username_0 on 2019-03-14. Score: 0

I didn't use list square brackets, the functionality is there as documented, just list brackets and group id.
e.g.:
vpc\_security\_group\_ids = [ "sg-dfe8e2bf" ]


---

