Skip to content

Commit

Permalink
Merge pull request #394 from hashicorp/forcenew-sensitive
Browse files Browse the repository at this point in the history
Forcenew sensitive
  • Loading branch information
uturunku1 committed Dec 7, 2021
2 parents dda1634 + 7dfc675 commit 7917a53
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions tfe/resource_tfe_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"

tfe "github.com/hashicorp/go-tfe"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
Expand Down Expand Up @@ -85,9 +84,25 @@ func resourceTFEVariable() *schema.Resource {
},
},

CustomizeDiff: customdiff.ForceNewIf("key", func(_ context.Context, d *schema.ResourceDiff, m interface{}) bool {
return d.Get("sensitive").(bool)
}),
CustomizeDiff: forceRecreateResourceIf(),
}
}

func forceRecreateResourceIf() schema.CustomizeDiffFunc {
/*
Destroy and add a new resource when:
1. the parameter key changed and the param sensitive is set to true
2. the parameter sensitive changed from true to false
*/
return func(ctx context.Context, d *schema.ResourceDiff, meta interface{}) error {
wasSensitiveVar := d.HasChange("sensitive") && !(d.Get("sensitive").(bool))

if wasSensitiveVar {
return d.ForceNew("sensitive")
} else if d.HasChange("key") && d.Get("sensitive").(bool) {
return d.ForceNew("key")
}
return nil
}
}

Expand Down

0 comments on commit 7917a53

Please sign in to comment.