Data Source: aws_security_group

aws_security_group provides details about a specific Security Group.

This resource can prove useful when a module accepts a Security Group id as an input variable and needs to, for example, determine the id of the VPC that the security group belongs to.

Example Usage

The following example shows how one might accept a Security Group id as a variable and use this data source to obtain the data necessary to create a subnet.

variable "security_group_id" {}

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

resource "aws_subnet" "subnet" {
  vpc_id     = data.aws_security_group.selected.vpc_id
  cidr_block = "10.0.1.0/24"
}

Argument Reference

The arguments of this data source act as filters for querying the available security group in the current region. The given filters must match exactly one security group whose data will be exported as attributes.

More complex filters can be expressed using one or more filter sub-blocks, which take the following arguments:

Attribute Reference

All of the argument attributes except filter blocks are also exported as result attributes. This data source will complete the data by populating any fields that are not included in the configuration with the data for the selected Security Group.

The following fields are also exported:

Timeouts

Configuration options: