Search code examples
amazon-web-servicesterraformaws-security-group

how to select a security-group id for the source when creating a security group in AWS with terraform


In the AWS console when you are creating a security group you can select a security group ID for the source IP (inbound rule). Is it possible to do this in terraform, and if so how would you do this?

AWS Console


Solution

  • You can use the aws_security_group_rule described here https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule It has a source_security_group_id field where you can specify the security group you want to allow traffic from.

    Before that you'd probably create the security group with the aws_security_group resource https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group. And you can the pass the id of this security group in the security_group_id field of the aws_security_group_rule resource.