Query existing infrastructure data for use in resources.

Section: Dynamic Blocks and Data Sources

Data source example

hcl
hcl
data "aws_ami" "ubuntu" {
  most_recent = true
  owners      = ["099720109477"]

  filter {
    name   = "name"
    values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"]
  }
}
Explanation

Query existing infrastructure data for use in resources.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Dynamic Blocks and Data Sources
Dynamic block
Generate repeated nested blocks from input data.
OpenIn sheethclsame section
String variable
Declare a typed string variable.
OpenIn sheethcl1 tag match
Use count
Create multiple similar resources with count.
OpenIn sheethcl1 tag match
Conditional expression
Choose values conditionally.
OpenIn sheethcl1 tag match
Object variable
Declare a typed object variable.
OpenIn sheethcl1 tag match
Use for_each
Create resources keyed by map/set members.
OpenIn sheethcl1 tag match