Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Terragrunt – how to deal with raw JSON

I’m using terragrunt to manage okta resources. I’m using okta_user resource and I want to add custom_profile_attributes to my variables. In my vars.tf file I have:

variable "custom_profile_attributes" {
  description = "custom profile attributes"
  type = map(any)
  default = {}
}

and in main.tf:

resource "okta_user" "user" {
  first_name                = var.first_name
  last_name                 = var.last_name
  login                     = var.email
  email                     = var.email
  status                    = var.status
  custom_profile_attributes = var.custom_profile_attributes
}

and my terragrunt.hcl:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

inputs = {
  first_name  = title(local.full_name[0])
  last_name   = title(local.full_name[1])
  email       = "${local.full_name[0]}.${local.full_name[1]}@company.com"
  status      = "ACTIVE"
  groups      = [dependency.team.outputs.okta_group_id]
  admin_roles = ["USER_ADMIN"]
  lifecycle = {
    ignore_changes = ["admin_roles"]
  }
  custom_profile_attributes = {
    "tenant_id" : "ssotest",
  }
}

and while running terragrunt apply I get:

│ Error: Incorrect attribute value type
│ 
│   on main.tf line 7, in resource "okta_user" "user":
│    7:   custom_profile_attributes = var.custom_profile_attributes
│     ├────────────────
│     │ var.custom_profile_attributes is a map of dynamic
│ 
│ Inappropriate value for attribute "custom_profile_attributes": string
│ required.

And I can see that string is required, but even changing type to string I get the same error. Can somebody tell me what is wrong here?

>Solution :

You can use jsonencode built-in function for this. The variable would then stay of type map(any), but you would provide it like this:

  custom_profile_attributes = {
    tenant_id = "ssotest"
  }

Then, in the Okta resource, you would do the following:

resource "okta_user" "user" {
  first_name                = var.first_name
  last_name                 = var.last_name
  login                     = var.email
  email                     = var.email
  status                    = var.status
  custom_profile_attributes = jsonencode(var.custom_profile_attributes)
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading