All technological notes.
Data sources
data sources correspond to an infrastructure object type that is accessed via a remote network APIsome specialized data sources operate only within Terraform itself, calculating some results and exposing them for use elsewhere.
How it works
data resources during the planning phase when possible, but announces in the plan when it must defer reading resources until the apply phase to preserve the order of operations.data blockdata data_source ds_name {
# query constraints
}
cause Terraform to read from a given data source (“data_source”) and export the result under the given local name (“ds_name”).
precondition and postcondition blocks to specify assumptions and guarantees about how the data source operates.data "aws_ami" "example" {
id = var.aws_ami_id
lifecycle {
# The AMI ID must refer to an existing AMI that has the tag "nomad-server".
postcondition {
condition = self.tags["Component"] == "nomad-server"
error_message = "tags[\"Component\"] must be \"nomad-server\"."
}
}
}
# caller identity details, such as account ID and ARN, for the current AWS account.
data "aws_caller_identity" "current" {}
# current AWS region
data "aws_region" "current" {}
# list of availability zones available in the current AWS region
data "aws_availability_zones" "current" {}
# get an existing remote s3 state
data "terraform_remote_state" "s3_remote_state"{
backend = "s3"
config = {
bucket = "bucket_name"
key = "key_name"
region = "region_name"
}
}
# output vpc
output "remote_state_vpc_id" {
value = data.terraform_remote_state.s3_remote_state.vpc_id
}