Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

s3control: Improve policy diffs #28866

Merged
merged 2 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .changelog/28866.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
```release-note:bug
resource/aws_s3_access_point: Improve refresh to avoid unnecessary diffs in `policy`
```

```release-note:bug
resource/aws_s3control_bucket_policy: Improve refresh to avoid unnecessary diffs in `policy`
```

```release-note:bug
resource/aws_s3control_multi_region_access_point_policy: Improve refresh to avoid unnecessary diffs in `details` `policy`
```

```release-note:bug
resource/aws_s3control_object_lambda_access_point_policy: Improve refresh to avoid unnecessary diffs in `policy`
```

```release-note:bug
resource/aws_s3control_access_point_policy: Improve refresh to avoid unnecessary diffs in `policy`
```
14 changes: 6 additions & 8 deletions internal/service/s3control/access_point.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,12 @@ func resourceAccessPoint() *schema.Resource {
Computed: true,
},
"policy": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringIsJSON,
DiffSuppressFunc: verify.SuppressEquivalentPolicyDiffs,
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringIsJSON,
DiffSuppressFunc: verify.SuppressEquivalentPolicyDiffs,
DiffSuppressOnRefresh: true,
StateFunc: func(v interface{}) string {
json, _ := structure.NormalizeJsonString(v)
return json
Expand Down Expand Up @@ -203,7 +204,6 @@ func resourceAccessPointCreate(ctx context.Context, d *schema.ResourceData, meta

if v, ok := d.GetOk("policy"); ok && v.(string) != "" && v.(string) != "{}" {
policy, err := structure.NormalizeJsonString(v.(string))

if err != nil {
return diag.Errorf("policy (%s) is invalid JSON: %s", v.(string), err)
}
Expand Down Expand Up @@ -316,7 +316,6 @@ func resourceAccessPointRead(ctx context.Context, d *schema.ResourceData, meta i
}

policyToSet, err := verify.PolicyToSet(d.Get("policy").(string), policy)

if err != nil {
return diag.FromErr(err)
}
Expand Down Expand Up @@ -344,7 +343,6 @@ func resourceAccessPointUpdate(ctx context.Context, d *schema.ResourceData, meta
if d.HasChange("policy") {
if v, ok := d.GetOk("policy"); ok && v.(string) != "" && v.(string) != "{}" {
policy, err := structure.NormalizeJsonString(v.(string))

if err != nil {
return diag.Errorf("policy (%s) is invalid JSON: %s", v.(string), err)
}
Expand Down
12 changes: 5 additions & 7 deletions internal/service/s3control/access_point_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ func resourceAccessPointPolicy() *schema.Resource {
Computed: 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 @@ -73,7 +74,6 @@ func resourceAccessPointPolicyCreate(ctx context.Context, d *schema.ResourceData
}

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

if err != nil {
return diag.Errorf("policy (%s) is invalid JSON: %s", d.Get("policy").(string), err)
}
Expand Down Expand Up @@ -120,7 +120,6 @@ func resourceAccessPointPolicyRead(ctx context.Context, d *schema.ResourceData,

if policy != "" {
policyToSet, err := verify.PolicyToSet(d.Get("policy").(string), policy)

if err != nil {
return diag.FromErr(err)
}
Expand All @@ -143,7 +142,6 @@ func resourceAccessPointPolicyUpdate(ctx context.Context, d *schema.ResourceData
}

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

if err != nil {
return diag.Errorf("policy (%s) is invalid JSON: %s", d.Get("policy").(string), err)
}
Expand Down
12 changes: 5 additions & 7 deletions internal/service/s3control/bucket_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ func resourceBucketPolicy() *schema.Resource {
ValidateFunc: verify.ValidARN,
},
"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 @@ -60,7 +61,6 @@ func resourceBucketPolicyCreate(ctx context.Context, d *schema.ResourceData, met
bucket := d.Get("bucket").(string)

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

if err != nil {
return diag.Errorf("policy (%s) is invalid JSON: %s", d.Get("policy").(string), err)
}
Expand Down Expand Up @@ -110,7 +110,6 @@ func resourceBucketPolicyRead(ctx context.Context, d *schema.ResourceData, meta

if output.Policy != nil {
policyToSet, err := verify.PolicyToSet(d.Get("policy").(string), aws.StringValue(output.Policy))

if err != nil {
return diag.FromErr(err)
}
Expand All @@ -127,7 +126,6 @@ func resourceBucketPolicyUpdate(ctx context.Context, d *schema.ResourceData, met
conn := meta.(*conns.AWSClient).S3ControlConn()

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

if err != nil {
return diag.Errorf("policy (%s) is invalid JSON: %s", d.Get("policy").(string), err)
}
Expand Down
10 changes: 5 additions & 5 deletions internal/service/s3control/multi_region_access_point_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ func resourceMultiRegionAccessPointPolicy() *schema.Resource {
ValidateFunc: validateS3MultiRegionAccessPointName,
},
"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 Down Expand Up @@ -250,7 +251,6 @@ func expandPutMultiRegionAccessPointPolicyInput_(tfMap map[string]interface{}) *

if v, ok := tfMap["policy"].(string); ok {
policy, err := structure.NormalizeJsonString(v)

if err != nil {
policy = v
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ func resourceObjectLambdaAccessPointPolicyCreate(ctx context.Context, d *schema.
resourceID := ObjectLambdaAccessPointCreateResourceID(accountID, name)

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

if err != nil {
return diag.Errorf("policy (%s) is invalid JSON: %s", d.Get("policy").(string), err)
}
Expand Down Expand Up @@ -123,7 +122,6 @@ func resourceObjectLambdaAccessPointPolicyRead(ctx context.Context, d *schema.Re

if policy != "" {
policyToSet, err := verify.PolicyToSet(d.Get("policy").(string), policy)

if err != nil {
return diag.FromErr(err)
}
Expand All @@ -146,7 +144,6 @@ func resourceObjectLambdaAccessPointPolicyUpdate(ctx context.Context, d *schema.
}

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

if err != nil {
return diag.Errorf("policy (%s) is invalid JSON: %s", d.Get("policy").(string), err)
}
Expand Down