O'Reilly logo

Getting Started with Terraform - Second Edition by Kirill Shirinkin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Exploring Terraform configuration resources

Quite frequently, you will require some random data to be generated. This could be default password for a database or a random hostname for your servers. Terraform has random provider that solves this problem.

Of course, completely random values are harmful for Terraform. That's why, the random_id resource generates random string only on creation and then value is kept during updates (unless you change the configuration of this resource). Imagine that we want to pass random hostname to the previously configured template_file user data. We could do it as follows:

 resource "random_id" "hostname" { byte_length = 4 } data "template_file" "user_data" { template = "${file("${path.module}/user_data.sh.tpl")}" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required