Skip to content

Commit

Permalink
ForceNew on route ID update (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
RayVGS committed Jul 18, 2023
1 parent 6571040 commit f1a9baa
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions provider/type_resource_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
"github.com/pkg/errors"
"gopkg.in/yaml.v3"
"reflect"
Expand Down Expand Up @@ -41,6 +42,7 @@ func resourceRoute() *schema.Resource {
Importer: &schema.ResourceImporter{
StateContext: resourceRouteImport,
},
CustomizeDiff: customdiff.ForceNewIfChange("inline_config", isIdUpdated),

Schema: map[string]*schema.Schema{
"environment": {
Expand Down Expand Up @@ -84,14 +86,23 @@ func suppressEquivalentRouteDiffs(k string, oldValue string, newValue string, d
oldMap = internal.Convert(oldMap)
_ = internal.SafeDeleteKey(oldMap, "attributes.created_at")
_ = internal.SafeDeleteKey(oldMap, "attributes.updated_at")
_ = internal.SafeDeleteKey(oldMap, "attributes.id")

newMap = internal.Convert(newMap)
_ = internal.SafeDeleteKey(newMap, "attributes.created_at")
_ = internal.SafeDeleteKey(newMap, "attributes.updated_at")
_ = internal.SafeDeleteKey(newMap, "attributes.id")

return reflect.DeepEqual(oldMap, newMap)
}

func isIdUpdated(ctx context.Context, oldValue, newValue, meta interface{}) bool {
oldRouteId, _ := vgstools.RouteIdFromYaml(oldValue.(string))
newRouteId, _ := vgstools.RouteIdFromYaml(newValue.(string))

return oldRouteId != newRouteId
}

func readRoute(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
vaultId := d.Get("vault").(string)

Expand Down

0 comments on commit f1a9baa

Please sign in to comment.