Skip to content

Data Source: awsEbsVolumes

awsEbsVolumes provides identifying information for EBS volumes matching given criteria.

This data source can be useful for getting a list of volume IDs with (for example) matching tags.

Example Usage

The following demonstrates obtaining a map of availability zone to EBS volume ID for volumes with a given tag value.

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";
const dataAwsEbsVolumesExample = new aws.dataAwsEbsVolumes.DataAwsEbsVolumes(
  this,
  "example",
  {
    tags: {
      VolumeSet: "TestVolumeSet",
    },
  }
);
const dataAwsEbsVolumeExample = new aws.dataAwsEbsVolume.DataAwsEbsVolume(
  this,
  "example_1",
  {
    filter: [
      {
        name: "volume-id",
        values: ["${each.value}"],
      },
    ],
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
dataAwsEbsVolumeExample.overrideLogicalId("example");
/*In most cases loops should be handled in the programming language context and 
not inside of the Terraform context. If you are looping over something external, e.g. a variable or a file input
you should consider using a for loop. If you are looping over something only known to Terraform, e.g. a result of a data source
you need to keep this like it is.*/
dataAwsEbsVolumeExample.addOverride("for_each", dataAwsEbsVolumesExample.ids);
new cdktf.TerraformOutput(this, "availability_zone_to_volume_id", {
  value: `\${{ for s in ${dataAwsEbsVolumeExample} : s.id => s.availability_zone }}`,
});

Argument Reference

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

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

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. For example, if matching against the size filter, use:
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.dataAwsEbsVolumes.DataAwsEbsVolumes(this, "ten_or_twenty_gb_volumes", {
  filter: [
    {
      name: "size",
      values: ["10", "20"],
    },
  ],
});
  • values - (Required) Set of values that are accepted for the given field. EBS Volume IDs will be selected if any one of the given values match.

Attributes Reference

  • id - AWS Region.
  • ids - Set of all the EBS Volume IDs found. This data source will fail if no volumes match the provided criteria.

Timeouts

Configuration options:

  • read - (Default 20M)