From 62578dec40f4bbb05f145090226001ae42c5de2a Mon Sep 17 00:00:00 2001 From: Ish Shah Date: Wed, 27 Nov 2024 10:57:52 -0800 Subject: [PATCH 01/11] initial toggle --- main.tf | 1 + variables.tf | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/main.tf b/main.tf index 1fc131b..3090305 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" diff --git a/variables.tf b/variables.tf index 093b9e9..d9ce65e 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 = boolean + default = true + description = "Enable or disable applying and releasing Helm chart" +} \ No newline at end of file From b4dd4e7a7ae9a139db996fadcc72e0351efa4d88 Mon Sep 17 00:00:00 2001 From: Ish Shah Date: Wed, 27 Nov 2024 11:08:51 -0800 Subject: [PATCH 02/11] fix bool type --- variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variables.tf b/variables.tf index d9ce65e..cf00e03 100644 --- a/variables.tf +++ b/variables.tf @@ -28,7 +28,7 @@ variable "operator_chart_version" { } variable "enable_helm_release" { - type = boolean + type = bool default = true description = "Enable or disable applying and releasing Helm chart" } \ No newline at end of file From 0fe0abfccccec50ca7cbdbc3715e89a7428ee0d8 Mon Sep 17 00:00:00 2001 From: Ish Shah Date: Wed, 27 Nov 2024 11:10:34 -0800 Subject: [PATCH 03/11] add toggle to wandb helm chart and operator --- main.tf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.tf b/main.tf index 3090305..200fc86 100644 --- a/main.tf +++ b/main.tf @@ -22,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 From 2601e13055025a38600939815c97fd98876278de Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 27 Nov 2024 19:11:56 +0000 Subject: [PATCH 04/11] terraform-docs: automated action --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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 From b421b1ce3b4dec95fa594f57c8484ead59dcc198 Mon Sep 17 00:00:00 2001 From: Ish Shah Date: Wed, 27 Nov 2024 12:01:49 -0800 Subject: [PATCH 05/11] local vars to transition broken references --- main.tf | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 200fc86..b459785 100644 --- a/main.tf +++ b/main.tf @@ -43,5 +43,10 @@ resource "helm_release" "wandb" { type = "string" } - depends_on = [helm_release.operator] + depends_on = [helm_release_operator] +} + +locals { + helm_release_wandb = one(helm_release.wandb[*]) + helm_release_operator = one(helm_release.operator[*]) } \ No newline at end of file From c73979fbc3b585c4641a89c1f297d52172d733f3 Mon Sep 17 00:00:00 2001 From: Ish Shah Date: Mon, 2 Dec 2024 15:07:41 -0800 Subject: [PATCH 06/11] generate status messages for resource migration --- migrate-state.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 migrate-state.sh diff --git a/migrate-state.sh b/migrate-state.sh new file mode 100644 index 0000000..23fa8ee --- /dev/null +++ b/migrate-state.sh @@ -0,0 +1,41 @@ +#!/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..." + +# Migrate the operator release +migrate_resource "helm_release.operator" "helm_release.operator[0]" + +# Migrate the wandb release +migrate_resource "helm_release.wandb" "helm_release.wandb[0]" + +echo "Migration completed!" +echo "Please review the state and run 'terraform plan' to verify the migration" \ No newline at end of file From cfe3461a848cb9133d95241f87701a62be1d907d Mon Sep 17 00:00:00 2001 From: Ish Shah Date: Mon, 2 Dec 2024 15:11:08 -0800 Subject: [PATCH 07/11] migration permission --- migrate-state.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 migrate-state.sh diff --git a/migrate-state.sh b/migrate-state.sh old mode 100644 new mode 100755 From 0500a0e5f44584142f9eb6a40529ed701daff0b2 Mon Sep 17 00:00:00 2001 From: Ish Shah Date: Tue, 3 Dec 2024 14:12:07 -0800 Subject: [PATCH 08/11] update migration state to change any potential state containing helm_release in the name --- migrate-state.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/migrate-state.sh b/migrate-state.sh index 23fa8ee..bec97d8 100755 --- a/migrate-state.sh +++ b/migrate-state.sh @@ -31,11 +31,13 @@ terraform state pull > terraform.tfstate.backup.$(date +%Y%m%d-%H%M%S) # Migrate each resource echo "Migrating resources..." -# Migrate the operator release -migrate_resource "helm_release.operator" "helm_release.operator[0]" - -# Migrate the wandb release -migrate_resource "helm_release.wandb" "helm_release.wandb[0]" +# 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 From 4443c7e6ba90db17634151630d4d90ac72d89f39 Mon Sep 17 00:00:00 2001 From: Ish Shah Date: Tue, 3 Dec 2024 15:07:12 -0800 Subject: [PATCH 09/11] denote local --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index b459785..cdfc0df 100644 --- a/main.tf +++ b/main.tf @@ -43,7 +43,7 @@ resource "helm_release" "wandb" { type = "string" } - depends_on = [helm_release_operator] + depends_on = [local.helm_release_operator] } locals { From fd087f58370fac6d31f55ae67845fa05983029c8 Mon Sep 17 00:00:00 2001 From: jonathan meeks Date: Wed, 18 Dec 2024 16:29:17 -0600 Subject: [PATCH 10/11] fmt update --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index cdfc0df..afb6e8d 100644 --- a/main.tf +++ b/main.tf @@ -47,6 +47,6 @@ resource "helm_release" "wandb" { } locals { - helm_release_wandb = one(helm_release.wandb[*]) + helm_release_wandb = one(helm_release.wandb[*]) helm_release_operator = one(helm_release.operator[*]) } \ No newline at end of file From 83ad5b4a6de51af2ca8148b2677998566487d8ac Mon Sep 17 00:00:00 2001 From: Ish Shah Date: Wed, 18 Dec 2024 14:38:59 -0800 Subject: [PATCH 11/11] add moved tags --- main.tf | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index cdfc0df..6d963a2 100644 --- a/main.tf +++ b/main.tf @@ -47,6 +47,16 @@ resource "helm_release" "wandb" { } locals { - helm_release_wandb = one(helm_release.wandb[*]) + helm_release_wandb = one(helm_release.wandb[*]) helm_release_operator = one(helm_release.operator[*]) -} \ No newline at end of file +} + +moved { + from = helm_release.operator + to = helm_release.operator[0] +} + +moved { + from = helm_release.wandb + to = helm_release.wandb[0] +}