From 4c9b895ae3176d202e891dd363c8080cf3da451a Mon Sep 17 00:00:00 2001 From: Ramya Bangera Date: Mon, 12 Feb 2024 16:33:40 +0530 Subject: [PATCH] Do not fail the planning phase if the custom template name specified in the custom policy assignment is not found Initially this check was added as the custom template creation via TMC TF provider was not supported. Now since the provider supports creation of the custom template removing this check, to let user create the custom template and assign it to custom policy on the fly. Signed-off-by: Ramya Bangera --- .../policy/kind/custom/recipe/tmc_custom_schema.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/resources/policy/kind/custom/recipe/tmc_custom_schema.go b/internal/resources/policy/kind/custom/recipe/tmc_custom_schema.go index 5f2462186..4a4acdf7b 100644 --- a/internal/resources/policy/kind/custom/recipe/tmc_custom_schema.go +++ b/internal/resources/policy/kind/custom/recipe/tmc_custom_schema.go @@ -20,6 +20,7 @@ import ( policyrecipecustomcommonmodel "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/policy/recipe/custom/common" recipemodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/recipe" "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/policy/kind/common" + clienterrors "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/errors" ) var TMCCustomSchema = &schema.Schema{ @@ -117,7 +118,11 @@ func ValidateCustomRecipe(config authctx.TanzuContext, customRecipe map[string]i recipeData, err := config.TMCConnection.RecipeResourceService.RecipeResourceServiceGet(recipeModel) if err != nil { - errMessages = append(errMessages, err.Error()) + // NOTE: If error is 404 not found then do not fail the planning. This fix ensures that if user tries to create the new custom template + // and assign the same template to the custom policy in a single terraform apply operation will be able to proceed, instead of failing in the planning phase. + if !clienterrors.IsNotFoundError(err) { + errMessages = append(errMessages, err.Error()) + } } else { errs := ValidateRecipeParameters(recipeData.Recipe.Spec.InputSchema, customRecipe[ParametersKey].(string))