Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Terraform - Infrastructure as a Code

Terraform - Infrastructure as a Code

Ondrej Sika

October 06, 2019
Tweet

More Decks by Ondrej Sika

Other Decks in Programming

Transcript

  1. Ondrej Sika
    [email protected]
    @ondrejsika
    LinuxDays 2019
    Terraform
    Infrastructure as a code

    View Slide

  2. About me - Ondrej Sika
    I'm DevOps consultant and lecturer.
    I'm helping companies to setup DevOps. That means for them
    to focus on their product, faster & more reliable delivery new
    features to production and stop wasting time for example on
    deployments and infrastructure.

    View Slide

  3. We want Git versioned
    - Source Code
    - Environments (Dockerfiles)
    - Configuration (Nginx, …)
    - Deployments (Kubernetes)
    - Infrastructure?

    View Slide

  4. How we handle infrastructure?
    - Physical servers - manually
    - Virtual servers - manually
    - Cloud - manually
    - Cloud - as a code - Terraform

    View Slide

  5. Terraform

    View Slide

  6. What is
    Terraform?
    Terraform is a tool for
    managing infrastructure as
    code
    You can version your infrastructure
    in Git, create resources from pull
    requests or fork infrastructure you
    like.

    View Slide

  7. View Slide

  8. Terraform
    - Designed for infrastructure management
    - Provide declarative way how to define your infrastructure
    - Support removing resources (has state)
    - Help you to evolve infrastructure save & predictable way
    - Work with all major clouds (AWS, Azure, …)
    - Open Source (18 000 stars on Github)
    - Can predict costs (Terraform Enterprise)

    View Slide

  9. Why Terraform? and not Ansible, Puppet, ...
    Terraform is better with Ansible, Puppet, ...
    - Terraform is not a configuration management tool,
    Ansible or Puppet do it and do it pretty good
    - Terraform work with configuration management tool
    - Terraform creates infrastructure and run CM tool for
    setting up the resources

    View Slide

  10. How Terraform works
    Terraform compare actual infrastructure (stored in local or
    remote state) and infrastructure you want (in .tf files).
    Then apply (create, update or remove) the differences.

    View Slide

  11. Configuration Language

    View Slide

  12. Providers
    A provider is responsible for understanding API interactions
    and exposing resources.
    Providers generally are an IaaS (e.g. AWS, GCP, Azure,
    OpenStack) or SaaS services (e.g. CloudFlare, Gitlab).

    View Slide

  13. View Slide

  14. Resources
    Terraform is used to create, manage, and update
    infrastructure resources such as physical machines, VMs,
    network switches, containers, and more. Almost any
    infrastructure type can be represented as a resource in
    Terraform.

    View Slide

  15. View Slide

  16. Data Sources
    Data sources allow data to be fetched or computed for use
    elsewhere in Terraform configuration.
    Use of data sources allows a Terraform configuration to make
    use of information defined outside of Terraform, or defined
    by another separate Terraform configuration.

    View Slide

  17. View Slide

  18. Modules
    A module is a container for multiple resources that are used
    together.

    View Slide

  19. View Slide

  20. View Slide

  21. Backends
    A "backend" in Terraform determines how state is loaded and
    how an operation such as apply is executed. This abstraction
    enables non-local file state storage, remote execution, etc.
    Why remote state / backend?
    - Working in a team
    - Remote operations (CI/CD)

    View Slide

  22. Terraform CLI

    View Slide

  23. Terraform CLI
    - terraform init - download plugins & setup modules
    - terraform plan - show & prepare changes of
    infrastructure
    - terraform apply - apply new version of infrastructure
    - terraform destroy - destroy your infrastructure

    View Slide

  24. View Slide

  25. View Slide

  26. View Slide

  27. View Slide

  28. View Slide

  29. Demo Time

    View Slide

  30. ondrej-sika.cz/repozitare/#terraform

    View Slide

  31. Thank you & Questions
    Ondrej Sika
    email: [email protected]
    www: https://ondrej-sika.cz
    twitter: @ondrejsika
    linkedin: /in/ondrejsika/
    Slides: https://sika.link/linuxdays2019

    View Slide