null_data_source

The null_data_source data source implements the standard data source lifecycle but does not interact with any external APIs.

Historically, the null_data_source was typically used to construct intermediate values to re-use elsewhere in configuration. The same can now be achieved using locals or the terraform_data resource type in Terraform 1.4 and later.

Example Usage

resource "aws_instance" "green" {
  count         = 3
  ami           = "ami-0dcc1e21636832c5d"
  instance_type = "m5.large"

  # ...
}

resource "aws_instance" "blue" {
  count         = 3
  ami           = "ami-0dcc1e21636832c5d"
  instance_type = "m5.large"

  # ...
}

data "null_data_source" "values" {
  inputs = {
    all_server_ids = concat(
      aws_instance.green[*].id,
      aws_instance.blue[*].id,
    )
    all_server_ips = concat(
      aws_instance.green[*].private_ip,
      aws_instance.blue[*].private_ip,
    )
  }
}

resource "aws_elb" "main" {
  instances = data.null_data_source.values.outputs["all_server_ids"]

  # ...
  listener {
    instance_port     = 8000
    instance_protocol = "http"
    lb_port           = 80
    lb_protocol       = "http"
  }
}

output "all_server_ids" {
  value = data.null_data_source.values.outputs["all_server_ids"]
}

output "all_server_ips" {
  value = data.null_data_source.values.outputs["all_server_ips"]
}

Schema

Optional

Read-Only