terraformoktaterraform-provider

How to check if trusted origins are already exist in okta via terraform


I wanted to create a trusted origin in okta via terraform by using "okta_trusted_origin" form a list of urls. I would like to know how can I check if the URL is already exist in okta trusted origins, don't create a new one.

I tried using a filter in "okta_trusted_origins" data source, but I'm not sure what would be the correct search criteria

Here is my code:

resource "okta_trusted_origin" "trusted_origin" {
  count = length(data.okta_trusted_origins.all.trusted_origins) == 0 ? 1 : 0

  name   = var.name
  origin = var.origin
  scopes = var.scopes
}

data "okta_trusted_origins" "all" {
  filter = "trusted_origins.origin eq ${var.origin}"
}

Solution

  • The correct filter syntax is:

    data "okta_trusted_origins" "all" {
      filter = "origin eq \"${var.origin}\""
    }