Terraform with Multiple State Files

แชร์
ฝัง
  • เผยแพร่เมื่อ 25 ส.ค. 2024
  • Terraform with Multiple State Files | Sign up to our free Discord community: / discord
    SUBSCRIBE: bit.ly/2WBPF1W
    JOIN THE COMMUNITY: / discord
    About The Cloud Coach:
    Michael Crilly, aka "The Cloud Coach", is a leading expert in DevOps and automation. The Coach has automated everything from Cisco hardware to AWS resources using various tools like Python, Ruby, Go, Terraform, Packer, CloudFormation, CI/CD, JenkinsCI, GitOps, and much more. The Coach also loves to teach everyone and anyone about the joy of automating complex Cloud resources to deliver a fast, better infrastructure that's cheaper to operate and more stable to manage.
    Connect with The Cloud Coach:
    My Discord community: / discord
    The VIP program: www.thecloud.c...
    The Newsletter: www.thecloud.c...
    Checkout my FREE courses!
    What are IAC & CAC?: www.thecloud.c...
    Terraform Crash Course: www.thecloud.c...
    Ansible Crash Course: www.thecloud.c...
    Packer Crash Course: www.thecloud.c...
    Checkout my PREMIUM courses!
    Terraform Crash Course: Premium: www.thecloud.c...
    Terraform: Understanding State: www.thecloud.c...
    CI/CD Introduction: www.thecloud.c...

