Parsing Data with For Loops

Ғылым және технология

The data you receive for your Terraform configurations might be outside of your control. It could come from a ticketing system, a code generation pipeline, or an Excel spreadsheet. You can use loops in Terraform to parse through complex data structures and extract the values you need for your modules. In this video I go DEEP on how to use for loops on JSON data in Terraform. Buckle up kids and bring a snack, this is going to be a heckuva trip.
GitHub Repo: github.com/ned1313/terraform-...
Docs about for loops: www.terraform.io/docs/languag...
Terraform Certification Guide: leanpub.com/terraform-certified/
Day Two Cloud podcast: daytwocloud.io
-----------------------------------------------------------------------------------------------------
Patreon: / nedinthecloud
Website: nedinthecloud.com
Pluralsight: app.pluralsight.com/profile/a...
GitHub: github.com/ned1313
Music by Evan Williams ©2020
Intro 0:00
The Problem with Data Structures 1:33
Nested Loops for Infrastructure 3:38
Working with JSON in Terraform 4:36
Using Terraform Console 7:20
Examining the For Syntax 9:17
Using Real-world Config Data 14:51
Building the Loops 18:05
Examining Nested Loop Data 22:03
Outro 27:24

Пікірлер: 26

  • @vibhormathpal2021
    @vibhormathpal20219 ай бұрын

    This one is really a gold.

  • @methate
    @methate2 жыл бұрын

    I read official TF Doc, I read some articles. Nothing helped to get an idea how it's actually working. So, I'm happy that I found your video. It's perfect explanation. In fact, probably you're the best presenter that I've ever seen (and I've seen a lot of presenters). Please continue doing your good job!

  • @devlinthornicroft9975
    @devlinthornicroft99753 жыл бұрын

    This video was excellent at explaining the concept. Thank you.

  • @deefdragon
    @deefdragon2 жыл бұрын

    This is a ridiculously good tutorial on complex data structures in terraform. This is literally exactly what I have been looking for to wrap my head around them. I will be honest, this is not something I would expect from someone with 3.75 K subs. More like 375K. Keep on going, cause you are awesome. Edit: It took all of 5 minutes after watching this tutorial to completely refactor my code to be SOOO much more readable, and actually make logical sense. So thank you again.

  • @dawidmandyna8635
    @dawidmandyna86353 жыл бұрын

    Hey Ned, Great job on this video. I was looking for a while for a good explanation about the for_loops in Terraform, as their documentation is lacking a lot of information in that space. Now everything is much clearer! Thank you!

  • @NedintheCloud

    @NedintheCloud

    3 жыл бұрын

    Glad I could help!

  • @TheXiguazhi
    @TheXiguazhi Жыл бұрын

    Subscribed. This makes what I'm trying to do so much easier knowing what you just said here. Thank you for saving me hours of looping in my brain so I can work on looping inside my terraform files

  • @NedintheCloud

    @NedintheCloud

    Жыл бұрын

    Glad it helped!

  • @MrNoartik
    @MrNoartik Жыл бұрын

    Oh man, you save so many hours, thanks wery helpfull

  • @moritz473
    @moritz4733 жыл бұрын

    Great content! Thank you

  • @vonschnappi
    @vonschnappi3 жыл бұрын

    “Hey everybody what’s up it’s Ned…” Yep, imma subscribe.

  • @AniruddhaKhadkikar
    @AniruddhaKhadkikar Жыл бұрын

    This has been a nirvana moment for me aka lots of aha's! Thanks a ton Ned! I will try to do something similar but with a yaml config and yamldecode.

  • @MrPankajkr06
    @MrPankajkr062 жыл бұрын

    This video is gold

  • @ayush2708
    @ayush27082 жыл бұрын

    God or wut. I was always searching on how to visualise each line in documentation. And terrform console was it. Plus godly explanation. Thank you. :)

  • @jafarshaik5160
    @jafarshaik51603 жыл бұрын

    Loved it

  • @timsamanchi3004
    @timsamanchi30042 жыл бұрын

    thank you kind sir.

  • @onenationunderduress8994
    @onenationunderduress89942 жыл бұрын

    My anxiety level after that taco intro is through the roof!

  • @ajpatterson57
    @ajpatterson572 жыл бұрын

    Thanks for the video. Do you know how we would loop these into a data source? So for instance how would we loop a list of userprincipalnames into azuread_users to return object ids?

  • @mosksky
    @mosksky3 жыл бұрын

    TY Ned another great demo! now there is no need to declare the variables (variables.tf is not needed) no more finding appropriate type as well. Any chance you could update "terraform-Tuesday" repo as a map (Parsing Data with For Loops => 2021-01-25) just use for loop :) Really hard to trace some of old recording, like this video has been dated 01/26 but the repo folder is 01/25. I am not picky just want to share my feedback

  • @NedintheCloud

    @NedintheCloud

    3 жыл бұрын

    I have been thinking about updating the folder naming to the episode to make it easier. I'll see if I can fit that in before next week's episode.

  • @p.a8750
    @p.a87503 жыл бұрын

    Great video! Been trying to get my head round this for some time and your video explains it perfectly! One question - i saw some code that had the following: For i in var.instances: “${i.name} ${i.zone}” => i Trying to work out if => i is making ‘i’ have the values of i.name and i.zone from each iteration in var.instances? Var.instances was an object containing a name value and a zone value. What does => actually mean?

  • @NedintheCloud

    @NedintheCloud

    3 жыл бұрын

    The syntax can be confusing: { for i in var.instances: "${i.name} ${i.zone}" => i } The curly braces indicate the resulting data type with be an object. The var. instances is the source of the for loop. I would guess that var.instances is a list of maps or objects. The "i" is the iterator for the for loop. As the loop iterates, "i" will load a map from the list of maps stored in var.instances. The i.name and i.zone come from the currently loaded map. Since we are creating an object with key value pairs, the "${i.name} ${i.zone}" is the key and the "i" is the value. The => indicates mapping a key to a value. Hopefully that clears things up! Here's the official docs too: www.terraform.io/docs/language/expressions/for.html

  • @p.a8750

    @p.a8750

    3 жыл бұрын

    @@NedintheCloud thank you for explaining this!

  • @michaelhanley7112
    @michaelhanley71123 жыл бұрын

    Great Vid. But i have a question, Instead of managing a json file for data could a map variable work?

  • @NedintheCloud

    @NedintheCloud

    3 жыл бұрын

    If you are able to pass the data to Terraform as a map that would be great. Sometimes you don't have control over the input format or you want to extract a small portion of a larger data structure.

  • @michaelhanley7112

    @michaelhanley7112

    3 жыл бұрын

    @@NedintheCloud thank u ned

Келесі