Skip to content

Data Source: awsSecurityGroup

awsSecurityGroup 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.

import * as cdktf from "cdktf";
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
/*Terraform Variables are not always the best fit for getting inputs in the context of Terraform CDK.
You can read more about this at https://cdk.tf/variables*/
const securityGroupId = new cdktf.TerraformVariable(
  this,
  "security_group_id",
  {}
);
const dataAwsSecurityGroupSelected =
  new aws.dataAwsSecurityGroup.DataAwsSecurityGroup(this, "selected", {
    id: securityGroupId.value,
  });
new aws.subnet.Subnet(this, "subnet", {
  cidrBlock: "10.0.1.0/24",
  vpcId: dataAwsSecurityGroupSelected.vpcId,
});

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.

  • filter - (Optional) Custom filter block as described below.

  • id - (Optional) Id of the specific security group to retrieve.

  • name - (Optional) Name that the desired security group must have.

  • tags - (Optional) Map of tags, each pair of which must exactly match a pair on the desired security group.

  • vpcId - (Optional) Id of the VPC that the desired security group belongs to.

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

  • name - (Required) Name of the field to filter by, as defined by the underlying AWS API.

  • values - (Required) Set of values that are accepted for the given field. A Security Group will be selected if any one of the given values matches.

Attributes 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:

  • description - Description of the security group.
  • arn - Computed ARN of the security group.

\~> Note: The default security group for a VPC has the name default.

Timeouts

Configuration options:

  • read - (Default 20M)