The Terraform Book by James Turnbull
Author:James Turnbull
Language: eng
Format: epub
Publisher: James Turnbull
Published: 2016-11-26T16:00:00+00:00
Now lets actually use our template in the file provisioner.
provisioner "file" { content = "${element(data.template_file.index.*.rendered, count.index)}" destination = "/tmp/index.html" }
The first attribute, content, is the actual file content we want to provision. We’ve specified an element function, which we introduced in Chapter 3, as the value of the content attribute. The element function pulls an element from a list using a given index. We’ve specified our data source as the list and the count.index as the element index. This will create an individual template for each element of the list.
We specify a data source much like we specify a resource. We start with data as the prefix, then the type of data source—here, template_file. We then specify the name of the resource, index. Remember how we specified a count in the data.template_file.index data source? This means we can use the splat syntax, *, to create a list of all the possible templates. The last part of the data source is rendered. The rendered method is a special call on the template_file data source. It returns the rendered template.
Lastly, we’re then using our count.index as the index to return a specific iteration of the template.
You can see we’re not actually passing around a variable between the instance resource and the template resource. Rather we’re relying on the value of the count.index to ensure our template is uniquely provisioned. This is because of the sequence in which Terraform creates the dependency graph. The template is created when the resource is created, so we cannot use attribute values—for example, the instance’s IP address or DNS name—in the template because they will not yet exist when the template is created.
The next attribute, destination, tells the file provisioner where to upload the file content. We’re uploading to /tmp/index.html.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Coding Theory | Localization |
Logic | Object-Oriented Design |
Performance Optimization | Quality Control |
Reengineering | Robohelp |
Software Development | Software Reuse |
Structured Design | Testing |
Tools | UML |
Deep Learning with Python by François Chollet(12610)
Hello! Python by Anthony Briggs(9931)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9806)
The Mikado Method by Ola Ellnestam Daniel Brolund(9798)
Dependency Injection in .NET by Mark Seemann(9354)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8317)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7777)
Grails in Action by Glen Smith Peter Ledbrook(7710)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7573)
Becoming a Dynamics 365 Finance and Supply Chain Solution Architect by Brent Dawson(7245)
Microservices with Go by Alexander Shuiskov(7012)
Practical Design Patterns for Java Developers by Miroslav Wengner(6920)
Test Automation Engineering Handbook by Manikandan Sambamurthy(6873)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6431)
Angular Projects - Third Edition by Aristeidis Bampakos(6289)
The Art of Crafting User Stories by The Art of Crafting User Stories(5809)
NetSuite for Consultants - Second Edition by Peter Ries(5740)
Demystifying Cryptography with OpenSSL 3.0 by Alexei Khlebnikov(5556)
Kotlin in Action by Dmitry Jemerov(5078)
