# Copyright 2021 Google LLC
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#     https://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

variable "project" {
  description = "Project for Dataflow job deployment"
  default     = "keen-opus-356917"
}

variable "organization_id" {
  description = "Organization ID for Org-level Log Sink"
  default     = "770038880827"
}

variable "region" {
  description = "Region to deploy regional-resources into. This must match subnet's region if deploying into existing network (e.g. Shared VPC)"
  default     = "us-east1"
}

variable "environment" {
  default = "prod"
}

variable "service_name" {
  default = "gsirt-splunk-logs"
}

variable "create_network" {
  description = "Boolean value specifying if a new network needs to be created."
  default     = true
  type        = bool
}

variable "network" {
  description = "Network to deploy into"
  default     = "gsirt-export-network"
}

variable "subnet" {
  description = "Subnet to deploy into. This is required when deploying into existing network (e.g. Shared VPC)"
  default     = "gsirt-export-subnet"
}

variable "primary_subnet_cidr" {
  type        = string
  description = "The CIDR Range of the primary subnet"
  default     = "10.128.0.0/20"
}

# Dashboard parameters

variable "workspace" {
  description = "Cloud Monitoring Workspace to create dashboard under. This assumes Workspace is already created and project provided is already added to it. If parameter is empty, no dashboard will be created"
  default     = ""
}

# Log sink details

variable "log_filter" {
  description = "Log filter to use when exporting logs"
  default     = "logName:\"cloudaudit.googleapis.com\""
}

# Dataflow job output

variable "splunk_hec_url" {
  description = "Splunk HEC URL to write data to. Example: https://[MY_SPLUNK_IP_OR_FQDN]:8088"
  default     = "https://hec-external-nlb.gsirtconnect.net:8088"

  validation {
    condition     = can(regex("https?://.*(:[0-9]+)?", var.splunk_hec_url))
    error_message = "Splunk HEC url must of the form <protocol>://<host>:<port> ."
  }
}

# TBD this is exposing token in plaintext in the terraform state
#variable "splunk_hec_token" {
#  description = "Splunk HEC token"
#  sensitive = true
#}
#
#variable "splunk_hec_crypto_key" {
#  description = "Splunk HEC crypto key"
#}
#
#variable "splunk_hec_keyring" {
#  description = "Splunk HEC key ring"
#}

# Dataflow job parameters

variable "dataflow_template_version" {
  type        = string
  description = "Dataflow template version for the replay job."
  default     = "latest"
}

variable "dataflow_job_name" {
  description = "Dataflow job name. No spaces"
  default     = "gsirtlogexport"
}

variable "dataflow_job_machine_type" {
  description = "Dataflow job worker machine type"
  default     = "n1-standard-4"
}

variable "dataflow_job_machine_count" {
  description = "Dataflow job max worker count. Defaults to 2."
  type        = number
  default     = 2
}

variable "dataflow_job_parallelism" {
  description = "Maximum parallel requests to Splunk. Defaults to 8."
  type        = number
  default     = 8
}

variable "dataflow_job_batch_count" {
  description = "Batch count of messages in single request to Splunk. Defaults to 50."
  type        = number
  default     = 50
}

variable "dataflow_job_disable_certificate_validation" {
  description = "Disable SSL certificate validation (default: false)"
  type        = bool
  default     = false
}

variable "dataflow_job_udf_gcs_path" {
  description = "[Optional Dataflow UDF] GCS path for JavaScript file (default: '')"
  default     = ""
}

variable "dataflow_job_udf_function_name" {
  description = "[Optional Dataflow UDF] Name of JavaScript function to be called (default: '')"
  default     = "process"
}

variable "create_workspaces_logging" {
  description = "Boolean value specifying if we deploy the Google Workspaces API logging solution"
  default     = true
  type        = bool
}

variable "workspaces_assets_name" {
  description = "Workspaces API base assets name. alphanumeric with underscores only."
  default     = "gws_gsirt_export"
}

variable "workspaces_assets_location" {
  description = "The geographic location where the assets should reside. See official docs."
  default     = "us-east4"
}

variable "workspaces_alertcenter_email" {
  description = "The Workspaces alert center email address for access to the api."
  default     = "workspacesplunklogs@theorchard.com"
}

variable "workspaces_alerts_api_version" {
  description = "Workspaces Alerts API current version"
  default     = "v1beta1"
}