Add importProperties parameter for selective property import#90
Open
RudyBricks wants to merge 3 commits into
Open
Add importProperties parameter for selective property import#90RudyBricks wants to merge 3 commits into
importProperties parameter for selective property import#90RudyBricks wants to merge 3 commits into
Conversation
Author
|
@microsoft-github-policy-service agree |
importProperties parameter for selective property import and improve state tracking
importProperties parameter for selective property import and improve state trackingimportProperties parameter for selective property import and improve state tracking
importProperties parameter for selective property import and improve state tracking importProperties parameter for selective property import and improve state tracking
Author
|
@ms-henglu anything I can do to make the review easier for you? |
importProperties parameter for selective property import and improve state tracking importProperties parameter for selective property import
RudyBricks
force-pushed
the
fix-89-import-drift
branch
from
July 19, 2026 19:16
6510040 to
1ca9918
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR enhances the import functionality for
msgraph_resourceso that existing Microsoft Graph resources can be imported without triggering unintended modifications (Fixes #89). It introduces theimportPropertiesquery parameter, which lets users declare exactly which properties Terraform should manage.Changes
1. Import with selective properties (
importProperties)importPropertiesquery parameter in import IDs/groups/{id}?importProperties=displayName,mailEnabled,mailNickname,securityEnablednullin state during importweb.redirectUris)web,web.redirectUrisandweb.redirectUris,webseed the same bodyweb..redirectUris,web.,.web) are skipped without affecting the remaining propertiesImportStateperforms no API calls — it parses the import ID and seeds state, and the values are filled in by the following Read.2. Tests
Added
internal/services/import_properties_test.go— 21 table-driven cases, no credentials or network required:TestAddNullPropertycovers flat, nested and deep paths, shared parents, duplicates, all three parent/child collision orderings, and malformed pathsTestImportStateBodydrivesImportStateend to end and assertsbody,url,idandapi_versionfor: no query parameter, single and nested properties, whitespace trimming, empty and separator-only values,api-version=betacombined withimportProperties, and$refimports3. Documentation
docs/guides/importing_resources.md(and itstemplates/source), covering the workflow, nested and overlapping property paths, API versions,$refrelationships, best practices and troubleshootingdocs/resources/resource.mdwith import examplesexamples/imports/groups/Use case
Before: importing a resource left
bodynull. On the next plan Terraform saw every configured property as missing from state and proposed an in-place update, sending a redundantPATCHthat rewrote properties which already held the correct values:After: users import exactly the properties they intend to manage, and the first plan is clean:
terraform import msgraph_resource.group "/groups/{id}?importProperties=displayName,mailEnabled,mailNickname,securityEnabled"Verification
Besides the unit tests, the workflow was exercised against a live tenant using the example in
examples/imports/groups/:importProperties0 to change; follow-up plan reports no changesimportProperties1 to change— the behaviour being fixed1 to change, scoped to that property alonebodynorimportProperties0 to change; never enters state