From 6843d55b791a679e30d11afaa9f2d1003e439652 Mon Sep 17 00:00:00 2001 From: Itzik Gabay Date: Thu, 25 Jul 2024 15:29:30 +0300 Subject: [PATCH] add new version of module --- main.tf | 853 ++++++++------------------------------------------- outputs.tf | 19 -- variables.tf | 228 ++++---------- versions.tf | 19 -- 4 files changed, 183 insertions(+), 936 deletions(-) diff --git a/main.tf b/main.tf index 98a2b1e..2131dc8 100644 --- a/main.tf +++ b/main.tf @@ -1,775 +1,168 @@ -resource "castai_gke_cluster" "castai_cluster" { - project_id = var.project_id - location = var.gke_cluster_location - name = var.gke_cluster_name - delete_nodes_on_disconnect = var.delete_nodes_on_disconnect - credentials_json = var.gke_credentials +data "google_container_cluster" "my_cluster" { + name = var.gke_cluster_name + location = var.region + project = var.project_id } -resource "castai_node_configuration" "this" { - for_each = { for k, v in var.node_configurations : k => v } +data "google_client_config" "default" {} - cluster_id = castai_gke_cluster.castai_cluster.id - - name = try(each.value.name, each.key) - disk_cpu_ratio = try(each.value.disk_cpu_ratio, 0) - drain_timeout_sec = try(each.value.drain_timeout_sec, 0) - min_disk_size = try(each.value.min_disk_size, 100) - subnets = try(each.value.subnets, null) - ssh_public_key = try(each.value.ssh_public_key, null) - image = try(each.value.image, null) - tags = try(each.value.tags, {}) - init_script = try(each.value.init_script, null) - - gke { - max_pods_per_node = try(each.value.max_pods_per_node, 110) - network_tags = try(each.value.network_tags, null) - disk_type = try(each.value.disk_type, null) - use_ephemeral_storage_local_ssd = try(each.value.use_ephemeral_storage_local_ssd, null) - } -} - -resource "castai_node_configuration_default" "this" { - cluster_id = castai_gke_cluster.castai_cluster.id - configuration_id = var.default_node_configuration -} - -resource "castai_node_template" "this" { - for_each = { for k, v in var.node_templates : k => v } - - cluster_id = castai_gke_cluster.castai_cluster.id - - name = try(each.value.name, each.key) - configuration_id = try(each.value.configuration_id, null) - is_default = try(each.value.is_default, false) - is_enabled = try(each.value.is_enabled, true) - should_taint = try(each.value.should_taint, true) - custom_instances_enabled = try(each.value.custom_instances_enabled, false) - custom_instances_with_extended_memory_enabled = try(each.value.custom_instances_with_extended_memory_enabled, false) - - custom_labels = try(each.value.custom_labels, {}) - - dynamic "custom_taints" { - for_each = flatten([lookup(each.value, "custom_taints", [])]) - - content { - key = try(custom_taints.value.key, null) - value = try(custom_taints.value.value, null) - effect = try(custom_taints.value.effect, null) - } - } - - dynamic "constraints" { - for_each = [for constraints in flatten([lookup(each.value, "constraints", [])]) : constraints if constraints != null] - - content { - compute_optimized = try(constraints.value.compute_optimized, null) - storage_optimized = try(constraints.value.storage_optimized, null) - compute_optimized_state = try(constraints.value.compute_optimized_state, "") - storage_optimized_state = try(constraints.value.storage_optimized_state, "") - is_gpu_only = try(constraints.value.is_gpu_only, false) - spot = try(constraints.value.spot, false) - on_demand = try(constraints.value.on_demand, null) - use_spot_fallbacks = try(constraints.value.use_spot_fallbacks, false) - fallback_restore_rate_seconds = try(constraints.value.fallback_restore_rate_seconds, null) - enable_spot_diversity = try(constraints.value.enable_spot_diversity, false) - spot_diversity_price_increase_limit_percent = try(constraints.value.spot_diversity_price_increase_limit_percent, null) - spot_interruption_predictions_enabled = try(constraints.value.spot_interruption_predictions_enabled, false) - spot_interruption_predictions_type = try(constraints.value.spot_interruption_predictions_type, null) - min_cpu = try(constraints.value.min_cpu, null) - max_cpu = try(constraints.value.max_cpu, null) - min_memory = try(constraints.value.min_memory, null) - max_memory = try(constraints.value.max_memory, null) - architectures = try(constraints.value.architectures, ["amd64"]) - azs = try(constraints.value.azs, null) - - dynamic "instance_families" { - for_each = [for instance_families in flatten([lookup(constraints.value, "instance_families", [])]) : instance_families if instance_families != null] - - content { - include = try(instance_families.value.include, []) - exclude = try(instance_families.value.exclude, []) - } - } - - dynamic "gpu" { - for_each = [for gpu in flatten([lookup(constraints.value, "gpu", [])]) : gpu if gpu != null] - - content { - manufacturers = try(gpu.value.manufacturers, []) - include_names = try(gpu.value.include_names, []) - exclude_names = try(gpu.value.exclude_names, []) - min_count = try(gpu.value.min_count, null) - max_count = try(gpu.value.max_count, null) - } - } - - dynamic "custom_priority" { - for_each = [for custom_priority in flatten([lookup(constraints.value, "custom_priority", [])]) : custom_priority if custom_priority != null] - - content { - instance_families = try(custom_priority.value.instance_families, []) - spot = try(custom_priority.value.spot, false) - on_demand = try(custom_priority.value.on_demand, false) - } - } - - dynamic "dedicated_node_affinity" { - for_each = flatten([lookup(constraints.value, "dedicated_node_affinity", [])]) - - content { - name = try(dedicated_node_affinity.value.name, null) - az_name = try(dedicated_node_affinity.value.az_name, null) - instance_types = try(dedicated_node_affinity.value.instance_types, []) - - dynamic "affinity" { - for_each = try(dedicated_node_affinity.value.affinity, {}) - - content { - key = try(affinity.key, null) - operator = try(affinity.operator, null) - values = try(affinity.values, []) - } - } - } - } - } - } - depends_on = [castai_autoscaler.castai_autoscaler_policies] -} - -resource "helm_release" "castai_agent" { - name = "castai-agent" - repository = "https://castai.github.io/helm-charts" - chart = "castai-agent" - namespace = "castai-agent" - create_namespace = true - cleanup_on_fail = true - wait = true - - version = var.agent_version - values = var.agent_values - - set { - name = "replicaCount" - value = "2" - } - - set { - name = "provider" - value = "gke" - } - - set { - name = "additionalEnv.STATIC_CLUSTER_ID" - value = castai_gke_cluster.castai_cluster.id - } - - set { - name = "createNamespace" - value = "false" - } - - dynamic "set" { - for_each = var.api_url != "" ? [var.api_url] : [] - content { - name = "apiURL" - value = var.api_url - } - } - - dynamic "set" { - for_each = var.castai_components_labels - content { - name = "podLabels.${set.key}" - value = set.value - } - } - - set_sensitive { - name = "apiKey" - value = castai_gke_cluster.castai_cluster.cluster_token - } -} - -resource "helm_release" "castai_cluster_controller" { - count = var.self_managed ? 0 : 1 - - name = "cluster-controller" - repository = "https://castai.github.io/helm-charts" - chart = "castai-cluster-controller" - namespace = "castai-agent" - create_namespace = true - cleanup_on_fail = true - wait = true - - version = var.cluster_controller_version - values = var.cluster_controller_values - - set { - name = "castai.clusterID" - value = castai_gke_cluster.castai_cluster.id - } - - dynamic "set" { - for_each = var.api_url != "" ? [var.api_url] : [] - content { - name = "castai.apiURL" - value = var.api_url - } - } - - set_sensitive { - name = "castai.apiKey" - value = castai_gke_cluster.castai_cluster.cluster_token - } - - dynamic "set" { - for_each = var.castai_components_labels - content { - name = "podLabels.${set.key}" - value = set.value - } - } - - depends_on = [helm_release.castai_agent] - - lifecycle { - ignore_changes = [version] +provider "helm" { + kubernetes { + host = "https://${data.google_container_cluster.my_cluster.endpoint}" + token = data.google_client_config.default.access_token + cluster_ca_certificate = base64decode(data.google_container_cluster.my_cluster.master_auth.0.cluster_ca_certificate) } } -resource "helm_release" "castai_cluster_controller_self_managed" { - count = var.self_managed ? 1 : 0 - - name = "cluster-controller" - repository = "https://castai.github.io/helm-charts" - chart = "castai-cluster-controller" - namespace = "castai-agent" - create_namespace = true - cleanup_on_fail = true - wait = true - - version = var.cluster_controller_version - values = var.cluster_controller_values - - set { - name = "castai.clusterID" - value = castai_gke_cluster.castai_cluster.id - } - - dynamic "set" { - for_each = var.api_url != "" ? [var.api_url] : [] - content { - name = "castai.apiURL" - value = var.api_url - } - } - set_sensitive { - name = "castai.apiKey" - value = castai_gke_cluster.castai_cluster.cluster_token - } - dynamic "set" { - for_each = var.castai_components_labels - content { - name = "podLabels.${set.key}" - value = set.value - } - } - depends_on = [helm_release.castai_agent] +module "castai_gke_iam" { + source = "castai/gke-iam/castai" + project_id = var.project_id + gke_cluster_name = var.gke_cluster_name + service_accounts_unique_ids = var.service_accounts_unique_ids + depends_on = [ data.google_container_cluster.my_cluster, data.google_client_config.default ] } -resource "null_resource" "wait_for_cluster" { - count = var.wait_for_cluster_ready ? 1 : 0 - depends_on = [helm_release.castai_cluster_controller, helm_release.castai_agent] - provisioner "local-exec" { - environment = { - API_KEY = var.castai_api_token - } - command = <<-EOT - RETRY_COUNT=20 - POOLING_INTERVAL=30 - for i in $(seq 1 $RETRY_COUNT); do - sleep $POOLING_INTERVAL - curl -s ${var.api_url}/v1/kubernetes/external-clusters/${castai_gke_cluster.castai_cluster.id} -H "x-api-key: $API_KEY" | grep '"status"\s*:\s*"ready"' && exit 0 - done +module "castai-gke-cluster" { + source = "castai/gke-cluster/castai" + wait_for_cluster_ready = var.wait_for_cluster_ready + project_id = var.project_id + gke_cluster_name = var.gke_cluster_name + gke_cluster_location = var.region - echo "Cluster is not ready after 10 minutes" - exit 1 - EOT + gke_credentials = module.castai_gke_iam.private_key + delete_nodes_on_disconnect = true + autoscaler_policies_json = null - interpreter = ["bash", "-c"] - } -} - -resource "helm_release" "castai_evictor" { - count = var.self_managed ? 0 : 1 + default_node_configuration = module.castai-gke-cluster.castai_node_configurations["castaidefault"] - name = "castai-evictor" - repository = "https://castai.github.io/helm-charts" - chart = "castai-evictor" - namespace = "castai-agent" - create_namespace = true - cleanup_on_fail = true - wait = true + node_configurations = { + castaidefault = { + disk_cpu_ratio = 25 + subnets = [var.subnetwork_self_link] + tags = var.tags - version = var.evictor_version - values = var.evictor_values - - set { - name = "replicaCount" - value = "0" - } + max_pods_per_node = 110 + network_tags = ["dev"] + disk_type = "pd-balanced" - set { - name = "castai-evictor-ext.enabled" - value = "false" - } - - dynamic "set" { - for_each = var.castai_components_labels - content { - name = "podLabels.${set.key}" - value = set.value } + test_node_config = { + disk_cpu_ratio = 10 + subnets = [var.subnetwork_self_link] + tags = {} + max_pods_per_node = 40 + disk_type = "pd-ssd", + network_tags = ["dev"] + } } + node_templates = { + default_by_castai = { + name = "default-by-castai" + configuration_id = module.castai-gke-cluster.castai_node_configurations["castaidefault"] + is_default = true + is_enabled = true + should_taint = false - depends_on = [helm_release.castai_agent] - - lifecycle { - ignore_changes = [set, version] - } -} - -resource "helm_release" "castai_evictor_self_managed" { - count = var.self_managed ? 1 : 0 - - name = "castai-evictor" - repository = "https://castai.github.io/helm-charts" - chart = "castai-evictor" - namespace = "castai-agent" - create_namespace = true - cleanup_on_fail = true - wait = true - - version = var.evictor_version - values = var.evictor_values - - set { - name = "castai-evictor-ext.enabled" - value = "false" - } + constraints = { + on_demand = true + spot = true + use_spot_fallbacks = true - dynamic "set" { - for_each = var.castai_components_labels - content { - name = "podLabels.${set.key}" - value = set.value - } - } - - depends_on = [helm_release.castai_agent] -} - -resource "helm_release" "castai_evictor_ext" { - name = "castai-evictor-ext" - repository = "https://castai.github.io/helm-charts" - chart = "castai-evictor-ext" - namespace = "castai-agent" - create_namespace = false - cleanup_on_fail = true - wait = true - - version = var.evictor_ext_version - values = var.evictor_ext_values - - depends_on = [helm_release.castai_evictor] -} - -resource "helm_release" "castai_pod_pinner" { - count = var.self_managed ? 0 : 1 - - name = "castai-pod-pinner" - repository = "https://castai.github.io/helm-charts" - chart = "castai-pod-pinner" - namespace = "castai-agent" - create_namespace = true - cleanup_on_fail = true - wait = true - - version = var.pod_pinner_version - values = var.pod_pinner_values - - set { - name = "castai.clusterID" - value = castai_gke_cluster.castai_cluster.id - } - - dynamic "set" { - for_each = var.api_url != "" ? [var.api_url] : [] - content { - name = "castai.apiURL" - value = var.api_url - } - } - - set_sensitive { - name = "castai.apiKey" - value = castai_gke_cluster.castai_cluster.cluster_token - } - - dynamic "set" { - for_each = var.grpc_url != "" ? [var.grpc_url] : [] - content { - name = "castai.grpcURL" - value = var.grpc_url - } - } - - dynamic "set" { - for_each = var.castai_components_labels - content { - name = "podLabels.${set.key}" - value = set.value - } - } - - set { - name = "replicaCount" - value = "0" - } - - depends_on = [helm_release.castai_agent] - - lifecycle { - ignore_changes = [set, version] - } -} - -resource "helm_release" "castai_pod_pinner_self_managed" { - count = var.self_managed ? 1 : 0 - - name = "castai-pod-pinner" - repository = "https://castai.github.io/helm-charts" - chart = "castai-pod-pinner" - namespace = "castai-agent" - create_namespace = true - cleanup_on_fail = true - wait = true - - version = var.pod_pinner_version - values = var.pod_pinner_values - - set { - name = "castai.clusterID" - value = castai_gke_cluster.castai_cluster.id - } - - dynamic "set" { - for_each = var.api_url != "" ? [var.api_url] : [] - content { - name = "castai.apiURL" - value = var.api_url - } - } - - set_sensitive { - name = "castai.apiKey" - value = castai_gke_cluster.castai_cluster.cluster_token - } - - dynamic "set" { - for_each = var.grpc_url != "" ? [var.grpc_url] : [] - content { - name = "castai.grpcURL" - value = var.grpc_url - } - } - - dynamic "set" { - for_each = var.castai_components_labels - content { - name = "podLabels.${set.key}" - value = set.value - } - } - - depends_on = [helm_release.castai_agent] -} - -resource "helm_release" "castai_spot_handler" { - name = "castai-spot-handler" - repository = "https://castai.github.io/helm-charts" - chart = "castai-spot-handler" - namespace = "castai-agent" - create_namespace = true - cleanup_on_fail = true - wait = true - - version = var.spot_handler_version - values = var.spot_handler_values - - set { - name = "castai.provider" - value = "gcp" - } - - set { - name = "createNamespace" - value = "false" - } - - dynamic "set" { - for_each = var.api_url != "" ? [var.api_url] : [] - content { - name = "castai.apiURL" - value = var.api_url - } - } - - set { - name = "castai.clusterID" - value = castai_gke_cluster.castai_cluster.id - } - - dynamic "set" { - for_each = var.castai_components_labels - content { - name = "podLabels.${set.key}" - value = set.value - } - } - - depends_on = [helm_release.castai_agent] -} - -resource "helm_release" "castai_kvisor" { - count = var.install_security_agent && !var.self_managed ? 1 : 0 - - name = "castai-kvisor" - repository = "https://castai.github.io/helm-charts" - chart = "castai-kvisor" - namespace = "castai-agent" - create_namespace = true - cleanup_on_fail = true - - version = var.kvisor_version - values = var.kvisor_values - - lifecycle { - ignore_changes = [version] - } - - set { - name = "castai.clusterID" - value = castai_gke_cluster.castai_cluster.id - } - - set_sensitive { - name = "castai.apiKey" - value = castai_gke_cluster.castai_cluster.cluster_token - } - - set { - name = "castai.grpcAddr" - value = var.api_grpc_addr - } - - dynamic "set" { - for_each = var.kvisor_controller_extra_args - content { - name = "controller.extraArgs.${set.key}" - value = set.value + enable_spot_diversity = false + spot_diversity_price_increase_limit_percent = 20 + } } - } - - set { - name = "controller.extraArgs.kube-bench-cloud-provider" - value = "gke" - } -} - -resource "helm_release" "castai_kvisor_self_managed" { - count = var.install_security_agent && var.self_managed ? 1 : 0 + spot_tmpl = { + configuration_id = module.castai-gke-cluster.castai_node_configurations["castaidefault"] + is_enabled = true + should_taint = true - name = "castai-kvisor" - repository = "https://castai.github.io/helm-charts" - chart = "castai-kvisor" - namespace = "castai-agent" - create_namespace = true - cleanup_on_fail = true - - version = var.kvisor_version - values = var.kvisor_values - - set { - name = "castai.clusterID" - value = castai_gke_cluster.castai_cluster.id - } - - set_sensitive { - name = "castai.apiKey" - value = castai_gke_cluster.castai_cluster.cluster_token - } + custom_labels = { + custom-label-key-1 = "custom-label-value-1" + custom-label-key-2 = "custom-label-value-2" + } - set { - name = "castai.grpcAddr" - value = var.api_grpc_addr - } + custom_taints = [ + { + key = "custom-taint-key-1" + value = "custom-taint-value-1" + effect = "NoSchedule" + }, + { + key = "custom-taint-key-2" + value = "custom-taint-value-2" + effect = "NoSchedule" + } + ] + constraints = { + fallback_restore_rate_seconds = 1800 + spot = true + use_spot_fallbacks = true + min_cpu = 4 + max_cpu = 100 + instance_families = { + exclude = ["e2"] + } + compute_optimized_state = "disabled" + storage_optimized_state = "disabled" + } - dynamic "set" { - for_each = var.kvisor_controller_extra_args - content { - name = "controller.extraArgs.${set.key}" - value = set.value + custom_instances_enabled = true } } - set { - name = "controller.extraArgs.kube-bench-cloud-provider" - value = "gke" - } -} - -resource "castai_autoscaler" "castai_autoscaler_policies" { - cluster_id = castai_gke_cluster.castai_cluster.id - autoscaler_policies_json = var.autoscaler_policies_json - dynamic "autoscaler_settings" { - for_each = var.autoscaler_settings != null ? [var.autoscaler_settings] : [] + autoscaler_settings = { + enabled = true + node_templates_partial_matching_enabled = false - content { - enabled = try(autoscaler_settings.value.enabled, null) - is_scoped_mode = try(autoscaler_settings.value.is_scoped_mode, null) - node_templates_partial_matching_enabled = try(autoscaler_settings.value.node_templates_partial_matching_enabled, null) + unschedulable_pods = { + enabled = true - dynamic "unschedulable_pods" { - for_each = try([autoscaler_settings.value.unschedulable_pods], []) - - content { - enabled = try(unschedulable_pods.value.enabled, null) - custom_instances_enabled = try(unschedulable_pods.value.custom_instances_enabled, null) - - dynamic "headroom" { - for_each = try([unschedulable_pods.value.headroom], []) - - content { - enabled = try(headroom.value.enabled, null) - cpu_percentage = try(headroom.value.cpu_percentage, null) - memory_percentage = try(headroom.value.memory_percentage, null) - } - } - - dynamic "headroom_spot" { - for_each = try([unschedulable_pods.value.headroom_spot], []) - - content { - enabled = try(headroom_spot.value.enabled, null) - cpu_percentage = try(headroom_spot.value.cpu_percentage, null) - memory_percentage = try(headroom_spot.value.memory_percentage, null) - } - } - - dynamic "node_constraints" { - for_each = try([unschedulable_pods.value.node_constraints], []) - - content { - enabled = try(node_constraints.value.enabled, null) - min_cpu_cores = try(node_constraints.value.min_cpu_cores, null) - max_cpu_cores = try(node_constraints.value.max_cpu_cores, null) - min_ram_mib = try(node_constraints.value.min_ram_mib, null) - max_ram_mib = try(node_constraints.value.max_ram_mib, null) - } - } - } + headroom = { + enabled = true + cpu_percentage = 10 + memory_percentage = 10 } - dynamic "cluster_limits" { - for_each = try([autoscaler_settings.value.cluster_limits], []) - - content { - enabled = try(cluster_limits.value.enabled, null) - - - dynamic "cpu" { - for_each = try([cluster_limits.value.cpu], []) - - content { - min_cores = try(cpu.value.min_cores, null) - max_cores = try(cpu.value.max_cores, null) - } - } - } + headroom_spot = { + enabled = true + cpu_percentage = 10 + memory_percentage = 10 } + } - dynamic "spot_instances" { - for_each = try([autoscaler_settings.value.spot_instances], []) - - content { - enabled = try(spot_instances.value.enabled, null) - max_reclaim_rate = try(spot_instances.value.max_reclaim_rate, null) - spot_diversity_enabled = try(spot_instances.value.spot_diversity_enabled, null) - spot_diversity_price_increase_limit = try(spot_instances.value.spot_diversity_price_increase_limit, null) - - dynamic "spot_backups" { - for_each = try([spot_instances.value.spot_backups], []) - - content { - enabled = try(spot_backups.value.enabled, null) - spot_backup_restore_rate_seconds = try(spot_backups.value.spot_backup_restore_rate_seconds, null) - } - } - - dynamic "spot_interruption_predictions" { - for_each = try([spot_instances.value.spot_interruption_predictions], []) + node_downscaler = { + enabled = true - content { - enabled = try(spot_interruption_predictions.value.enabled, null) - spot_interruption_predictions_type = try(spot_interruption_predictions.value.spot_interruption_predictions_type, null) - } - } - } + empty_nodes = { + enabled = true } - dynamic "node_downscaler" { - for_each = try([autoscaler_settings.value.node_downscaler], []) - - content { - enabled = try(node_downscaler.value.enabled, null) - - dynamic "empty_nodes" { - for_each = try([node_downscaler.value.empty_nodes], []) - - content { - enabled = try(empty_nodes.value.enabled, null) - delay_seconds = try(empty_nodes.value.delay_seconds, null) - } - } + evictor = { + aggressive_mode = false + cycle_interval = "5s10s" + dry_run = false + enabled = true + node_grace_period_minutes = 10 + scoped_mode = false + } + } - dynamic "evictor" { - for_each = try([node_downscaler.value.evictor], []) + cluster_limits = { + enabled = true - content { - enabled = try(evictor.value.enabled, null) - dry_run = try(evictor.value.dry_run, null) - aggressive_mode = try(evictor.value.aggressive_mode, null) - scoped_mode = try(evictor.value.scoped_mode, null) - cycle_interval = try(evictor.value.cycle_interval, null) - node_grace_period_minutes = try(evictor.value.node_grace_period_minutes, null) - pod_eviction_failure_back_off_interval = try(evictor.value.pod_eviction_failure_back_off_interval, null) - ignore_pod_disruption_budgets = try(evictor.value.ignore_pod_disruption_budgets, null) - } - } - } + cpu = { + max_cores = 20 + min_cores = 1 } } } - - depends_on = [helm_release.castai_agent, helm_release.castai_evictor] -} + depends_on = [data.google_container_cluster.my_cluster, data.google_client_config.default, module.castai_gke_iam ] +} \ No newline at end of file diff --git a/outputs.tf b/outputs.tf index 0f61b4f..e69de29 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,19 +0,0 @@ -output "cluster_id" { - value = castai_gke_cluster.castai_cluster.id - description = "CAST.AI cluster id, which can be used for accessing cluster data using API" - sensitive = true -} - -output "castai_node_configurations" { - description = "Map of node configurations ids by name" - value = { - for k, v in castai_node_configuration.this : v.name => v.id - } -} - -output "castai_node_templates" { - description = "Map of node template by name" - value = { - for k, v in castai_node_template.this : v.name => v.name - } -} diff --git a/variables.tf b/variables.tf index f8bf03a..9b629ca 100644 --- a/variables.tf +++ b/variables.tf @@ -1,198 +1,90 @@ -variable "api_url" { - type = string - description = "URL of alternative CAST AI API to be used during development or testing" - default = "https://api.cast.ai" -} - -variable "castai_api_token" { - type = string - description = "Optional CAST AI API token created in console.cast.ai API Access keys section. Used only when `wait_for_cluster_ready` is set to true" - sensitive = true - default = "" -} - -variable "grpc_url" { - type = string - description = "gRPC endpoint used by pod-pinner" - default = "grpc.cast.ai:443" -} - -variable "api_grpc_addr" { - type = string - description = "CAST AI GRPC API address" - default = "api-grpc.cast.ai:443" -} - -variable "kvisor_controller_extra_args" { - type = map(string) - description = "Extra arguments for the kvisor controller. Optionally enable kvisor to lint Kubernetes YAML manifests, scan workload images and check if workloads pass CIS Kubernetes Benchmarks as well as NSA, WASP and PCI recommendations." - default = { - "kube-linter-enabled" = "true" - "image-scan-enabled" = "true" - "kube-bench-enabled" = "true" - } -} - variable "project_id" { + description = "The ID of the project" type = string - description = "The project id from GCP" } variable "gke_cluster_name" { + description = "The name of the GKE cluster" type = string - description = "Name of the cluster to be connected to CAST AI." } -variable "autoscaler_policies_json" { +variable "region" { + description = "The region of the GKE cluster" type = string - description = "Optional json object to override CAST AI cluster autoscaler policies. Deprecated, use `autoscaler_settings` instead." - default = null } -variable "autoscaler_settings" { - type = any - description = "Optional Autoscaler policy definitions to override current autoscaler settings" - default = null +variable "service_accounts_unique_ids" { + description = "Unique IDs of the service accounts" + type = list(string) + default = [] } -variable "delete_nodes_on_disconnect" { +variable "wait_for_cluster_ready" { + description = "Flag to wait for cluster readiness" type = bool - description = "Optionally delete Cast AI created nodes when the cluster is destroyed" default = false } -variable "gke_cluster_location" { - type = string - description = "Location of the cluster to be connected to CAST AI. Can be region or zone for zonal clusters" - -} - -variable "gke_credentials" { - type = string - description = "Optional GCP Service account credentials.json" -} - -variable "castai_components_labels" { - type = map(any) - description = "Optional additional Kubernetes labels for CAST AI pods" - default = {} -} - -variable "node_configurations" { - type = any - description = "Map of GKE node configurations to create" - default = {} -} - -variable "default_node_configuration" { +variable "subnetwork_self_link" { + description = "Self link of the subnetwork" type = string - description = "ID of the default node configuration" } -variable "node_templates" { - type = any - description = "Map of node templates to create" +variable "tags" { + description = "Tags for the node configuration" + type = map(string) default = {} } -variable "install_security_agent" { - type = bool - default = false - description = "Optional flag for installation of security agent (https://docs.cast.ai/product-overview/console/security-insights/)" -} - -variable "agent_version" { - description = "Version of castai-agent helm chart. Default latest" - type = string - default = null -} - -variable "cluster_controller_version" { - description = "Version of castai-cluster-controller helm chart. Default latest" - type = string - default = null -} - -variable "evictor_version" { - description = "Version of castai-evictor chart. Default latest" - type = string - default = null -} - -variable "evictor_ext_version" { - description = "Version of castai-evictor-ext chart. Default latest" - type = string - default = null -} - -variable "pod_pinner_version" { - description = "Version of pod-pinner helm chart. Default latest" - type = string - default = null -} - -variable "spot_handler_version" { - description = "Version of castai-spot-handler helm chart. Default latest" - type = string - default = null -} - -variable "kvisor_version" { - description = "Version of kvisor chart. If not provided, latest version will be used." +variable "autoscaler_policies_json" { + description = "Autoscaler policies in JSON format" type = string default = null } -variable "agent_values" { - description = "List of YAML formatted string values for agent helm chart" - type = list(string) - default = [] -} - -variable "spot_handler_values" { - description = "List of YAML formatted string values for spot-handler helm chart" - type = list(string) - default = [] -} - -variable "cluster_controller_values" { - description = "List of YAML formatted string values for cluster-controller helm chart" - type = list(string) - default = [] -} - -variable "evictor_values" { - description = "List of YAML formatted string values for evictor helm chart" - type = list(string) - default = [] -} - -variable "evictor_ext_values" { - description = "List of YAML formatted string with evictor-ext values" - type = list(string) - default = [] -} - -variable "pod_pinner_values" { - description = "List of YAML formatted string values for agent helm chart" - type = list(string) - default = [] -} - -variable "kvisor_values" { - description = "List of YAML formatted string values for kvisor helm chart" - type = list(string) - default = [] -} - -variable "self_managed" { - type = bool - default = false - description = "Whether CAST AI components' upgrades are managed by a customer; by default upgrades are managed CAST AI central system." +variable "node_configurations" { + description = "Configuration for node pools" + type = map(object({ + disk_cpu_ratio = number + subnets = list(string) + tags = map(string) + max_pods_per_node = number + disk_type = string + network_tags = list(string) + })) + default = {} } -variable "wait_for_cluster_ready" { - type = bool - description = "Wait for cluster to be ready before finishing the module execution, this option requires `castai_api_token` to be set" - default = false +variable "node_templates" { + description = "Templates for node configurations" + type = map(object({ + name = string + configuration_id = string + is_default = bool + is_enabled = bool + should_taint = bool + custom_labels = map(string) + custom_taints = list(object({ + key = string + value = string + effect = string + })) + constraints = object({ + on_demand = bool + spot = bool + use_spot_fallbacks = bool + enable_spot_diversity = bool + spot_diversity_price_increase_limit_percent = number + fallback_restore_rate_seconds = number + min_cpu = number + max_cpu = number + instance_families = object({ + exclude = list(string) + }) + compute_optimized_state = string + storage_optimized_state = string + }) + custom_instances_enabled = bool + })) + default = {} } diff --git a/versions.tf b/versions.tf index 0846f6c..e69de29 100644 --- a/versions.tf +++ b/versions.tf @@ -1,19 +0,0 @@ -terraform { - required_version = ">= 0.13" - - required_providers { - google = { - source = "hashicorp/google" - version = ">= 2.49" - } - castai = { - source = "castai/castai" - version = "~> 7.8" - } - helm = { - source = "hashicorp/helm" - version = ">= 2.0.0" - } - } -} -