diff --git a/README.md b/README.md index 3bf8120..4daef8a 100644 --- a/README.md +++ b/README.md @@ -24,12 +24,11 @@ No modules. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| -| [operator\_image\_tag](#input\_operator\_image\_tag) | wandb/controller image tag | `string` | `"1.2.13"` | no | -| [operator\_namespace](#input\_operator\_namespace) | Kubernetes namespace where the operator CRD's will be deployed. By default, it uses the `default` namespace. | `string` | `"wandb"` | no | -| [operator\_version](#input\_operator\_version) | https://github.com/wandb/helm-charts/tree/main/charts/operator helm chart version | `string` | `"0.1.6"` | no | +| [controller\_image\_tag](#input\_controller\_image\_tag) | wandb/controller image tag | `string` | `"latest"` | no | +| [enable\_helm\_release](#input\_enable\_helm\_release) | Enable or disable applying and releasing Helm chart | `bool` | `true` | no | +| [operator\_chart\_namespace](#input\_operator\_chart\_namespace) | Kubernetes namespace where the operator CRD's will be deployed. By default, it uses the `default` namespace. | `string` | `"wandb"` | no | +| [operator\_chart\_version](#input\_operator\_chart\_version) | https://github.com/wandb/helm-charts/tree/main/charts/operator helm chart version | `string` | `"latest"` | no | | [spec](#input\_spec) | Specification used in the helm release for the instance. see https://github.com/wandb/cdk8s/blob/main/config-schema.json for details. | `any` | n/a | yes | -| [wandb\_cloud](#input\_wandb\_cloud) | The cloud provider to use. | `string` | n/a | yes | -| [wandb\_fqdn](#input\_wandb\_fqdn) | The FQDN to the W&B application | `string` | n/a | yes | | [wandb\_namespace](#input\_wandb\_namespace) | Kubernetes namespace where the operator will be deployed. By default, it uses the `default` namespace. | `string` | `"default"` | no | ## Outputs diff --git a/main.tf b/main.tf index 1fc131b..6d963a2 100644 --- a/main.tf +++ b/main.tf @@ -10,6 +10,7 @@ resource "helm_release" "operator" { cleanup_on_fail = false disable_webhooks = true verify = false + count = var.enable_helm_release ? 1 : 0 set { name = "image.tag" @@ -21,6 +22,8 @@ resource "helm_release" "wandb" { name = "wandb-cr" chart = "wandb-cr" + count = var.enable_helm_release ? 1 : 0 + force_update = true repository = path.module @@ -40,5 +43,20 @@ resource "helm_release" "wandb" { type = "string" } - depends_on = [helm_release.operator] -} \ No newline at end of file + depends_on = [local.helm_release_operator] +} + +locals { + helm_release_wandb = one(helm_release.wandb[*]) + helm_release_operator = one(helm_release.operator[*]) +} + +moved { + from = helm_release.operator + to = helm_release.operator[0] +} + +moved { + from = helm_release.wandb + to = helm_release.wandb[0] +} diff --git a/migrate-state.sh b/migrate-state.sh new file mode 100755 index 0000000..bec97d8 --- /dev/null +++ b/migrate-state.sh @@ -0,0 +1,43 @@ +#!/bin/bash +set -e + +echo "Starting Terraform state migration..." + +# Function to check if a resource exists in terraform state +check_resource() { + terraform state list | grep -q "$1" && return 0 || return 1 +} + +# Function to migrate a single resource +migrate_resource() { + local OLD_RESOURCE="$1" + local NEW_RESOURCE="$2" + + if check_resource "$OLD_RESOURCE"; then + echo "Migrating ${OLD_RESOURCE} to ${NEW_RESOURCE}" + terraform state mv -lock=false "$OLD_RESOURCE" "$NEW_RESOURCE" || { + echo "Failed to migrate ${OLD_RESOURCE}" + return 1 + } + else + echo "Resource ${OLD_RESOURCE} not found in state, skipping..." + fi +} + +# Backup the current state +echo "Creating state backup..." +terraform state pull > terraform.tfstate.backup.$(date +%Y%m%d-%H%M%S) + +# Migrate each resource +echo "Migrating resources..." + +# Find all helm_release resources and migrate them +terraform state list | grep "helm_release" | while read -r resource; do + # Skip if resource already has count index + if [[ "$resource" != *"[0]"* ]]; then + migrate_resource "$resource" "${resource}[0]" + fi +done + +echo "Migration completed!" +echo "Please review the state and run 'terraform plan' to verify the migration" \ No newline at end of file diff --git a/variables.tf b/variables.tf index 093b9e9..cf00e03 100644 --- a/variables.tf +++ b/variables.tf @@ -26,3 +26,9 @@ variable "operator_chart_version" { default = "latest" description = "https://github.com/wandb/helm-charts/tree/main/charts/operator helm chart version" } + +variable "enable_helm_release" { + type = bool + default = true + description = "Enable or disable applying and releasing Helm chart" +} \ No newline at end of file