Fireship · @fireship

Terraform in 100 Seconds

Uploaded July 28, 2021 · Length 2:18

Terraform in 100 Seconds

Summary

terraform provides a way to build and manage cloud infrastructure as code using a human-readable blueprint.

  • terraform
  • infrastructure as code
  • cloud provisioning
  • hashicorp
  • aws
  • google cloud
  • azure

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    terraform an infrastructure as code tool

  2. 0:02

    that can provision resources in the

  3. 0:04

    cloud

  4. 0:05

    from simple declarative code when

  5. 0:07

    building an app in the cloud you may

  6. 0:08

    find yourself using the graphical user

  7. 0:10

    interface of your favorite cloud

  8. 0:12

    provider

  9. 0:12

    clicking on buttons and paying for

  10. 0:14

    products just like you would on an

  11. 0:15

    e-commerce site the only drawback of

  12. 0:17

    this approach is that it's complete and

  13. 0:19

    total chaos you might click a thousand

  14. 0:20

    different buttons to get your vm

  15. 0:22

    configured properly

  16. 0:23

    but what happens when you need to

  17. 0:24

    reproduce the same thing again in the

  18. 0:26

    future

  19. 0:26

    terraform provides a way to build change

  20. 0:28

    and version infrastructure

  21. 0:30

    safely and efficiently by representing

  22. 0:32

    your infrastructure

  23. 0:33

    and all that settings with the hashicorp

  24. 0:35

    configuration language or optionally

  25. 0:37

    json think of it like a human readable

  26. 0:39

    blueprint that can execute and

  27. 0:41

    automate everything you do in the cloud

  28. 0:43

    it's free and open source

  29. 0:45

    and the first step to get started is to

  30. 0:46

    install the cli on your local system

  31. 0:49

    then from your project create a file

  32. 0:51

    ending in tf

  33. 0:52

    at the top we have a terraform block

  34. 0:54

    that controls global settings for

  35. 0:55

    terraform itself

  36. 0:56

    most importantly we can define providers

  37. 0:58

    here which are like plugins that can

  38. 1:00

    connect to different cloud providers

  39. 1:02

    like aws

  40. 1:03

    google cloud azure etc below that we

  41. 1:05

    have a provider block which gives

  42. 1:07

    terraform the necessary credentials to

  43. 1:09

    connect to our google cloud account

  44. 1:11

    from there we can create actual cloud

  45. 1:13

    infrastructure using a resource block it

  46. 1:15

    takes a type as its first argument which

  47. 1:17

    corresponds to a product on google cloud

  48. 1:20

    then a custom name to identify it as the

  49. 1:22

    second argument

  50. 1:23

    inside the block we can customize the

  51. 1:24

    settings of the resource like its

  52. 1:26

    machine type

  53. 1:27

    zone and anything else you can imagine

  54. 1:29

    now that our infrastructure is defined

  55. 1:30

    as code we can run terraform init to

  56. 1:33

    initialize the project

  57. 1:34

    then terraform apply to make the actual

  58. 1:36

    changes to google cloud

  59. 1:38

    it'll require a confirmation before

  60. 1:39

    making the changes then after it's

  61. 1:41

    complete

  62. 1:42

    the terraform show command can be used

  63. 1:43

    to inspect the current state of the

  64. 1:45

    infrastructure what's awesome

  65. 1:46

    is that as we add more resources to the

  66. 1:48

    configuration terraform keeps track of

  67. 1:50

    the changes or diff

  68. 1:52

    similar to a version control system like

  69. 1:54

    git just run terraform apply again to

  70. 1:56

    deploy any changes to the configuration

  71. 1:58

    now once your startup has failed and it