Skip to content

Always use /setup-tests endpoint for plan-only attributes#509

Draft
fivetran-jovanmanojlovic wants to merge 10 commits intomainfrom
rd-1080143-fix-plan-only-attributes-update-logic
Draft

Always use /setup-tests endpoint for plan-only attributes#509
fivetran-jovanmanojlovic wants to merge 10 commits intomainfrom
rd-1080143-fix-plan-only-attributes-update-logic

Conversation

@fivetran-jovanmanojlovic
Copy link
Contributor

@fivetran-jovanmanojlovic fivetran-jovanmanojlovic commented Jan 20, 2026

Why Terraform Provider Didn't Call the Setup Tests Endpoint

The Terraform provider has two different paths for updating connectors:

Path 1 - PATCH endpoint: Used when "real" attributes change (like config, sync_frequency, paused, etc.)
Path 2 - /setup-tests endpoint: Used when ONLY plan-only attributes change (run_setup_tests, trust_certificates, trust_fingerprints)

The provider checks: "Are there any real attribute changes?"

  • If YES → Use PATCH endpoint
  • If NO → Use /setup-tests endpoint

Customer's scenario:
They changed BOTH:

  • Plan-only attributes: run_setup_tests from false to true
  • Other attributes: sync_frequency, paused, pause_after_trial

Since there were "other" changes, the provider chose Path 1 (PATCH endpoint). The PATCH endpoint accepts the run_setup_tests parameter but the API ignores it unless there's also a config change.

Why API Doesn't Run Tests on PATCH Without Config Changes

The backend API has intentional logic in the PATCH endpoint:

Step 1: Check if config or auth fields changed
Step 2: If yes → Apply credential changes and run setup tests
Step 3: If no → Skip the entire setup test execution flow

Customer's PATCH request included:

  • run_setup_tests: true (the flag was set)
  • data_delay_threshold: changed from 0 to 1
  • config: empty object
  • auth: empty object

The API checked: "Did config or auth change?"

  • Answer: NO (both were empty objects)
  • Result: The entire setup test execution flow was skipped
  • The run_setup_tests flag was simply ignored

This is intentional API design because setup tests are meant to validate configuration. If no configuration changed, the API assumes there's nothing new to test.

The separate /setup-tests endpoint exists for exactly this use case: Running tests without requiring a config change.

The Fix:
The Terraform provider needs to always check if plan-only attributes changed FIRST, and call /setup-tests endpoint when needed, THEN handle any other attribute changes via PATCH. This ensures setup tests run regardless of what other attributes changed in the same update.

  1. Check plan-only attributes BEFORE checking other updates
  2. Always call /setup-tests when plan-only attributes change (not just when there are no other updates)
  3. Removed plan-only attributes from PATCH request (they're handled separately now)
  4. Both endpoints can be called in same update if needed

Check plan-only attributes first and call /setup-tests endpoint before
handling other updates via PATCH. This ensures setup tests run even when
other attributes change in the same update.

RD-1080143
Test will be added in separate PR after this fix is merged
@fivetran-jovanmanojlovic fivetran-jovanmanojlovic force-pushed the rd-1080143-fix-plan-only-attributes-update-logic branch from 44f7680 to e32680d Compare January 21, 2026 10:51
updatePerformed := false

if planOnlyAttributesChanged {
response, err := r.GetClient().NewConnectionSetupTests().ConnectionID(state.Id.ValueString()).DoCustom(ctx)
Copy link
Contributor

@fivetran-renat-sh fivetran-renat-sh Jan 22, 2026

Choose a reason for hiding this comment

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

In a situation when TF Config is having changes in both run_setup_tests and config, currently it seems it will end up in API requests sequence as:

  1. POST /connections/{}/test
  2. PATCH /connections/{} with { "config": {"password": "new-password"} },

i.e. setup tests are going to be performed on old config.

If this is so, looks like we need to switch the order - first patch connection, then run tests, as:

if hasUpdates {
  ...
  r.GetClient().NewConnectionUpdate()
  ...
}
if planOnlyAttributesChanged {
  ...
  r.GetClient().NewConnectionSetupTests() 
  ...
}

}

if planOnlyAttributesChanged {
response, err := r.GetClient().NewConnectionSetupTests().ConnectionID(state.Id.ValueString()).DoCustom(ctx)
Copy link
Contributor

@fivetran-renat-sh fivetran-renat-sh Jan 22, 2026

Choose a reason for hiding this comment

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

Seems we need to add trust-certificates and trust-fingerprints flags, like:

Suggested change
response, err := r.GetClient().NewConnectionSetupTests().ConnectionID(state.Id.ValueString()).DoCustom(ctx)
response, err := r.GetClient().NewConnectionSetupTests().
ConnectionID(state.Id.ValueString()).
TrustCertificates(trustCertificates...).
TrustFingerprints(trustFingerprints...).
DoCustom(ctx)

updatePerformed = true
}

if planOnlyAttributesChanged {
Copy link
Contributor

@fivetran-renat-sh fivetran-renat-sh Jan 22, 2026

Choose a reason for hiding this comment

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

Looks like we should not call /connection/{}/test if it is set to false in TF Config.

And have condition

  • either
	if planOnlyAttributesChanged && runSetupTestsToPreserve {
  • or if we're not calling tests in PATCH /connection/{} then probably
	if (planOnlyAttributesChanged || updatePerformed) && runSetupTestsToPreserve {

Copy link
Contributor

Choose a reason for hiding this comment

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

Edit - updated condition suggestion

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.

2 participants