Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
HashiCorp Terraform Associate (003) Exam Guide

You're reading from   HashiCorp Terraform Associate (003) Exam Guide Prepare to pass the Terraform Associate exam on your first attempt

Arrow left icon
Product type Paperback
Published in May 2024
Publisher Packt
ISBN-13 9781804618844
Length 344 pages
Edition 1st Edition
Arrow right icon
Authors (2):
Arrow left icon
Manjunath H. Gowda Manjunath H. Gowda
Author Profile Icon Manjunath H. Gowda
Manjunath H. Gowda
Chandra Mohan Dhanasekaran Chandra Mohan Dhanasekaran
Author Profile Icon Chandra Mohan Dhanasekaran
Chandra Mohan Dhanasekaran
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Introduction to Infrastructure as Code (IaC) and Concepts 2. Why Do We Need Terraform? FREE CHAPTER 3. Basics of Terraform and Core Workflow 4. Terraform Commands and State Management 5. Terraform Modules 6. Terraform Backends and Resource Management 7. Debugging and Troubleshooting Terraform 8. Terraform Functions 9. Understanding HCP Terraform’s Capabilities 10. Miscellaneous Topics 11. Accessing the Online Practice Resources 12. Other Books You May Enjoy

Preconditions and Postconditions

Input validation stops resource creation in the case of invalid inputs if you run the configuration script, which means the validation takes place before the terraform apply operation.

But if you want a similar condition(s) to be applied to resources, data sources, or outputs and the evaluation has to be done before and after, based on the scenario, Terraform has precondition and postcondition to explore.

For resources and data sources, the precondition and postcondition checks need to be added under the lifecycle {} block. The outputs can contain a precondition check only without the lifecycle {} block. The precondition and postcondition check will contain the condition and the error message parameters, such as the one you saw with the input validation.

Look at the following code snippet:

data "aws_ecr_repository" "repo_data" {
  name = aws_ecr_repository.app_repo.name
  lifecycle {
 ...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime