OpsLevel / terraform-provider-opslevel

Terraform provider for OpsLevel.com
https://registry.terraform.io/providers/OpsLevel/opslevel/latest/docs
MIT License
8 stars 5 forks source link

add Terraform config validation to filter predicates #356

Closed davidbloss closed 2 months ago

davidbloss commented 2 months ago

Issues

Add filter predicate validation for Terraform configs

Changelog

Add predicate validation at config time, i.e. terraform validate (pre-plan).

NOTE: predicated on update in this opslevel-go PR

Tophatting

Using this config

resource "opslevel_check_alert_source_usage" "example" {
  name    = "foo"
  enabled = true
  # To set a future enable date remove field 'enabled' and use 'enable_on'
  # enable_on = "2022-05-23T14:14:18.782000Z"
  category = "Z2lkOi8vb3BzbGV2ZWwvQ2F0ZWdvcnkvNjk3OQ"
  level    = "Z2lkOi8vb3BzbGV2ZWwvTGV2ZWwvMzcwOA"
  owner    = "Z2lkOi8vb3BzbGV2ZWwvVGVhbS8xNzQzNA"
  filter   = "Z2lkOi8vb3BzbGV2ZWwvRmlsdGVyLzQ3NDM"
  notes    = "Optional additional info on why this check is run or how to fix it"

  alert_type = "pagerduty" # one of: "pagerduty", "datadog", "opsgenie"
  alert_name_predicate = {
    type  = "exists"
    value = null
  }
}

resource "opslevel_check_repository_grep" "example" {
  name    = "foo"
  enabled = true
  # To set a future enable date remove field 'enabled' and use 'enable_on'
  # enable_on = "2022-05-23T14:14:18.782000Z"
  category = "Z2lkOi8vb3BzbGV2ZWwvQ2F0ZWdvcnkvNjk3OQ"
  level    = "Z2lkOi8vb3BzbGV2ZWwvTGV2ZWwvMzcwOA"
  owner    = "Z2lkOi8vb3BzbGV2ZWwvVGVhbS8xNzQzNA"
  filter   = "Z2lkOi8vb3BzbGV2ZWwvRmlsdGVyLzQ3NDM"
  notes    = "Optional additional info on why this check is run or how to fix it"

  filepaths        = ["kjsd"]
  directory_search = false
  file_contents_predicate = {
    type  = "does_not_exist"
    value = null
  }
}

resource "opslevel_check_repository_file" "example" {
  name    = "foo"
  enabled = true
  # To set a future enable date remove field 'enabled' and use 'enable_on'
  # enable_on = "2022-05-23T14:14:18.782000Z"
  category = "Z2lkOi8vb3BzbGV2ZWwvQ2F0ZWdvcnkvNjk3OQ"
  level    = "Z2lkOi8vb3BzbGV2ZWwvTGV2ZWwvMzcwOA"
  owner    = "Z2lkOi8vb3BzbGV2ZWwvVGVhbS8xNzQzNA"
  filter   = "Z2lkOi8vb3BzbGV2ZWwvRmlsdGVyLzQ3NDM"
  notes    = "Optional additional info on why this check is run or how to fix it"

  filepaths         = ["kjsd"]
  use_absolute_root = false
  directory_search  = false
  file_contents_predicate = {
    type  = "contains"
    value = "asdf"
  }
}

resource "opslevel_check_repository_search" "example" {
  name    = "foo"
  enabled = true
  # To set a future enable date remove field 'enabled' and use 'enable_on'
  # enable_on = "2022-05-23T14:14:18.782000Z"
  category = "Z2lkOi8vb3BzbGV2ZWwvQ2F0ZWdvcnkvNjk3OQ"
  level    = "Z2lkOi8vb3BzbGV2ZWwvTGV2ZWwvMzcwOA"
  owner    = "Z2lkOi8vb3BzbGV2ZWwvVGVhbS8xNzQzNA"
  filter   = "Z2lkOi8vb3BzbGV2ZWwvRmlsdGVyLzQ3NDM"
  notes    = "Optional additional info on why this check is run or how to fix it"

  file_contents_predicate = {
    type  = "contains"
    value = "asdf"
  }
}

