diff --git a/castai/resource_eks_cluster_id.go b/castai/resource_eks_cluster_id.go index c7324990..fb166697 100644 --- a/castai/resource_eks_cluster_id.go +++ b/castai/resource_eks_cluster_id.go @@ -16,6 +16,7 @@ func resourceEKSClusterID() *schema.Resource { CreateContext: resourceEKSClusterIDCreate, ReadContext: resourceEKSClusterIDRead, DeleteContext: resourceEKSClusterIDDelete, + Description: "Retrieve CAST AI clusterid", Schema: map[string]*schema.Schema{ "account_id": { Type: schema.TypeString, diff --git a/castai/resource_eks_cluster_userarn.go b/castai/resource_eks_cluster_userarn.go index 9f6e3e00..c25bbb93 100644 --- a/castai/resource_eks_cluster_userarn.go +++ b/castai/resource_eks_cluster_userarn.go @@ -17,6 +17,7 @@ func resourceEKSClusterUserARN() *schema.Resource { ReadContext: resourceEKSUserARNRead, CreateContext: resourceEKSUserARNCreate, DeleteContext: resourceEKSUserARNDelete, + Description: "Retrieve EKS Cluster user arn", Schema: map[string]*schema.Schema{ EKSClusterUserARNFieldClusterID: { Type: schema.TypeString, diff --git a/castai/resource_eviction_config.go b/castai/resource_eviction_config.go index ad716d87..140e271f 100644 --- a/castai/resource_eviction_config.go +++ b/castai/resource_eviction_config.go @@ -126,14 +126,17 @@ func resourceEvictionConfig() *schema.Resource { FieldEvictionOptionDisabled: { Type: schema.TypeBool, Optional: true, + Description: "Marking pods as removalDisabled", }, FieldEvictionOptionAggressive: { Type: schema.TypeBool, + Description: "Apply Aggressive mode to Evictor", Optional: true, }, FieldEvictionOptionDisposable: { Type: schema.TypeBool, Optional: true, + Description: "Marking node as disposable", }, }, }, diff --git a/castai/resource_node_configuration_gke_test.go b/castai/resource_node_configuration_gke_test.go index 0cb9837e..581761bc 100644 --- a/castai/resource_node_configuration_gke_test.go +++ b/castai/resource_node_configuration_gke_test.go @@ -9,6 +9,12 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) +const ( + // acceptanceTestClusterSubnetworkName points to the subnet that the acceptance test cluster uses. + // Actual value (should) be managed by our IaC repository and could be shared with other clusters as well. + acceptanceTestClusterSubnetworkName = "ext-prov-e2e-shared-ip-range-nodes" +) + func TestAccResourceNodeConfiguration_gke(t *testing.T) { rName := fmt.Sprintf("%v-node-cfg-%v", ResourcePrefix, acctest.RandString(8)) resourceName := "castai_node_configuration.test" @@ -127,6 +133,7 @@ resource "castai_gke_cluster" "test" { } func testAccGCPConfig(rName, clusterName, projectID string) string { + return fmt.Sprintf(` locals { @@ -134,7 +141,7 @@ locals { cluster_name = %[1]q service_account_email = "${local.service_account_id}@$%[2]s.iam.gserviceaccount.com" custom_role_id = "castai.tfAcc.${substr(sha1(local.service_account_id),0,8)}.tf" - subnet_id = "projects/%[2]s/regions/us-central1/subnetworks/%[1]s-ip-range-nodes" + subnet_id = "projects/%[2]s/regions/us-central1/subnetworks/%[4]s" } resource "google_service_account" "castai_service_account" { @@ -177,5 +184,5 @@ resource "google_service_account_key" "castai_key" { public_key_type = "TYPE_X509_PEM_FILE" } -`, clusterName, projectID, rName) +`, clusterName, projectID, rName, acceptanceTestClusterSubnetworkName) } diff --git a/castai/resource_node_template.go b/castai/resource_node_template.go index dcc97710..498f709a 100644 --- a/castai/resource_node_template.go +++ b/castai/resource_node_template.go @@ -984,9 +984,9 @@ func updateDefaultNodeTemplate(ctx context.Context, d *schema.ResourceData, meta for _, d := range diagnostics { if d.Severity == diag.Error { if strings.Contains(d.Summary, "node template not found") { - return retry.RetryableError(fmt.Errorf(d.Summary)) + return retry.RetryableError(fmt.Errorf("%s", d.Summary)) } - return retry.NonRetryableError(fmt.Errorf(d.Summary)) + return retry.NonRetryableError(fmt.Errorf("%s", d.Summary)) } } return nil diff --git a/castai/sdk/api.gen.go b/castai/sdk/api.gen.go index 6cd484e0..337d96df 100644 --- a/castai/sdk/api.gen.go +++ b/castai/sdk/api.gen.go @@ -3301,6 +3301,7 @@ type WorkloadoptimizationV1RecommendationPolicies struct { // MANAGED - workload watched (metrics collected), CAST AI may perform actions on the workload. ManagementOption WorkloadoptimizationV1ManagementOption `json:"managementOption"` Memory WorkloadoptimizationV1ResourcePolicies `json:"memory"` + Startup *WorkloadoptimizationV1StartupSettings `json:"startup,omitempty"` } // WorkloadoptimizationV1ResourceConfig defines model for workloadoptimization.v1.ResourceConfig. @@ -3390,6 +3391,13 @@ type WorkloadoptimizationV1Resources struct { Requests *WorkloadoptimizationV1ResourceQuantity `json:"requests,omitempty"` } +// WorkloadoptimizationV1StartupSettings defines model for workloadoptimization.v1.StartupSettings. +type WorkloadoptimizationV1StartupSettings struct { + // Startup period defines the duration of increased resource usage during startup. + // Recommendations will be adjusted to ignore the spikes during regular execution. If not set workload will get usual recommendations. + PeriodSeconds *int32 `json:"periodSeconds"` +} + // WorkloadoptimizationV1SurgeContainer defines model for workloadoptimization.v1.SurgeContainer. type WorkloadoptimizationV1SurgeContainer struct { Name string `json:"name"` diff --git a/docs/data-sources/eks_settings.md b/docs/data-sources/eks_settings.md index 4ae1811b..9eb96330 100644 --- a/docs/data-sources/eks_settings.md +++ b/docs/data-sources/eks_settings.md @@ -10,7 +10,16 @@ description: |- Retrieve IAM policy, IAM User Policy and instance profile policies for the specified cluster - +## Example Usage + +```terraform +data "castai_eks_settings" "current" { + account_id = data.aws_caller_identity.current.account_id + region = var.cluster_region + cluster = var.cluster_name + vpc = var.vpc +} +``` ## Schema diff --git a/docs/data-sources/gke_user_policies.md b/docs/data-sources/gke_user_policies.md index 8bb52b5c..a403b155 100644 --- a/docs/data-sources/gke_user_policies.md +++ b/docs/data-sources/gke_user_policies.md @@ -10,7 +10,11 @@ description: |- +## Example Usage +```terraform +data "castai_gke_user_policies" "gke" {} +``` ## Schema diff --git a/docs/data-sources/organization.md b/docs/data-sources/organization.md index ecd95a25..a56ea9f1 100644 --- a/docs/data-sources/organization.md +++ b/docs/data-sources/organization.md @@ -10,7 +10,13 @@ description: |- Retrieve organization ID +## Example Usage +```terraform +data "castai_organization" "dev" { + name = var.castai_dev_organization_name +} +``` ## Schema diff --git a/docs/resources/autoscaler.md b/docs/resources/autoscaler.md index 2dcf9401..68118ca0 100644 --- a/docs/resources/autoscaler.md +++ b/docs/resources/autoscaler.md @@ -10,7 +10,52 @@ description: |- CAST AI autoscaler resource to manage autoscaler settings - +## Example Usage + +```terraform +resource "castai_autoscaler" "castai_autoscaler_policy" { + cluster_id = castai_eks_cluster.test.id + + autoscaler_settings { + enabled = true + is_scoped_mode = false + node_templates_partial_matching_enabled = false + + unschedulable_pods { + enabled = true + } + + cluster_limits { + enabled = true + + cpu { + min_cores = 1 + max_cores = 10 + } + } + + node_downscaler { + enabled = true + + empty_nodes { + enabled = true + delay_seconds = 90 + } + + evictor { + enabled = true + dry_run = false + aggressive_mode = false + scoped_mode = false + cycle_interval = "300s" + node_grace_period_minutes = 10 + pod_eviction_failure_back_off_interval = "30s" + ignore_pod_disruption_budgets = false + } + } + } +} +``` ## Schema diff --git a/docs/resources/eks_clusterid.md b/docs/resources/eks_clusterid.md index cecc6de7..60528ee1 100644 --- a/docs/resources/eks_clusterid.md +++ b/docs/resources/eks_clusterid.md @@ -3,14 +3,22 @@ page_title: "castai_eks_clusterid Resource - terraform-provider-castai" subcategory: "" description: |- - + Retrieve CAST AI clusterid --- # castai_eks_clusterid (Resource) +Retrieve CAST AI clusterid +## Example Usage - +```terraform +resource "castai_eks_clusterid" "cluster_id" { + account_id = data.aws_caller_identity.current.account_id + region = var.cluster_region + cluster_name = var.cluster_name +} +``` ## Schema diff --git a/docs/resources/eks_user_arn.md b/docs/resources/eks_user_arn.md index 5e353d27..20fab1a6 100644 --- a/docs/resources/eks_user_arn.md +++ b/docs/resources/eks_user_arn.md @@ -3,14 +3,20 @@ page_title: "castai_eks_user_arn Resource - terraform-provider-castai" subcategory: "" description: |- - + Retrieve EKS Cluster user arn --- # castai_eks_user_arn (Resource) +Retrieve EKS Cluster user arn +## Example Usage - +```terraform +resource "castai_eks_user_arn" "castai_user_arn" { + cluster_id = castai_eks_clusterid.cluster_id.id +} +``` ## Schema diff --git a/docs/resources/evictor_advanced_config.md b/docs/resources/evictor_advanced_config.md index 1a0fed02..d8fff7a2 100644 --- a/docs/resources/evictor_advanced_config.md +++ b/docs/resources/evictor_advanced_config.md @@ -10,7 +10,35 @@ description: |- CAST AI eviction config resource to manage evictor properties - +## Example Usage + +```terraform +resource "evictor_advanced_config" "config" { + evictor_advanced_config = [ + { + pod_selector = { + kind = "Job" + namespace = "castai" + match_labels = { + "app.kubernetes.io/name" = "castai-node" + } + }, + aggressive = true + }, + { + node_selector = { + match_expressions = [ + { + key = "pod.cast.ai/flag" + operator = "Exists" + } + ] + }, + disposable = true + } + ] +} +``` ## Schema @@ -33,11 +61,11 @@ CAST AI eviction config resource to manage evictor properties Optional: -- `aggressive` (Boolean) -- `disposable` (Boolean) +- `aggressive` (Boolean) Apply Aggressive mode to Evictor +- `disposable` (Boolean) Marking node as disposable - `node_selector` (Block List) node selector (see [below for nested schema](#nestedblock--evictor_advanced_config--node_selector)) - `pod_selector` (Block List) pod selector (see [below for nested schema](#nestedblock--evictor_advanced_config--pod_selector)) -- `removal_disabled` (Boolean) +- `removal_disabled` (Boolean) Marking pods as removalDisabled ### Nested Schema for `evictor_advanced_config.node_selector` diff --git a/docs/resources/node_template.md b/docs/resources/node_template.md index 49c35e13..925132cb 100644 --- a/docs/resources/node_template.md +++ b/docs/resources/node_template.md @@ -10,7 +10,62 @@ description: |- CAST AI node template resource to manage node templates - +## Example Usage + +```terraform +resource "castai_node_template" "default" { + cluster_id = castai_eks_cluster.test.id + + name = "my-node-template" + is_default = true + is_enabled = true + configuration_id = castai_node_configuration.default.id + should_taint = true + + custom_labels = { + env = "production" + } + + custom_taints { + key = "dedicated" + value = "backend" + effect = "NoSchedule" + } + + constraints { + on_demand = true + spot = false + use_spot_fallbacks = true + fallback_restore_rate_seconds = 300 + enable_spot_diversity = true + spot_diversity_price_increase_limit_percent = 20 + spot_interruption_predictions_enabled = true + spot_interruption_predictions_type = "aws-rebalance-recommendations" + compute_optimized_state = "disabled" + storage_optimized_state = "disabled" + is_gpu_only = false + min_cpu = 2 + max_cpu = 8 + min_memory = 4096 + max_memory = 16384 + architectures = ["amd64"] + azs = ["us-east-2a", "us-east-2b"] + burstable_instances = "disabled" + customer_specific = "enabled" + + instance_families { + include = ["c5"] + } + + custom_priority { + instance_families = ["c5"] + spot = false + on_demand = true + } + } + +} +``` ## Schema diff --git a/docs/resources/organization_members.md b/docs/resources/organization_members.md index 98e43a1f..45ae274e 100644 --- a/docs/resources/organization_members.md +++ b/docs/resources/organization_members.md @@ -10,7 +10,27 @@ description: |- CAST AI organization members resource to manage organization members +## Example Usage +```terraform +data "castai_organization" "dev" { + name = var.castai_dev_organization_name +} + +resource "castai_organization_members" "dev" { + organization_id = data.castai_organization.dev.id + + owners = [ + "owner@test.ai", + ] + + members = [ + "member@test.ai", + ] + + viewers = [] +} +``` ## Schema diff --git a/docs/resources/workload_scaling_policy.md b/docs/resources/workload_scaling_policy.md index 41631e3b..d4c2fb0e 100644 --- a/docs/resources/workload_scaling_policy.md +++ b/docs/resources/workload_scaling_policy.md @@ -17,7 +17,7 @@ simultaneously or create custom policies with different settings and apply them ```terraform castai_workload_scaling_policy "services" { name = "services" - cluster_id = castai_gke_cluster.dev.id + cluster_id = castai_eks_cluster.dev.id apply_type = "IMMEDIATE" management_option = "MANAGED" cpu { diff --git a/examples/data-sources/castai_eks_settings/data-source.tf b/examples/data-sources/castai_eks_settings/data-source.tf new file mode 100644 index 00000000..6b0ea282 --- /dev/null +++ b/examples/data-sources/castai_eks_settings/data-source.tf @@ -0,0 +1,6 @@ +data "castai_eks_settings" "current" { + account_id = data.aws_caller_identity.current.account_id + region = var.cluster_region + cluster = var.cluster_name + vpc = var.vpc +} diff --git a/examples/data-sources/castai_gke_user_policies/data-source.tf b/examples/data-sources/castai_gke_user_policies/data-source.tf new file mode 100644 index 00000000..ba342eba --- /dev/null +++ b/examples/data-sources/castai_gke_user_policies/data-source.tf @@ -0,0 +1 @@ +data "castai_gke_user_policies" "gke" {} diff --git a/examples/data-sources/castai_organization/data-source.tf b/examples/data-sources/castai_organization/data-source.tf new file mode 100644 index 00000000..2b822b79 --- /dev/null +++ b/examples/data-sources/castai_organization/data-source.tf @@ -0,0 +1,3 @@ +data "castai_organization" "dev" { + name = var.castai_dev_organization_name +} diff --git a/examples/resources/castai_autoscaler/resource.tf b/examples/resources/castai_autoscaler/resource.tf new file mode 100644 index 00000000..666e4933 --- /dev/null +++ b/examples/resources/castai_autoscaler/resource.tf @@ -0,0 +1,42 @@ +resource "castai_autoscaler" "castai_autoscaler_policy" { + cluster_id = castai_eks_cluster.test.id + + autoscaler_settings { + enabled = true + is_scoped_mode = false + node_templates_partial_matching_enabled = false + + unschedulable_pods { + enabled = true + } + + cluster_limits { + enabled = true + + cpu { + min_cores = 1 + max_cores = 10 + } + } + + node_downscaler { + enabled = true + + empty_nodes { + enabled = true + delay_seconds = 90 + } + + evictor { + enabled = true + dry_run = false + aggressive_mode = false + scoped_mode = false + cycle_interval = "300s" + node_grace_period_minutes = 10 + pod_eviction_failure_back_off_interval = "30s" + ignore_pod_disruption_budgets = false + } + } + } +} diff --git a/examples/resources/castai_eks_clusterid/resource.tf b/examples/resources/castai_eks_clusterid/resource.tf new file mode 100644 index 00000000..a51979d2 --- /dev/null +++ b/examples/resources/castai_eks_clusterid/resource.tf @@ -0,0 +1,5 @@ +resource "castai_eks_clusterid" "cluster_id" { + account_id = data.aws_caller_identity.current.account_id + region = var.cluster_region + cluster_name = var.cluster_name +} diff --git a/examples/resources/castai_eks_user_arn/resource.tf b/examples/resources/castai_eks_user_arn/resource.tf new file mode 100644 index 00000000..f0a8a958 --- /dev/null +++ b/examples/resources/castai_eks_user_arn/resource.tf @@ -0,0 +1,3 @@ +resource "castai_eks_user_arn" "castai_user_arn" { + cluster_id = castai_eks_clusterid.cluster_id.id +} diff --git a/examples/resources/castai_evictor_advanced_config/resource.tf b/examples/resources/castai_evictor_advanced_config/resource.tf new file mode 100644 index 00000000..0b264d32 --- /dev/null +++ b/examples/resources/castai_evictor_advanced_config/resource.tf @@ -0,0 +1,25 @@ +resource "evictor_advanced_config" "config" { + evictor_advanced_config = [ + { + pod_selector = { + kind = "Job" + namespace = "castai" + match_labels = { + "app.kubernetes.io/name" = "castai-node" + } + }, + aggressive = true + }, + { + node_selector = { + match_expressions = [ + { + key = "pod.cast.ai/flag" + operator = "Exists" + } + ] + }, + disposable = true + } + ] +} diff --git a/examples/resources/castai_node_template/resource.tf b/examples/resources/castai_node_template/resource.tf new file mode 100644 index 00000000..c60c2c70 --- /dev/null +++ b/examples/resources/castai_node_template/resource.tf @@ -0,0 +1,52 @@ +resource "castai_node_template" "default" { + cluster_id = castai_eks_cluster.test.id + + name = "my-node-template" + is_default = true + is_enabled = true + configuration_id = castai_node_configuration.default.id + should_taint = true + + custom_labels = { + env = "production" + } + + custom_taints { + key = "dedicated" + value = "backend" + effect = "NoSchedule" + } + + constraints { + on_demand = true + spot = false + use_spot_fallbacks = true + fallback_restore_rate_seconds = 300 + enable_spot_diversity = true + spot_diversity_price_increase_limit_percent = 20 + spot_interruption_predictions_enabled = true + spot_interruption_predictions_type = "aws-rebalance-recommendations" + compute_optimized_state = "disabled" + storage_optimized_state = "disabled" + is_gpu_only = false + min_cpu = 2 + max_cpu = 8 + min_memory = 4096 + max_memory = 16384 + architectures = ["amd64"] + azs = ["us-east-2a", "us-east-2b"] + burstable_instances = "disabled" + customer_specific = "enabled" + + instance_families { + include = ["c5"] + } + + custom_priority { + instance_families = ["c5"] + spot = false + on_demand = true + } + } + +} diff --git a/examples/resources/castai_organization_members/resource.tf b/examples/resources/castai_organization_members/resource.tf new file mode 100644 index 00000000..6bc138b8 --- /dev/null +++ b/examples/resources/castai_organization_members/resource.tf @@ -0,0 +1,19 @@ +data "castai_organization" "dev" { + name = var.castai_dev_organization_name +} + +resource "castai_organization_members" "dev" { + organization_id = data.castai_organization.dev.id + + owners = [ + "owner@test.ai", + ] + + members = [ + "member@test.ai", + ] + + viewers = [] +} + + diff --git a/examples/resources/castai_workload_scaling_policy/resource.tf b/examples/resources/castai_workload_scaling_policy/resource.tf index 6f5b1afb..e90e4ee5 100644 --- a/examples/resources/castai_workload_scaling_policy/resource.tf +++ b/examples/resources/castai_workload_scaling_policy/resource.tf @@ -1,6 +1,6 @@ castai_workload_scaling_policy "services" { name = "services" - cluster_id = castai_gke_cluster.dev.id + cluster_id = castai_eks_cluster.dev.id apply_type = "IMMEDIATE" management_option = "MANAGED" cpu { @@ -14,4 +14,4 @@ castai_workload_scaling_policy "services" { overhead = 0.35 apply_threshold = 0.2 } -} \ No newline at end of file +}