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?

3 Answers 3


You can retrieve security group from data source

variable "security_group_id" {}

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

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" ]


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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.