Skip to content

Conversation

@intuneascode
Copy link
Contributor

@intuneascode intuneascode commented Nov 12, 2025

Summary

This PR fixes the import functionality for Group Policy Administrative Template (ADMX) resources by implementing composite ID parsing and API-based metadata resolution. Previously, importing group_policy_text_value, group_policy_boolean_value, and group_policy_multi_text_value resources failed because the resolver required metadata fields (policy_name, class_type, category_path) that were not populated during import.

Issue Reference

Fixes #867

Motivation and Context

  • Why: The existing import implementation used ImportStatePassthroughID() which only set the id field, leaving required metadata fields null. This caused the Read function's resolver to fail with "provide policy_name, class_type, and category_path for auto-discovery"
  • What problem it solves: Enables users to import existing Group Policy configurations from Intune into Terraform state, which is essential for managing existing infrastructure as code
  • How: Implemented a composite ID import pattern (configID/definitionValueID/presentationValueID) with a helper function that fetches metadata from the Microsoft Graph API during import

Dependencies

  • No new dependencies required
  • Uses existing Microsoft Graph Beta SDK for API calls
  • Requires $expand=definition query parameter support in Graph API (already available)

Type of Change

Please mark the relevant option with an x:

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📝 Documentation update (Wiki/README/Code comments)
  • ♻️ Refactor (code improvement without functional changes)
  • 🎨 Style update (formatting, renaming)
  • 🔧 Configuration change
  • 📦 Dependency update

Changes Made

Files Modified

group_policy_text_value resource:

  • resource.go: Updated ImportState() to parse composite ID format
  • crud.go: Enhanced Read() to detect import scenarios and call metadata helper
  • import.go: Created populateMetadataFromAPI() helper function
  • import.sh: Updated example to show composite ID format

Similar changes applied to:

  • group_policy_boolean_value (same pattern)
  • group_policy_multi_text_value (same pattern)

Key Implementation Details

  1. Composite ID Format: configID/definitionValueID/presentationValueID
  2. Import Detection: Read function checks if metadata fields are null while IDs exist
  3. API Metadata Fetch: Uses GET /deviceManagement/groupPolicyConfigurations/{id}/definitionValues with $expand=definition
  4. Extracted Fields: policy_name (displayName), class_type, category_path, and optionally presentation_id

Testing

  • Tested import functionality with real Intune Group Policy configurations
  • Verified metadata is correctly extracted from Graph API responses
  • Confirmed normal CRUD operations (Create/Update/Delete) remain unaffected
  • Validated composite ID parsing with multiple test cases
  • Tested with authenticated Graph API client against production tenant

Test Environment:

  • Windows 11
  • Terraform 1.x with local provider override
  • Microsoft Graph Beta API
  • Dell Command Update ADMX policy configurations

Quality Checklist

  • I have reviewed my own code before requesting review
  • I have verified there are no other open Pull Requests for the same update/change
  • My code follows the established style guidelines of this project
  • I have added necessary documentation (updated import.sh examples)
  • I have commented my code, particularly in complex areas (import helper function)
  • My changes generate no new warnings
  • I have performed a self-review of my own code
  • My code is properly formatted according to Go standards
  • I have tested the changes locally with the provider development override

Additional Notes

This implementation follows common Terraform provider patterns seen in AWS, Azure, and GCP providers for handling complex import scenarios. The approach:

  • Maintains backward compatibility with existing resources
  • Reuses existing Read logic to avoid duplication
  • Properly handles Microsoft Graph API navigation properties with $expand
  • Can be easily extended to other Group Policy resource types if needed

An example showing importing Dell ADMX Template Update Settings value.

terraform {
  required_providers {
    microsoft365 = {
      source = "deploymenttheory/microsoft365"
    }
  }
}


import {
  to = microsoft365_graph_beta_device_management_group_policy_text_value.dell_command_update_broad_ec63adea_a781_487b_85de_0bda63641530_664685e4_bf2c_4c74_93f7_219e5c030760
  id = "a5eef1df-19b0-41c5-8631-8a1f2fbb8d13/ec63adea-a781-487b-85de-0bda63641530/664685e4-bf2c-4c74-93f7-219e5c030760"
}

resource "microsoft365_graph_beta_device_management_group_policy_text_value" "dell_command_update_broad_ec63adea_a781_487b_85de_0bda63641530_664685e4_bf2c_4c74_93f7_219e5c030760" {
  group_policy_configuration_id = "a5eef1df-19b0-41c5-8631-8a1f2fbb8d13"
  policy_name                   = "Update Settings"
  class_type                    = "machine"
  category_path                 = "\\Dell\\Dell Command Update\\Update Settings"
  enabled                       = true
  value                         = "Tuesday"
}

@intuneascode intuneascode marked this pull request as draft November 13, 2025 00:22
@intuneascode intuneascode marked this pull request as ready for review November 13, 2025 01:29
@github-actions
Copy link
Contributor

This pull request has been automatically marked as stale because it has not had recent activity.
It will be closed in 2 days if no further activity occurs.

@github-actions github-actions bot added the stale label Nov 20, 2025
@github-actions
Copy link
Contributor

This pull request has been automatically closed due to inactivity.
If you'd like to continue this work, please reopen it or create a new pull request.

@github-actions github-actions bot closed this Nov 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug Report: Importing Group Policy Text Value failing

1 participant