Interpolation Syntax

In this lesson, we'll discuss the attributes a resource returns and will go through an example project to understand attributes reference.

Useful resource output

Once a resource is created, it returns a number of attributes. The attributes a resource returns can be found in the “Attributes Reference” section on the documentation page for any resource. This is amazingly useful as it allows you to use the output from one resource as the argument for another resource.

Project example

Consider the following project:



provider "aws" {
    region = "us-east-2"
}

resource "aws_vpc" "my_vpc" {
    cidr_block = "10.0.0.0/16"
}

resource "aws_security_group" "my_security_group" {
    vpc_id = aws_vpc.my_vpc.id
    name = "Example security group"
}

resource "aws_security_group_rule" "tls_in" {
    protocol = "tcp"
    security_group_id = aws_security_group.my_security_group.id
    from_port = 443
    to_port = 443
    type = "ingress"
    cidr_blocks = ["0.0.0.0/0"]
}
Create AWS VPC with CIDR block using this project

This project creates an AWS VPC with CIDR block 10.0.0.0/16. Then it defines a security group (aws_security_group). Notice that the value of vpc_id is set to aws_vpc.my_vpc.id in the definition of the ...