Terraform with Multiple State Files

Поділитися
Вставка
  • Опубліковано 7 лис 2020
  • 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.coach/vips
    The Newsletter: www.thecloud.coach/news-letter
    Checkout my FREE courses!
    What are IAC & CAC?: www.thecloud.coach/what-are-i...
    Terraform Crash Course: www.thecloud.coach/terraform-...
    Ansible Crash Course: www.thecloud.coach/ansible-cr...
    Packer Crash Course: www.thecloud.coach/packer-cra...
    Checkout my PREMIUM courses!
    Terraform Crash Course: Premium: www.thecloud.coach/terraform-...
    Terraform: Understanding State: www.thecloud.coach/terraform-...
    CI/CD Introduction: www.thecloud.coach/ci-cd-intr...
  • Наука та технологія

КОМЕНТАРІ • 66

  • @Cloud-Radio
    @Cloud-Radio 3 роки тому +2

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

  • @hamidapremani6151
    @hamidapremani6151 3 роки тому +2

    Well-explained and concise, as always. Thanks!

  • @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)

  • @Organicnz2
    @Organicnz2 3 роки тому +2

    As always clear. Thanks for sharing bro :)

  • @subzeroleaf
    @subzeroleaf 3 роки тому +1

    Thank you for the great content! That was really clarifying

  • @ankansikdar1751
    @ankansikdar1751 2 роки тому +1

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

  • @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.

  • @sharonsahadevan4904
    @sharonsahadevan4904 Рік тому +1

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

  • @giftfelix4848
    @giftfelix4848 Рік тому +1

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

  • @luccapessoa4494
    @luccapessoa4494 2 роки тому +1

    I love the knowledge that you share!

  • @kristof19816
    @kristof19816 3 роки тому +2

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

  • @HDINH34
    @HDINH34 Рік тому +1

    Excellent explanation. Thank you.

  • @changuage
    @changuage 2 роки тому +1

    Bless you my friend

  • @umka7536
    @umka7536 Рік тому +1

    Awesome video with explanation! Thanks a lot!

  • @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.

  • @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.

  • @karthikkarthik100
    @karthikkarthik100 3 роки тому +1

    Thank you Mike, awesome

  • @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.

  • @welbsterhansi
    @welbsterhansi Рік тому +1

    Very nice!

  • @rajendragosavi2233
    @rajendragosavi2233 3 роки тому +1

    Thank you very much. That helps

  • @ramyahello
    @ramyahello 2 роки тому +1

    Thanks a lot

  • @rezaebrahimi1498
    @rezaebrahimi1498 Рік тому +1

    very good explanation. i get involved into your courses

  • @kayoutube690
    @kayoutube690 Рік тому +1

    Wow!!

  • @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.

  • @deepdeep4629
    @deepdeep4629 3 роки тому +1

    best video ever !

  • @barrymanilow3893
    @barrymanilow3893 7 місяців тому +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 5 місяців тому

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

  • @silopolis-yt
    @silopolis-yt 5 місяців тому

    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 11 місяців тому +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  11 місяців тому

      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.

  • @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 :-)

  • @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 :)

  • @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!

  • @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 ?

  • @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.

  • @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

  • @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 UA-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?