-
Notifications
You must be signed in to change notification settings - Fork 5
Description
Description
The import functionality for Group Policy resources (microsoft365_graph_beta_device_management_group_policy_text_value, microsoft365_graph_beta_device_management_group_policy_boolean_value, and microsoft365_graph_beta_device_management_group_policy_multi_text_value) does not work correctly. When attempting to import these resources, the provider fails with an error stating that policy_name, class_type, and category_path fields are required for auto-discovery, even though the resource exists in Intune.
This prevents users from importing existing Group Policy Administrative Template configurations into Terraform state.
Steps to Reproduce
- Create a Group Policy configuration with presentation values in Intune (or use an existing one)
- Attempt to import a group policy text value resource using Terraform import block:
import {
to = microsoft365_graph_beta_device_management_group_policy_text_value.example
id = "config-id/definition-value-id/presentation-value-id"
}- Run
terraform plan
Expected Behavior
The import should:
- Parse the composite ID (configID/definitionValueID/presentationValueID)
- Fetch the resource from the Graph API
- Populate all fields including
policy_name,class_type, andcategory_pathfrom the API response - Successfully import the resource into Terraform state
Actual Behavior
Import fails with error:
Error: Error resolving IDs during read
Could not resolve definition and presentation IDs for graph_beta_device_management_group_policy_text_value (HTTP 0): provide policy_name, class_type, and category_path for auto-discovery
The import function only sets the id field in state, leaving policy_name, class_type, and category_path as null. When the Read function is called after import, the resolver fails because these required metadata fields are missing.
Environment
- OS: Windows
- Terraform Version: 1.13.4
- Provider Version: 0.35.0-alpha (main branch)
- Graph API: Microsoft Graph Beta
Root Cause
The import function uses resource.ImportStatePassthroughID() which only sets the id field. The Read function then calls the GroupPolicyIDResolver which requires policy_name, class_type, and category_path to be present in state to resolve the definition and presentation template IDs. During import, these fields don't exist in state yet, causing the validation to fail.
Proposed Solution
Implement a composite ID import pattern with a helper function to fetch metadata from the API:
- Update ImportState function to parse composite ID format:
configID/definitionValueID/presentationValueID - Enhance Read function to detect import scenarios (when IDs exist but metadata is missing)
- Add helper function
populateMetadataFromAPI()that:- Fetches definition values with
$expand=definition - Extracts
policy_name(displayName),class_type, andcategory_pathfrom the definition - Optionally fetches presentation template ID from presentation value
- Populates these fields in the model before the resolver runs
- Fetches definition values with
This approach:
- Reuses existing Read logic
- Follows common Terraform provider patterns (AWS, Azure)
- Works with the Graph API's navigation properties correctly
- Maintains backward compatibility with normal CRUD operations
Files Affected
internal/services/resources/device_management/graph_beta/group_policy_text_value/resource.go- ImportState functioninternal/services/resources/device_management/graph_beta/group_policy_text_value/crud.go- Read function enhancementinternal/services/resources/device_management/graph_beta/group_policy_text_value/import.go- New helper functionexamples/resources/microsoft365_graph_beta_device_management_group_policy_text_value/import.sh- Updated documentation
Similar changes needed for:
group_policy_boolean_valuegroup_policy_multi_text_value