terraform-provider-sumologic icon indicating copy to clipboard operation
terraform-provider-sumologic copied to clipboard

Fix use_versioned_api default value discrepancy

Open vsinghal13 opened this issue 1 year ago • 9 comments

The current TF provider version has a bug where any new AWS sources (except S3 Source) when created, are using use_versioned_api as false despite having a default value of true.

This PR fixes that by:

  1. restrict setting the useVersionedApi only when content_type is AwsS3Bucket else always set it to true internally via code.
  2. modifying the existing custom diffSuppressFunc to not suppress the diff when the content_type != AwsS3Bucket and the current value of use_versioned_api is set to false so that post the TF provider upgrade, all the sources that are using incorrect values of the use_versioned_api parameter can be updated and set to true.

Testing Performed:

  • [X] Verified creating S3 sources with use_versioned_api as true, false, and null(missing field).
  • [X] Verified creating other S3 sources(other than AwsS3Bucket) with use_versioned_api as true, false, and null(missing field) and sources are always created with value true as expected.
  • [X] Verified that post provider upgrade, the sources with incorrect values will be fixed.

vsinghal13 avatar Apr 29 '24 21:04 vsinghal13

what caused the bug exactly? not sure if I'm getting that information from the PR description

maimaisie avatar Apr 29 '24 22:04 maimaisie

what caused the bug exactly? not sure if I'm getting that information from the PR description

not sure exactly but seems related to tf not being able to identify correctly when the parameter is not present and setting it to false.

vsinghal13 avatar Apr 30 '24 00:04 vsinghal13

let's spend some more time on the real root cause before putting in bandage fixes

maimaisie avatar Apr 30 '24 17:04 maimaisie

@dagould found an old issue that shows that the default value is ignored when used with DiffSuppressFunc https://github.com/hashicorp/terraform-plugin-sdk/issues/70

vsinghal13 avatar May 02 '24 17:05 vsinghal13

so what's the proper fix?

maimaisie avatar May 02 '24 17:05 maimaisie

From standup discussion it sounds like there is no proper fix since this is still an issue present in TF today, and we can only work around it. It would be nice if that was made more clear in your previous comment :)

maimaisie avatar May 02 '24 18:05 maimaisie

I think we should update this doc if we are now restricting the value from being set to false for content types other than AwsS3Bucket https://registry.terraform.io/providers/SumoLogic/sumologic/latest/docs/resources/s3_source#use_versioned_api But on the other hand, we don't have this restriction on the backend, so I'm wondering if it's really a good idea to restrict it only in TF

I don't think we should update the docs as its only mentioned in s3 source documentation and not others and for s3 source we have no change in behavior.

vsinghal13 avatar May 02 '24 19:05 vsinghal13

we also don't mention it for other aws sources in sumologic documentation, but we don't block users from creating the source with this field in the backend if user sets it in the API

maimaisie avatar May 02 '24 19:05 maimaisie

Probably add another test to see if there is any unexpected diff after reapplying the plan. I feel like the DiffSuppressFunc is buggy when I am doing testing for azure log source.

yyyttthan99 avatar May 03 '24 19:05 yyyttthan99

Updated the description with respect to the latest commit.

vsinghal13 avatar May 16 '24 20:05 vsinghal13