Answers: <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>
  
Answers: CC BY-SA 4.0
Answers: 2019-03-15T00:19:06.720Z
Answers: 2019-03-15T00:19:06.720Z
Answers: myron-semack
Answers: <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>
  
Answers: CC BY-SA 4.0
Answers: 2019-03-14T04:22:52.033Z
Answers: 2019-03-14T04:22:52.033Z
Answers: Daniel Johns
Answers: <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>
  
Answers: CC BY-SA 4.0
Answers: 2019-03-14T10:14:45.720Z
Answers: 2019-03-14T10:14:45.720Z
Answers: Vasiliy  Shakhunov
Body: <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>
  
Tags: <terraform>
Title: Terraform - referencing existing security group
UserDisplayName: Daniel Johns
ThreadText: # 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](https://www.terraform.io/docs/providers/aws/d/security_group.html)
  
  ```
  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" ]
  
  
  ---
  
  