Skip to content

Fix: detect is_inactive drift when environment state changes outside Terraform#1088

Merged
yarivg merged 3 commits into
mainfrom
eng-1310-is-inactive-drift-detection
Mar 12, 2026
Merged

Fix: detect is_inactive drift when environment state changes outside Terraform#1088
yarivg merged 3 commits into
mainfrom
eng-1310-is-inactive-drift-detection

Conversation

@yarivg

@yarivg yarivg commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Set is_inactive from API response (IsArchived) during environment read/refresh, not just during import
  • Previously, setEnvironmentSchema skipped IsArchived (tagged tfschema:"-") so terraform plan couldn't detect when an environment was activated/deactivated outside Terraform (e.g. from the UI)

Fixes #1052

Test coverage - is_inactive permutations

# Step 1 (config) Step 2 (config) Expected behavior
1 is_inactive = false is_inactive = true Update → deactivates env
2 is_inactive = true is_inactive = false Update → re-activates env
3 is_inactive = false (removed) No change (default is false)
4 is_inactive = true (removed) Update → re-activates env (default is false)
5 (not set) is_inactive = true Update → deactivates env
6 (not set) is_inactive = false No change (default is false)

The is_inactive field (mapped to IsArchived in the API) was only being
set from the API response in the importer, not in setEnvironmentSchema
which is called during normal reads/refreshes. This meant terraform plan
could not detect when an environment was re-activated from the UI.

@RLRabinowitz RLRabinowitz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just making sure - there's no drift when creating an environment without is_inactive at all, and then re-planning? Want to make sure it doesn't show is_inactive as it will be set to true all of a sudden

Comment thread env0/resource_environment.go Outdated
return fmt.Errorf("schema resource data serialization failed: %w", err)
}

d.Set("is_inactive", false)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We probably need to remove the similar code from resource import

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@github-actions github-actions Bot added the ready to merge PR approved - can be merged once the PR owner is ready label Mar 12, 2026
yarivg added 2 commits March 12, 2026 16:01
- Avoids panic when setEnvironmentSchema is called from data source
  (which doesn't have is_inactive in its schema)
- Removes duplicate is_inactive code from the importer (Read is called
  after import anyway)
@yarivg

yarivg commented Mar 12, 2026

Copy link
Copy Markdown
Contributor Author

We probably need to remove the similar code from resource import
@RLRabinowitz

Done in 4a88880 — moved is_inactive setting to resourceEnvironmentRead (instead of setEnvironmentSchema) and removed the duplicate from the importer.

This also fixes a CI panic where setEnvironmentSchema is called from the data source which doesn't have is_inactive in its schema.


Just making sure - there's no drift when creating an environment without is_inactive at all, and then re-planning?

Verified against dev API — created environment without is_inactive in config, applied, re-planned → "No changes." No false drift.

@yarivg yarivg merged commit 08fa757 into main Mar 12, 2026
4 checks passed
@yarivg yarivg deleted the eng-1310-is-inactive-drift-detection branch March 12, 2026 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

provider ready to merge PR approved - can be merged once the PR owner is ready

Projects

None yet

Development

Successfully merging this pull request may close these issues.

is_inactive from env0_environment does not detect changes

2 participants