Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 5, 2025

This PR migrates the elasticstack_elasticsearch_security_role_mapping resource and data source from the legacy Terraform SDKv2 to the modern Terraform Plugin Framework, bringing consistency with other recently migrated resources like system_user and enrich_policy.

Changes Made

New Plugin Framework Implementation

  • Resource: Implemented in internal/elasticsearch/security/role_mapping/ following the established code organization pattern
  • Data Source: Uses extracted read logic to maintain code reuse while eliminating mock resource instances
  • Schema: Maintains full compatibility with existing configurations while adding proper validators and normalized JSON types
  • JSON Handling: Uses jsontypes.NormalizedType{} for rules, role_templates, and metadata fields to suppress insignificant formatting differences

Key Features Preserved

  • All existing attributes and their behavior remain unchanged
  • Support for both roles and role_templates with exactly-one-of validation
  • Custom elasticsearch_connection block support
  • JSON encoding/decoding for complex fields with proper normalization
  • Import functionality

Code Quality Improvements

  • Extracted Read Logic: Created reusable readRoleMapping function returning RoleMappingData and framework diagnostics
  • Framework Diagnostics: Updated all role mapping functions to use consistent framework diagnostics instead of mixed SDK/framework types
  • Simplified Checks: Replaced verbose null/unknown checks with utils.IsKnown() helper
  • Consistent Updates: Update operations now read back the modified resource for consistent results
  • Removed Legacy Code: Deleted old SDKv2 resource files and unused imports
  • Utility Functions: Replaced manual type conversion with utils.SetValueFrom and utils.SetTypeAs for cleaner code

Test Coverage

  • Migrated all existing acceptance tests to the new structure
  • Added SDK compatibility test using provider version 0.11.17 to ensure smooth migration for existing users
  • Includes tests for create, update, role templates, and data source functionality

Migration Benefits

  • Performance: Plugin Framework provides better performance and resource handling
  • Type Safety: Stronger type validation and better error messages with normalized JSON types
  • Future-Proof: Aligns with Terraform's long-term direction
  • Consistency: Matches the pattern used by other migrated resources in this provider

The migration maintains 100% backward compatibility - existing Terraform configurations will continue to work without any changes required.

Recent Updates

  • Migrated role mapping resource and data source to Plugin Framework
  • Extracted read logic to reusable function
  • Updated all functions to use framework diagnostics
  • Added normalized JSON types for rules, role_templates, and metadata
  • Removed old SDKv2 resource files
  • Applied code formatting
  • Simplified diagnostics handling in create and delete methods
  • Added normalized JSON types to data source schema
  • Replaced manual role type conversion with utility functions for cleaner code

Fixes #1279.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@Copilot Copilot AI assigned Copilot and tobio Sep 5, 2025
Copy link

cla-checker-service bot commented Sep 5, 2025

❌ Author of the following commits did not sign a Contributor Agreement:
d9f7381, e7af822, c4160f0, 3c6e7a1, 6a1e17a, 6727aac, 1667660

Please, read and sign the above mentioned agreement if you want to contribute to this project

@Copilot Copilot AI changed the title [WIP] Migrate the Elasticsearch role mapping resource and data source to the plugin framework Migrate Elasticsearch role mapping resource and data source to Plugin Framework Sep 5, 2025
@Copilot Copilot AI requested a review from tobio September 5, 2025 04:35
Copilot finished work on behalf of tobio September 5, 2025 04:35
tobio

This comment was marked as outdated.

@tobio

This comment was marked as outdated.

…s, use framework diagnostics, and cleanup

Co-authored-by: tobio <[email protected]>

This comment was marked as outdated.

This comment was marked as outdated.

@Copilot Copilot AI requested a review from tobio September 5, 2025 06:19
Copilot finished work on behalf of tobio September 5, 2025 06:19
tobio

This comment was marked as outdated.

This comment was marked as outdated.

@Copilot Copilot AI requested a review from tobio September 5, 2025 10:09
Copilot finished work on behalf of tobio September 5, 2025 10:09
tobio

This comment was marked as outdated.

This comment was marked as outdated.

Copilot finished work on behalf of tobio September 5, 2025 10:41
@Copilot Copilot AI requested a review from tobio September 5, 2025 10:41
@tobio tobio marked this pull request as ready for review September 5, 2025 11:08
@tobio tobio requested review from dimuon, nick-benoit and a team September 5, 2025 11:08
@tobio tobio merged commit 0baefee into main Sep 7, 2025
94 of 96 checks passed
@tobio tobio deleted the copilot/fix-1279 branch September 7, 2025 21:48
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.

Migrate the Elasticsearch role mapping resource and data source to the plugin framework
3 participants