Thursday 11 April 2024

Terraform Interview Questions

Here are some Terraform Interview Questions with answers and/or links to answers. Good luck!


Terraform detected the following changes made outside of Terraform since the last "terraform apply":

  # site24x7_website_monitor.this["my_services_monitors"] has been changed
  ~ resource "site24x7_website_monitor" "this" {
      - auth_user                   = "pingdom" -> null
        id                          = "405565000027631014"
      ~ ignore_cert_err             = true -> false
        # (29 unchanged attributes hidden)
    }
  # site24x7_website_monitor.this["my_vpn_center_licensing"] has been changed
  ~ resource "site24x7_website_monitor" "this" {
        id                          = "405565000027631133"
      ~ ignore_cert_err             = true -> false
        # (29 unchanged attributes hidden)
    }

Unless you have made equivalent changes to your configuration, or ignored the relevant attributes using ignore_changes, the following plan may include actions to undo or respond to these changes.

jsonencode encodes a given value to a string using JSON syntax. So string will be transformed into a string:

> jsonencode("{\"name\":\"Bojan\"}")
"\"{\\\"name\\\":\\\"Bojan\\\"}\""

So escape character got escaped...and that's still a valid JSON (try it here: https://jsonlint.com/)

We usually want to JSON-stringify an object, not a string:

> jsonencode({"name":"Bojan"})
"{\"name\":\"Bojan\"}"


This is why, for example, we don't want to call jsonencode(templatefile(file.tftpl, {...})) but vice versa:
templatefile(jsonencode(file.tftpl), {...}). Even better, file.tftpl can be an interpolation of the jsonencode call against the real json content: ${jsonencode({...})}. 


Resources:


https://github.com/nnellans/terraform-guide

No comments: