GoConqr has a new look! Let us know what you think.

Flashcards

6 Working with terraform

Archimed Nemes Kodekloud Terraform basics Easy English 33 cards

Cards in this deck (33)

  1. 1How to check correctness of configuration file?terraform validate
  2. 2How to improve readability of terraform configuration file?terraform fmt / terraform format
  3. 3Display current state of resourceterraform show
  4. 4View the terraform show in json formatterraform show -json
  5. 5View the list of providers in configuration directoryterraform providers
  6. 6Copy provider plugins needed for current configuration to another directory like this.terraform providers mirror /root/terraform/new_local_file
  7. 7Update terraform with changes made outside of terraform control and refresh state fileterraform refresh
  8. 8Vieü dependencies and Terraform execution plan visuallyterraform graph
  9. 9In what software graphs are better seen?graphviz
  10. 10How to pass result of terraform graph to graphvizterraform graph | dot -Tsvg > graph.svg
  11. 11How Terraform updates resource?It first destroy then recreates it.
  12. 12What does immutable infrastructure mean?It means creating new updated server then deleting old one
  13. 13How can we ensure that resources are created first then deleted or deletin ignored?By using lifecycle rules
  14. 14resource "local_file" "pet" { filename = "/root/pets.txt" content = "We love pets!" file_permission = "0700" } Add lifecycle rule so that resource is created first then deletedresource "local_file" "pet" {
    filename = "/root/pets.txt"
    content = "We love pets!"
    file_permission = "0700"
    lifecycle {
    create_before_destroy = true
    }
    }
  15. 15resource "local_file" "pet" { filename = "/root/pets.txt" content = "We love pets!" file_permission = "0700" } Add lifecycle rule so that resource is not deleted at allresource "local_file" "pet" {
    filename = "/root/pets.txt"
    content = "We love pets!"
    file_permission = "0700"
    lifecycle {
    prevent_destroy = true
    }
    }
  16. 16Ignore changes to content made to terraform outside it resource "local_file" "pet" { filename = "/root/pets.txt" content = "We love pets!" file_permission = "0700" }resource "local_file" "pet" {
    filename = "/root/pets.txt"
    content = "We love pets!"
    file_permission = "0700"
    lifecycle {
    ignore_changes = [
    content ]
    }
    }
  17. 17Ignore changes to content made to terraform outside it resource "local_file" "pet" { filename = "/root/pets.txt" content = "We love pets!" file_permission = "0700" }resource "local_file" "pet" {
    filename = "/root/pets.txt"
    content = "We love pets!"
    file_permission = "0700"
    lifecycle {
    ignore_changes = all
    }
  18. 18Explain data sourcesData sources allow Terraform to read attributes which are provisioned utside its control
  19. 19Read attirubutes from /root/dogs.txtdata "local_file" "dog" {
    filename = "/root/dog.txt"
    }
  20. 20resource "local_file" "pet" { filename = "/root/pets.txt" content = "We love pets!" } Change content to content of /root/dogs.txtresource "local_file" "pet" {
    filename = "/root/pets.txt"
    content = data.local_file.dog.content
    }
    data "local_file" "dog" {
    filename = "/root/dog.txt"
    }
  21. 21variable "filename" { default = "/root/pets.txt" } Create file of "local_file" pet 3 times (test this if there are 3 or 1 files)resource "local_file" "pet" {
    filename = var.filename
    count = 3
    }
  22. 22Declare variable filename which includes "/root/pets.txt" "/root/dogs.txt" "/root/cats.txt" and create these 3 filesvariable "filename" {
    default = [
    "/root/pets.txt"
    "/root/dogs.txt"
    "/root/cats.txt" ]
    }
    resource "local_file" "pet" {
    filename = var.filename[count.index]
    count = 3
    }
  23. 23Declare variable filename which includes "/root/pets.txt" "/root/dogs.txt" "/root/cats.txt" "/root/ducks.txt" and create these 4 files uing length attributevariable "filename" {
    default = [
    "/root/pets.txt"
    "/root/dogs.txt"
    "/root/cats.txt"
    "/root/ducks.txt ]
    }
    resource "local_file" "pet" {
    filename = var.filename[count.index]
    count = length(var.filename)
    }
  24. 24What is main problem with count?When using count if we reduce number of created resources in variable file terraform will first destroy all and then recreate fewer resources.
  25. 25How can we solve this problem with for_each using type set Declare variable filename which includes "/root/pets.txt" "/root/dogs.txt" "/root/cats.txt" and create these 3 filesvariable "filename" {
    type = set(string)
    default = [
    "/root/pets.txt"
    "/root/dogs.txt"
    "/root/cats.txt"
    ]
    }
    resource "local_file" "pet" {
    filename = each.value
    for_each=var.filename
    }
  26. 26How can we solve this problem with for_each using type list Declare variable filename which includes "/root/pets.txt" "/root/dogs.txt" "/root/cats.txt" and create these 3 filesvariable "filename" {
    type = list(string)
    default = [
    "/root/pets.txt"
    "/root/dogs.txt"
    "/root/cats.txt"
    ]
    }
    resource "local_file" "pet" {
    filename = each.value
    for_each=toset(var.filename)
    }
  27. 27In what form are created with for_each vs countfor_each - as map
    count - as list
  28. 28What block should we add to main.tf file to use terraform version 1.4.0 for local providerterraform {
    require_providers {
    local = {
    source = "hashicorp/local"
    version = "1.4.0"
    }
    }
    }
  29. 29What block should we add to main.tf file not to use terraform version 1.4.0 but previous version for local providerterraform {
    require_providers {
    local = {
    source = "hashicorp/local"
    version = "! = 1.4.0"
    }
    }
    }
  30. 30What block should we add to main.tf file to use terraform version lesser than 1.4.0 version for local providerterraform {
    require_providers {
    local = {
    source = "hashicorp/local"
    version = "<1.4.0"
    }
    }
    }
  31. 31What block should we add to main.tf file to use terraform version greater than 1.4.0 version for local providerterraform {
    require_providers {
    local = {
    source = "hashicorp/local"
    version = " > 1.4.0"
    }
    }
    }
  32. 32What block should we add to main.tf file to use terraform version lesser than 2.0.0, greater than 1.2.0 but not 1.4.0 version for local providerterraform {
    require_providers {
    local = {
    source = "hashicorp/local"
    version = " > 1.2.0, < 2.0.0, ! = 1.4.0"
    }
    }
    }
  33. 33What block should we add to main.tf file to use terraform version starting from 1.2.0 and above but not starting with 2.0.0 version for local providerterraform {
    require_providers {
    local = {
    source = "hashicorp/local"
    version = " ~> 1.2.0"
    }
    }
    }

Information

Description
Easy Kodekloud Terraform basics Flashcards on 6 Working with terraform, created by Archimed Nemes on 17/12/2022.
Created by
Archimed Nemes
Views
0
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?