Skip to content

Data Source: aws_security_groups#

Provides information about IDs of security groups and their association to any VPC.

Example usage#

Basic example#

data "aws_security_groups" "test" {
  tags = {
    Application = "k8s"
    Environment = "dev"
  }
}

Specific example#

variable vpc_id {}

data "aws_security_groups" "test" {
  filter {
    name   = "group-name"
    values = ["nodes"]
  }

  filter {
    name   = "vpc-id"
    values = [var.vpc_id]
  }
}

Argument reference#

  • filter - (Optional, Block) One or more name/value pairs to use as filters.
  • tags - (Optional, Map of strings) Key-value pairs. Must exactly match pairs on the required resources.

filter#

  • name - (Required, String) The name of the filter.
    • Constraints: Filter names are case-sensitive
  • values - (Required, List of strings) One or more filter values.
    • Constraints: Filter values are case-sensitive

Attribute reference#

In addition to all arguments above, the following attributes are exported:

  • arns - (String) The Amazon Resource Names (ARNs) of the matched security groups.
  • id - (String) The region.
    • Example: ru-spb
  • ids - (List of strings) The IDs of the matched security groups.
  • vpc_ids - (String) The VPC IDs of the matched security groups. The data source's tag or filter will span VPCs unless the vpc-id filter is also used.