Note_Tech

All technological notes.


Project maintained by simonangel-fong Hosted on GitHub Pages — Theme by mattgraham

Terraform - Data Source

Back


Data Source

data data_source ds_name {
    # query constraints
}

Custom Condition Checks

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\"."
    }
  }
}

Common Data Source

# 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
}