How to display when a Data Source is fetched during "terraform plan/apply"?

Question: Is there a way to display when a Data Source is fetched during terraform plan or terraform apply?

I remember from old versions of Terraform, when we ran terraform plan or terraform apply, we saw when Data Sources were fetched.

Rationale: When developing data sources or troubleshooting data sources, it is useful to see exactly WHEN they are fetched (sometimes, order matters).

I know that I can do:

TF_LOG=DEBUG terraform plan

but it’s VERY verbose for just checking the order and when the data sources are fetched.

Thanks,

Hi @samuel-phan,

Terraform always reads data sources during the plan when possible. If the data source depends on values which are unknown during the plan, then the plan output will show the data source with a line like:
# data.data_source.example will be read during apply
along with all its attributes being shown as (known after apply)

Hi @jbardin ,

Sorry, maybe my question was not clear enough.

Let’s say I have a main.tf file like this:

provider "aws" {
  region = "us-east-1"
}

data "aws_vpc" "default" {
  tags = {
    Name = "main-us-east-1"
  }
}

resource "aws_security_group" "sg" {
  vpc_id = data.aws_vpc.default.id

  ingress {
    description     = "SSH"
    protocol        = "tcp"
    from_port       = 22
    to_port         = 22
    cidr_blocks     = ["0.0.0.0/0"]
  }

  egress {
    description = "egress all"
    protocol    = "all"
    from_port   = 0
    to_port     = 0
    cidr_blocks = ["0.0.0.0/0"]
  }

When I run terraform apply, I see this:

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

aws_security_group.sg: Creating...
aws_security_group.sg: Creation complete after 4s [id=sg-04fa708c5de871ab9]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Nowhere, I see that TF has fetched the Data Source data.aws_vpc.default, and more importantly, WHEN it did so. In a more complex stack, it can be important to be able to see it.

In older TF versions, I remember that the Data Sources fetch actions were displayed during terraform plan or terraform apply.

I would be curious if there is a way to have a flag to add it back. For example:

terraform plan -show-data-sources=true
terraform apply -show-data-sources=true

And having something like this:

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

data.aws_vpc.default: Fetching... <-- Data source fetching...
aws_security_group.sg: Creating...
aws_security_group.sg: Creation complete after 4s [id=sg-04fa708c5de871ab9]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

OK, I see what you mean, there is no cli output when the data source is read during the plan, which is probably an oversight that no one has caught, since that is where it is always assumed to be read unless otherwise noted.

The output you are referring to doesn’t definitively show the order actions are being applied, since many things can be happening concurrently, so I wound’t rely on it for determining the absolute ordering of resources.