Cross-Reference-Attributes

 Basic of Attributes

Each resource has its associated set of attributes. 

Attributes are the fields in a resource that hold the values that end up in the state


Cross reference Resource Attribute

Terraform allows us to reference the attribute of one resource to be used in a different resources. 


In the below example aws public ip address associated with security group 

resource "aws_eip" "lb" {
  domain   = "vpc"
}
resource "aws_security_group" "allow_tls" {
  name        = "allow_tls"
  description = "Allow TLS inbound traffic"
  ingress {
    description      = "TLS from VPC"
    from_port        = 443
    to_port          = 443
    protocol         = "tcp"
    cidr_blocks      = ["${aws_eip.lb.public_ip}/32"]
  }

Comments