resource "opslevel_check_service_ownership" "example" {
  name    = "foo"
  enabled = true
  # To set a future enable date remove field 'enabled' and use 'enable_on'
  # enable_on = "2022-05-23T14:14:18.782000Z"
  category = "Z2lkOi8vb3BzbGV2ZWwvQ2F0ZWdvcnkvNjk3OQ"
  level    = "Z2lkOi8vb3BzbGV2ZWwvTGV2ZWwvMzcwOA"
  owner    = "Z2lkOi8vb3BzbGV2ZWwvVGVhbS8xNzQzNA"
  filter   = "Z2lkOi8vb3BzbGV2ZWwvRmlsdGVyLzQ3NDM"
  notes    = "Optional additional info on why this check is run or how to fix it"

  tag_predicate = {
    type  = "contains"
    value = "asdf"
  }
}

resource "opslevel_check_service_property" "example" {
  name    = "foo"
  enabled = true
  # To set a future enable date remove field 'enabled' and use 'enable_on'
  # enable_on = "2022-05-23T14:14:18.782000Z"
  category = "Z2lkOi8vb3BzbGV2ZWwvQ2F0ZWdvcnkvNjk3OQ"
  level    = "Z2lkOi8vb3BzbGV2ZWwvTGV2ZWwvMzcwOA"
  owner    = "Z2lkOi8vb3BzbGV2ZWwvVGVhbS8xNzQzNA"
  filter   = "Z2lkOi8vb3BzbGV2ZWwvRmlsdGVyLzQ3NDM"
  notes    = "Optional additional info on why this check is run or how to fix it"

  property = "name"
  predicate = {
    type  = "contains"
    value = "asdf"
  }
}

resource "opslevel_check_tag_defined" "example" {
  name    = "foo"
  enabled = true
  # To set a future enable date remove field 'enabled' and use 'enable_on'
  # enable_on = "2022-05-23T14:14:18.782000Z"
  category = "Z2lkOi8vb3BzbGV2ZWwvQ2F0ZWdvcnkvNjk3OQ"
  level    = "Z2lkOi8vb3BzbGV2ZWwvTGV2ZWwvMzcwOA"
  owner    = "Z2lkOi8vb3BzbGV2ZWwvVGVhbS8xNzQzNA"
  filter   = "Z2lkOi8vb3BzbGV2ZWwvRmlsdGVyLzQ3NDM"
  notes    = "Optional additional info on why this check is run or how to fix it"

  tag_key = "name"
  tag_predicate = {
    type  = "contains"
    value = "asdf"
  }
}

resource "opslevel_check_tool_usage" "example" {
  name    = "foo"
  enabled = true
  # To set a future enable date remove field 'enabled' and use 'enable_on'
  # enable_on = "2022-05-23T14:14:18.782000Z"
  category = "Z2lkOi8vb3BzbGV2ZWwvQ2F0ZWdvcnkvNjk3OQ"
  level    = "Z2lkOi8vb3BzbGV2ZWwvTGV2ZWwvMzcwOA"
  owner    = "Z2lkOi8vb3BzbGV2ZWwvVGVhbS8xNzQzNA"
  filter   = "Z2lkOi8vb3BzbGV2ZWwvRmlsdGVyLzQ3NDM"
  notes    = "Optional additional info on why this check is run or how to fix it"

  tool_category = "runbooks"
  environment_predicate = {
    type  = "contains"
    value = "asdf"
  }
  tool_name_predicate = {
    type  = "contains"
    value = "asdf"
  }
  tool_url_predicate = {
    type  = "contains"
    value = "asdf"
  }
}

Modify the type and value of each