ความคิดเห็น • 66

  • @azy22222
    @azy22222 3 ปีที่แล้ว +7

    Great video! Definitely a big fan of Terragrunt when it comes to the multi statefile setup, definitely cleaner!

    • @dus10dnd
      @dus10dnd 3 ปีที่แล้ว +2

      I've never seen the appeal of Terragrunt, but I came into Terraform at 0.12.

  • @FredericKouidri
    @FredericKouidri ปีที่แล้ว +1

    Thank you Michael, I have been searching for a long time the way to pass values from one project to another ! (data + terraform_remote_state)

  • @ScrolltheNature
    @ScrolltheNature 3 ปีที่แล้ว +2

    Loved it !! You clear my doubt as i am implementing terraform for an organization. Thanks for help.

  • @giftfelix4848
    @giftfelix4848 ปีที่แล้ว +1

    Great stuff man, I love the separation of concern. Thanks

  • @thecloudera5015
    @thecloudera5015 ปีที่แล้ว +1

    Brilliant one!! thanks for the video Michael ...my neurons are making new connections ... how does a module fit-in in this scenario ..whew!! thanks for sharing.

  • @hamidapremani6151
    @hamidapremani6151 3 ปีที่แล้ว +2

    Well-explained and concise, as always. Thanks!

  • @kristof19816
    @kristof19816 3 ปีที่แล้ว +2

    Great video! It helped me to prepare for the Terraform certification.

    • @MichaelCrilly
      @MichaelCrilly  3 ปีที่แล้ว

      Awesome! Let us know how you get on!

  • @Organicnz2
    @Organicnz2 3 ปีที่แล้ว +2

    As always clear. Thanks for sharing bro :)

  • @changuage
    @changuage 2 ปีที่แล้ว +1

    Bless you my friend

  • @sharonsahadevan4904
    @sharonsahadevan4904 ปีที่แล้ว +1

    Great! really helpful and easy to understand. Keep up the awesome work man!

  • @ankansikdar1751
    @ankansikdar1751 2 ปีที่แล้ว +1

    That's a great piece of info you just presented. Great job!

  • @leriksenbendigo
    @leriksenbendigo 3 ปีที่แล้ว +1

    Whilst this does have some use cases, I've typically found this to be the much more work for the devops eng to deal with. Terraform is very good at discovering how a change affects multiple resources in the state file. Separating out to separate states doesnt let tf discover/resolve those. terraform_remote_state can help a little. I think splitting out resources to separate state files can be limited to resources common across several environments/projects is ok - e.g. centralised log solution. One other possible case is per-developer environments. One state file per dev allows for developers to change their own env without affecting other devs, allowing new development to be prototyped, and a simple "terraform plan" tells them how to get back to the standard setup. Thanx for the content

    • @MichaelCrilly
      @MichaelCrilly  3 ปีที่แล้ว +2

      Some great points there mate. Overall I think as a tool Terraform has to be deployed in a manner that suits the environment and expectations of the business. So if you’re happy with long execution times and all in one state files then that’s fine too.
      Don’t forget with large enterprises and governments there’s often a need to separate out access to systems based on an engineer’s role in the organisation. Don’t want developers manipulating IAM policies to suit their needs for example.

  • @HDINH34
    @HDINH34 2 ปีที่แล้ว +1

    Excellent explanation. Thank you.

  • @krishna172225
    @krishna172225 3 ปีที่แล้ว +7

    Can you please do a video on how Terraform project should be created for multiple environments.

    • @MichaelCrilly
      @MichaelCrilly  2 ปีที่แล้ว +1

      Will do! Coming soon!

    • @StephenRayner
      @StephenRayner 2 ปีที่แล้ว

      I used work spaces for multiple stages, but I am looking at how I can deploy multiple stages for each customer

    • @vakuljain8649
      @vakuljain8649 ปีที่แล้ว

      @@MichaelCrilly hi, is this video released? Would love to see it for a project I have to setup.

  • @WebDevCody
    @WebDevCody 2 ปีที่แล้ว +1

    On our team we were looking into ways we could speed up our deploys. This might be useful. I’d need to see the speed benefits gained vs development time to refactor to split up some resources into separate states. We also do a similar thing you mentioned and put all of our policies and roles into a different state that can only be ran manually by a select few people (instead of allowing ci cd to modify them). Good info!

    • @MichaelCrilly
      @MichaelCrilly  2 ปีที่แล้ว

      It will speed things up for sure. I believe granular states can introduce complexity but also a lot of flexibility, security and speed when managing them.

  • @umka7536
    @umka7536 ปีที่แล้ว +1

    Awesome video with explanation! Thanks a lot!

  • @luccapessoa4494
    @luccapessoa4494 3 ปีที่แล้ว +1

    I love the knowledge that you share!

  • @subzeroleaf
    @subzeroleaf 3 ปีที่แล้ว +1

    Thank you for the great content! That was really clarifying

  • @rezaebrahimi1498
    @rezaebrahimi1498 ปีที่แล้ว +1

    very good explanation. i get involved into your courses

  • @kayoutube690
    @kayoutube690 ปีที่แล้ว +1

    Wow!!

  • @karthikkarthik100
    @karthikkarthik100 3 ปีที่แล้ว +1

    Thank you Mike, awesome

  • @ramyahello
    @ramyahello 2 ปีที่แล้ว +1

    Thanks a lot

  • @barrymanilow3893
    @barrymanilow3893 9 หลายเดือนก่อน +2

    The problem with this approach is you can’t terraform plan everything together before doing any terraform applys. Say you added a new resource to ‘networking’, outputted it and referenced it in ‘application’ - A terraform plan on ‘networking’ would complete but a terraform plan on ‘application’ would fail due to the outputs not being in the networking remote state file yet. This makes CI/CD harder as let’s say these changes were all part of the same commit, and you wanted to plan them all as part of a PR. It would fail due to the dependencies.

    • @silopolis-yt
      @silopolis-yt 6 หลายเดือนก่อน

      New to this, but I believe that's one of the problems tools like Atmos from @cloudposse try to solve.

  • @rajendragosavi2233
    @rajendragosavi2233 3 ปีที่แล้ว +1

    Thank you very much. That helps

  • @welbsterhansi
    @welbsterhansi 2 ปีที่แล้ว +1

    Very nice!

  • @silopolis-yt
    @silopolis-yt 6 หลายเดือนก่อน

    Excellent video Michael! Thanks for sharing it.
    One question: what if the remote state isn't up-to-date with the actual system? Using provider supplied data seems more reliable from this point of view. What are the tradeoffs of both solutions? Does a scenario using remote state for "static"/config data coming from TF, and provider for data about the live system, makes sense, and would it be reliable and maintainable?
    On to next one of yours...
    Cheers from France :)

  • @PENFRIEN002
    @PENFRIEN002 ปีที่แล้ว +1

    Great video Michael. :)
    Does this separation of state files helps in locking state file with another admins? Maybe I missed it in the video. Thank you and you got a good flow in videos and great explenation. :)

    • @MichaelCrilly
      @MichaelCrilly  ปีที่แล้ว

      Thanks mate. Yes, when you use multiple state files you can more easily lock them all individually, allowing multiple admins to work across different states at the same time.

  • @master2466
    @master2466 ปีที่แล้ว +1

    brilliant. More real time training would be a good one to focus on by taking aproject and start working on it, including showing the docummentation and demonstrate how one can understand documentation would be the hot cake.

    • @MichaelCrilly
      @MichaelCrilly  ปีที่แล้ว +2

      I’m working on it, actually :-)

  • @deepdeep4629
    @deepdeep4629 3 ปีที่แล้ว +1

    best video ever !

  • @t-xd6rp
    @t-xd6rp ปีที่แล้ว +1

    If you wanted seperate env's, say, Test, Pre-Prod, Prod etc. would you use the same code with all the same resources in each of the env's and then just plan and apply those changes to the env of choice hence not breaking prod when trying to add a new resource?

    • @MichaelCrilly
      @MichaelCrilly  ปีที่แล้ว

      That’s one way of doing it. You can use tfvars files to help with this.

    • @t-xd6rp
      @t-xd6rp ปีที่แล้ว +1

      @@MichaelCrilly Cool, many thanks :)

  • @dacceto
    @dacceto 2 ปีที่แล้ว +1

    This looks great, but I wonder how to put this in a yaml file where you end up having a bunch of resources dependencies, e.g. an API needs to be in a VNET, so if we change the api we need to make sure VNET exists and so on

    • @MichaelCrilly
      @MichaelCrilly  2 ปีที่แล้ว

      YAML file?
      You will have a tightly coupled dependencies between an API and a VNET whether you use multiple state files or not :-)

  • @erikwhitesides
    @erikwhitesides 3 ปีที่แล้ว +1

    have you tried using data "my network resource" calls from application instead of data "terraform_remote_state" ? my concern with using terraform_remote_state is that you're depending on a state file that could be using another terraform version.

    • @MichaelCrilly
      @MichaelCrilly  3 ปีที่แล้ว

      Good point. However I’d simply pin the Terraform version in the code. Problem solved.

  • @StephenRayner
    @StephenRayner 2 ปีที่แล้ว +1

    How would you scale this to work with multiple stages dev, QAT, UAT, and live as well as duplicating all the stages for each for multiple use cases.

    • @MichaelCrilly
      @MichaelCrilly  2 ปีที่แล้ว

      A case by case basis, really. Most of the time dev doesn’t perfectly match prod, for example. So can dev be one state? Possibly!

  • @UtkarshMishra-it4oc
    @UtkarshMishra-it4oc ปีที่แล้ว +1

    I am struggling with a issue regarding remote state management for quite a while now. So, actually while using this technique we are only able to use 5 output attributes from the remote state file. I have a requirement of using 6 attributes from 1 state file for using in further deployment. Can anybody suggest how do I achieve that? It'll be really very helpful and I'll be able to sleep.

    • @MichaelCrilly
      @MichaelCrilly  ปีที่แล้ว

      Join The DevOps Lounge and ask there: discord.gg/devopslounge

    • @UtkarshMishra-it4oc
      @UtkarshMishra-it4oc ปีที่แล้ว

      @@MichaelCrilly I am not able to join discord that's why, if you can give a clue here only. It will be helpful.

    • @MichaelCrilly
      @MichaelCrilly  ปีที่แล้ว

      It’s really difficult to answer here. Sorry. It’s too restricted an environment.

    • @UtkarshMishra-it4oc
      @UtkarshMishra-it4oc ปีที่แล้ว +1

      @@MichaelCrilly yeah, I understand. No problem, thanks anyways

  • @kaykhan9561
    @kaykhan9561 3 ปีที่แล้ว +1

    how does this work when using prod and dev workspaces?

    • @MichaelCrilly
      @MichaelCrilly  2 ปีที่แล้ว

      Good question. You'll have to jump on the Discord to discuss.

  • @othmanissa7976
    @othmanissa7976 3 ปีที่แล้ว

    Hello, I like the way how you describe it. How i can get this file for tranning perpose? or if you have it in git and i can fork it ?

  • @nahum35
    @nahum35 3 ปีที่แล้ว +1

    Hi, have you thought of doing a video and demonstrating how to build 5 Linux VM's with a shared subnet to everyone?...seems like there's no such tutorial on TH-cam, and yes you can check it out your self :)

    • @MichaelCrilly
      @MichaelCrilly  3 ปีที่แล้ว +1

      That’s just putting the instances in the same subnet. What challenges can I help you overcome?