Skip to content

Conversation

@alexGNX
Copy link
Contributor

@alexGNX alexGNX commented Nov 20, 2025

Description

The fix is about detecting changes made to an okms_secret resource outside of terraform and reconcile the states.

Fixes #1147 (issue)

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

export TF_ACC=1
export OVH_ENDPOINT=ovh-eu
export OVH_APPLICATION_KEY=...
export OVH_APPLICATION_SECRET=...
export OVH_CONSUMER_KEY=...
export OVH_OKMS=...

# data source tests
go test -timeout 30s -run ^TestAccOkmsSecretDataSource_latestAndVersions$ github.com/ovh/terraform-provider-ovh/v2/ovh
go test -timeout 60s -run ^TestAccOkmsSecretDataSource_latestAndVersions$ github.com/ovh/terraform-provider-ovh/v2/ovh

# resource tests
go test -timeout 90s -run ^TestAccOkmsSecretResource_basicLifecycle$ github.com/ovh/terraform-provider-ovh/v2/ovh
go test -timeout 5m -run TestAccOkmsSecretResource_basicLifecycle github.com/ovh/terraform-provider-ovh/v2/ovh
go test -timeout 5m -run TestAccOkmsSecretResource_casMismatch github.com/ovh/terraform-provider-ovh/v2/ovh
go test -timeout 5m -run TestAccOkmsSecretResource_pathRecreateAndMetadata github.com/ovh/terraform-provider-ovh/v2/ovh

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings or issues
  • I have added acceptance tests that prove my fix is effective or that my feature works
  • New and existing acceptance tests pass locally with my changes
  • I ran successfully go mod vendor if I added or modify go.mod file

@alexGNX alexGNX requested a review from a team as a code owner November 20, 2025 10:40
@alexGNX alexGNX force-pushed the dev/agagneux/okms_secret_fix branch from ac54557 to d1f97a1 Compare November 20, 2025 10:42
@alexGNX alexGNX force-pushed the dev/agagneux/okms_secret_fix branch from d1f97a1 to f1ff375 Compare November 20, 2025 10:43
Comment on lines +294 to +321
// semanticJSONEqual compares two JSON strings for semantic equality,
// ignoring formatting differences like whitespace and key ordering.
func semanticJSONEqual(a, b string) bool {
var objA, objB interface{}

// Try to parse both as JSON
if err := json.Unmarshal([]byte(a), &objA); err != nil {
// Not valid JSON, fall back to string comparison
return a == b
}
if err := json.Unmarshal([]byte(b), &objB); err != nil {
// Not valid JSON, fall back to string comparison
return a == b
}

// Re-marshal both in canonical form and compare
normalizedA, err := json.Marshal(objA)
if err != nil {
return a == b
}
normalizedB, err := json.Marshal(objB)
if err != nil {
return a == b
}

return string(normalizedA) == string(normalizedB)
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could reduce the amount of []byte <--> string conversions here, for example:

func semanticJSONEqual(a, b []byte) bool {
    var objA, objB any

    // Try to parse both as JSON
    if err := json.Unmarshal(a, &objA); err != nil {
        // Not valid JSON, fall back to []byte comparison
        return slices.Equal(a, b)
    }
    if err := json.Unmarshal(b, &objB); err != nil {
        return false
    }

    return reflect.DeepEqual(objA, objB)
} 

you would only have to convert input parameters as []byte to call this func

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] No data change recognition in ovh_okms_secret

2 participants