Specify the ChaosSearch Terraform Resources

How to define ChaosSearch resources using the Terraform provider

In the .tf file where you defined the provider, or any .tf file in the working directory, create resource definitions to define objects or actions like indexing controls. Each of the supported resources (destinations, indexing, monitors, object groups, views, subaccounts, and user groups) have a structure that defines all their related information.

The following topics describe each of the supported resources and their structure. A sample resources file follows.

terraform {
  required_providers {
    chaossearch = {
      source = "ChaosSearch/chaossearch"
      version = "1.0.10"
    }
  }
}

provider "chaossearch" {
  # Configuration options
  url               = "https://mycompany.chaossearch.io"
  access_key_id     = "<<API Key>>"
  secret_access_key = "<<API Secret>>"
  region            = "us-east-1"
  parent_user_id    = "<<Parent ID>>"
}

resource "chaossearch_object_group" "create-object-group" {
  bucket = "zz-cloudt-jsonflex-test-grp"
  source = "chaosdemo-datasets"
  format {
    type = "JSON"
    array_flatten_depth = "1"
    strip_prefix = "true"
    field_selection = jsonencode([{
        "excludes":[
            "Records.requestParameters",
            "Records.responseElements",
            "tags"
         ],
         "type":"blacklist"    
    }])
    vertical_selection = jsonencode([{
        "excludes":[
            "Records.requestParameters",
            "Records.responseElements",
         ],
         "type":"blacklist"
    }])
  }
  filter {
      field = "key"
      prefix = "cloudtrail"
  }
  filter {
      field = "key"
      regex = "cloudtrail\\/AWSLogs\\/250787501321\\/CloudTrail\\/ap\\-northeast.*\\/201.*\\/.*\\/.*\\/250787501321_CloudTrail_ap\\-northeast.*\\.json\\.gz"
  }
  options {
    compression = "GZIP"
    col_renames = jsonencode({
      "Records.accountId": "String",
      "Records.recipientAcountId": "String"
    })
  }
  partition_by = "cloudtrail/AWSLogs/250787501321/CloudTrail/(\\S.+)/2018/12/\\.*"  
}

resource "chaossearch_object_group" "create-object-group1" {
  bucket = "zz-sample-elb-tf-grp"
  source = "chaosdemo-datasets"
  format {
    type             = "LOG"
    pattern = "^(?<timestamp>\\\\d{4}-\\\\d{2}-\\\\d{2}T\\\\d{2}:\\\\d{2}:\\\\d{2}\\\\.\\\\d{6}Z) (?<elb>[^ ]+) (?<client_ip>[\\\\w\\\\.:]+):(?<client_port>\\\\d+) (?<backend_ip>[\\\\w\\\\.:-]+)(?::(?<backend_port>\\\\d+))? (?<request_processing_time>[\\\\d-]+(?:\\\\.\\\\d+)?) (?<backend_processing_time>[\\\\d-]+(?:\\\\.\\\\d+)?) (?<response_processing_time>[\\\\d-]+(?:\\\\.\\\\d+)?) (?<elb_status_code>\\\\d+|-) (?<backend_status_code>\\\\d+|-) (?<received_bytes>\\\\d+) (?<sent_bytes>\\\\d+) \\\"(?:\\\\-|(?<cs_method>\\\\w+|-) (?<cs_uri_stem>[^ \\\\?]+)(?:\\\\?(?<cs_uri_query>[^ ]*))? (?<cs_version>[\\\\w/\\\\.]+|-)\\\\s*)\\\" (?:\\\"\\\"|\\\"(?<user_agent>(?:(?:\\\\\\\\\\\")?[^\\\\\\\"]*)*)\\\") (?<ssl_cipher>[\\\\w-]+) (?<ssl_protocol>[\\\\w\\\\.-]+)(?<body>.*)"
  }
  index_retention {
    overall       = -1
  }
  filter {
      field = "key"
      prefix = "elb"
  }
  filter {
    field = "key"
    regex = "elb\\-logs\\/1509774364000_us\\-east\\-2172\\.16\\.78\\.9_us\\-east\\-2a\\-elb3\\.log"
  }
}

resource "chaossearch_object_group" "create-object-group2" {
  bucket = "zz-sample-csv-tf-grp"
  source = "chaosdemo-datasets"
  format {
    type  = "CSV"
    column_delimiter = ","
    header_row = true
    row_delimiter = "\n"
  }
  index_retention {
    overall       = -1
  }
  filter {
      field = "key"
      prefix = "TPCH"
  }
  filter {
    field = "key"
    regex = "TPCH_SF001\\/orders\\.csv"
  }
  options {
    col_selection = jsonencode ([{
      "excludes": ["o_custkey"],
      "type": "blacklist"
    }])
    col_renames = jsonencode ({
      "o_comment": "Description"
      "o_clerk": "ClerkID"
    })
  }
}
resource "chaossearch_index_model" "index" { 
  bucket_name = "zz-sample-csv-tf-grp" 
  model_mode = 0 
  delete_enabled = false 
  delete_timeout = 0 
}