How to use one file value to another file in terraform


#1

I have two terraform file test1.tf and test2.tf.

My requirement is i have one value in test1.tf (e.g id=123). How to refer this id in the file test2.tf.

Please let us know how to do this in terraform. My sample .tf file as below.

/*
VPC Creation
*/

resource “aws_vpc” “vpc_tuto” {
cidr_block = “${var.vpc_cidr}”
enable_dns_hostnames = true
enable_dns_support = true
tags {
Name = “Vennila”
}
}

/*
Create Elastic IP
*/

resource “aws_eip” “tuto_eip” {
vpc = true
depends_on = [“aws_internet_gateway.gw”]
}

/*
Public Subnet
*/
resource “aws_subnet” “public_subnet_eu_west_1a” {
vpc_id = “${aws_vpc.vpc_tuto.id}”
cidr_block = “${var.public_subnet_cidr}”
availability_zone = “us-east-1a”
tags {
Name = “Public_Subnet”
}
}


#2

@iamarunk1898

Hi use grep to grep the required content from test2.tf

for ex:

#grep id=123 test2.if

if you want to compare the content of both the files you can use diff, vimdiff or vim -d

for ex:

#vim -d test1 test2

(or)

#diff test1 test2

#3

HI,

Thanks for your reply. i have value id=123 in test1.tf.

How to refer this value automatically in test2.tf.