Multiple values in CSV file

Hi Team,

I am trying to create okta network zone by taking CSV file as input.
my input file is as this:
name,gateways,proxies
NetworkTest3,1.2.3.5/24,2.3.4.5-2.3.4.15

It works perfectly fine when i Keep just one value for gateways and proxies but when I keep multiple values for gateways and proxies it fails saying "make sure its valid CISR format.

name,gateways,proxies
NetworkTest3,1.2.3.5/24 2.3.4.5-2.3.4.15,2.3.4.5-2.3.4.15 3.3.4.5-3.3.4.15
(values are seprated by space)

tf file looks like this:
variable “org_name” {}
variable “api_token” {}
variable “base_url” {}

Enable and configure the Okta provider

terraform {
required_providers {
okta = {
source = “okta/okta”
version = “~> 3.15”
}
}
}

provider “okta” {
org_name = var.org_name
base_url = var.base_url
api_token = var.api_token
}

locals {
instances = csvdecode(file(“./main.csv”))
}
resource “okta_network_zone” “zones” {
type = “IP”
for_each = { for inst in local.instances : inst.name => inst }
name = each.value.name
gateways = [each.value.gateways]
proxies = [each.value.proxies]
}

can someone recommend what can be done?

Regards
Rahul Jha

You would need to split the string to create a list. And then it depends on if you can pass a list to the resource or if you need to loop over that list.

This should do what you need

resource "okta_network_zone" "zones" {
  for_each = { for inst in local.instances : inst.name => inst }
  type     = "IP"
  name     = each.value.name
  gateways = split(" ",each.value.gateways)
  proxies  = split(" ",each.value.proxies)
}

I tested the split with a local and got this:

> local.instances
tolist([
  {
    "gateways" = "1.2.3.5/24 2.3.4.5-2.3.4.15"
    "name" = "NetworkTest3"
    "proxies" = "2.3.4.5-2.3.4.15 3.3.4.5-3.3.4.15"
  },
])
> local.instances[0]
{
  "gateways" = "1.2.3.5/24 2.3.4.5-2.3.4.15"
  "name" = "NetworkTest3"
  "proxies" = "2.3.4.5-2.3.4.15 3.3.4.5-3.3.4.15"
}
> split(" ",local.instances[0].gateways)
tolist([
  "1.2.3.5/24",
  "2.3.4.5-2.3.4.15",
])
>

Thanks Cregkly,

This has worked out for me now.

Regards
Rahul Jha

1 Like