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.
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"]
}
has_computed_default
(String) If set, its literal value will be stored and returned. If not, its value defaults to "default"
. This argument exists primarily for testing and has little practical use.inputs
(Map of String) A map of arbitrary strings that is copied into the outputs
attribute, and accessible directly for interpolation.id
(String, Deprecated) This attribute is only present for some legacy compatibility issues and should not be used. It will be removed in a future version.outputs
(Map of String) After the data source is "read", a copy of the inputs
map.random
(String) A random value. This is primarily for testing and has little practical use; prefer the hashicorp/random provider for more practical random number use-cases.