okta / terraform-provider-okta

A Terraform provider to manage Okta resources, enabling infrastructure-as-code provisioning and management of users, groups, applications, and other Okta objects.
https://registry.terraform.io/providers/okta/okta
Mozilla Public License 2.0
255 stars 206 forks source link

okta_user_schema_property - failed to get application user schema property: json: cannot unmarshal number into Go struct field #1175

Closed Mrorya closed 2 years ago

Mrorya commented 2 years ago

Community Note

Terraform Version

Terraform v1.1.5
on darwin_amd64
+ provider registry.terraform.io/hashicorp/null v3.1.1
+ provider registry.terraform.io/okta/okta v3.29.0

Affected Resource(s)

Terraform Configuration Files

resource "okta_app_user_schema_property" "flex_sb_nesting" {
  app_id      = okta_app_saml.twilio_flex_sandbox.id
  index       = "is_nesting"
  title       = "is_nesting"
  type        = "array"
  master      = "PROFILE_MASTER"
  scope       = "NONE"
  array_type  = "string"
  permissions = "READ_WRITE"
  array_enum  = ["true"]
  array_one_of {
    const = "true"
    title = "true"
  }
  union     = true
  user_type = "default"
}

Expected Behavior

We've currently setup our terraform environment for Okta set to version 3.24.0 - we've been attempting to update beyond that version and we're getting a slew of errors on all custom profile fields we have created for a specific application - these profile fields have no update to the resource, and an example of one of these erroneous profile fields is referenced in the above (but we have about ~20 fields that all seem to have the same error. This is blocking us from proceeding on the provider upgrade as we'd want to make sure we aren't impacting these existing resources or preventing further modification of those resources.

Actual Behavior

Once we've set the provider version, these user schema all return the same error:

│ Error: failed to get application user schema property: json: cannot unmarshal number into Go struct field UserSchemaAttributeItems.definitions.custom.properties.items.enum of type string
│
│   with okta_app_user_schema_property.flex_prod_msgeneral,
│   on twilio_flex_sb-app_user_schema_properties.tf line 1, in resource "okta_app_user_schema_property" "flex_prod_msgeneral":
│    1: resource "okta_app_user_schema_property" "flex_prod_msgeneral" {
│
╵
╷
│ Error: failed to get application user schema property: json: cannot unmarshal number into Go struct field UserSchemaAttributeItems.definitions.custom.properties.items.enum of type string
│
│   with okta_app_user_schema_property.flex_sb_nesting,
│   on twilio_flex_sb-app_user_schema_properties.tf line 28, in resource "okta_app_user_schema_property" "flex_sb_nesting":
│   28: resource "okta_app_user_schema_property" "flex_sb_nesting" {
│
╵

Steps to Reproduce

  1. terraform plan

Important Factoids

Nothing that I'm aware of! Let me know if the log file is necessary

References

I found a couple other issues referencing a similar error, but I could not find any hints as to how it related to what we're seeing ( #701 , #706 )

monde commented 2 years ago

Thanks @Mrorya . Fwiw, this is what I'm currently working on. I fixed the issue in okta-sdk-golang which was released this week https://github.com/okta/okta-sdk-golang/releases/tag/v2.13.0 . It's been a pita juggling it on the Terraform side as they schema's a statically defined at runtime so the Terraform plugin SDK is inflexible for an array like this that can be typed differently depending on input parameters.

monde commented 2 years ago

v3.30.0 specifically addresses this bug, please reopen if this isn't addressed correctly. One thing to note, your example would look like this as the terraform runtime statically defines the schema at runtime and so we had make enum and one_of.const be string but under the hood the type ensures we handle the JSON call to the API correctly:

resource "okta_app_user_schema_property" "flex_sb_nesting" {
  # ...
  array_type  = "boolean"
  array_enum  = ["true"]
  array_one_of {
    const = "true"
    title = "true"
  }
  #...
}

See "important note on" https://registry.terraform.io/providers/okta/okta/latest/docs/resources/app_user_schema_property

Mrorya commented 2 years ago

Thanks @monde - can confirm working on v3.30.0