Use of yaml file inside terraform

Hi All,

I am new in terraform and currently trying to use it to configure Okta networks.

I have a YAML file that consists of gateways, proxies, and IPs, I want my tf file to read the network.yaml and set all the values given inside network.yaml in okta network.

I want to know how can i refer a YAML file or text file from tf file.

Let me know if this requires more details.

Thanks for help
Rahul Jha

You can use the file and yamldecode functions together to read a YAML file into a local variable.

Hi Stuart,

I have yaml file with below format

---
kind: Zone
apiVersion: v1alpha1
metadata:
  name: first
spec:
  type: IP
  # defaults to usage: POLICY
  # usage: POLICY
  gateways:
  - 0.0.0.0/16
  proxies:
  - 0.0.0.0/16
  - 0.0.0.0

and my tf code is

locals {
zones = lookup(yamldecode(file("./base_network.yaml")), "Zone", {})
}
resource "okta_network_zone" "zones" {
  for_each          = local.zones
  name              = each.value.name
  type              = lookup(each.value, "type", null)
  usage             = lookup(each.value, "usage", null)
  gateways          = lookup(each.value, "gateways", null)
  proxies           = lookup(each.value, "proxies", null)
  dynamic_locations = lookup(each.value, "dynamicLocations", null)
}

its giving me “This character is not used withing the language” any idea how can i use it to set networks zone in okta.

Regards