Skip to content

Commit

Permalink
Merge pull request #28838 from hashicorp/b-iot-policy-diffs
Browse files Browse the repository at this point in the history
iot/policy: Improve diffs of policy
  • Loading branch information
YakDriver authored Jan 11, 2023
2 parents 0250514 + 6a4d7cd commit 8941657
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .changelog/28838.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_iot_policy: Improve refresh to avoid unnecessary diffs in `policy`
```
12 changes: 5 additions & 7 deletions internal/service/iot/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ func ResourcePolicy() *schema.Resource {
ForceNew: true,
},
"policy": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringIsJSON,
DiffSuppressFunc: verify.SuppressEquivalentPolicyDiffs,
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringIsJSON,
DiffSuppressFunc: verify.SuppressEquivalentPolicyDiffs,
DiffSuppressOnRefresh: true,
StateFunc: func(v interface{}) string {
json, _ := structure.NormalizeJsonString(v)
return json
Expand All @@ -56,7 +57,6 @@ func resourcePolicyCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*conns.AWSClient).IoTConn()

policy, err := structure.NormalizeJsonString(d.Get("policy").(string))

if err != nil {
return fmt.Errorf("policy (%s) is invalid JSON: %w", policy, err)
}
Expand Down Expand Up @@ -97,7 +97,6 @@ func resourcePolicyRead(d *schema.ResourceData, meta interface{}) error {
d.Set("name", out.PolicyName)

policyToSet, err := verify.PolicyToSet(d.Get("policy").(string), aws.StringValue(out.PolicyDocument))

if err != nil {
return err
}
Expand All @@ -112,7 +111,6 @@ func resourcePolicyUpdate(d *schema.ResourceData, meta interface{}) error {

if d.HasChange("policy") {
policy, err := structure.NormalizeJsonString(d.Get("policy").(string))

if err != nil {
return fmt.Errorf("policy (%s) is invalid JSON: %w", policy, err)
}
Expand Down

0 comments on commit 8941657

Please sign in to comment.