From 3a9a4d7e2d4d9f86f4e9b9b4b45287e2c1825abc Mon Sep 17 00:00:00 2001 From: Nathan Flurry Date: Wed, 17 Jan 2024 10:27:53 +0000 Subject: [PATCH] Fix Bolt Terraform has_applied for disabled plans (#351) ## Changes --- CHANGELOG.md | 1 + lib/bolt/core/src/dep/terraform/cli.rs | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3673978d..3282477fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **Infra** Redis Kubernetes error when using non-Kubernetes provider - **api-helper** Remove excess logging - `user_identity.identities` not getting purged on create & delete +- **Bolt** Error when applying Terraform when a plan is no longer required ## [23.2.0-rc.1] - 2023-12-01 diff --git a/lib/bolt/core/src/dep/terraform/cli.rs b/lib/bolt/core/src/dep/terraform/cli.rs index 64218e5af..ecbf7bc26 100644 --- a/lib/bolt/core/src/dep/terraform/cli.rs +++ b/lib/bolt/core/src/dep/terraform/cli.rs @@ -160,6 +160,14 @@ pub async fn state_list(ctx: &ProjectContext, plan_id: &str) -> Option bool { + // Check if Terraform plan is required for both: + // - Return false if the plan was disabled for any reason + // - Faster performance + let terraform_plans = crate::tasks::infra::all_terraform_plans(ctx).unwrap(); + if terraform_plans.iter().all(|x| x != plan_id) { + return false; + } + // Check if there is any output // // HACK: This will have a false negative for plans that have no output variables