Skip to content

refactor(object/diff): using customize diff to refresh origin values #7376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Lance52259
Copy link
Contributor

@Lance52259 Lance52259 commented Jul 28, 2025

What this PR does / why we need it:
The current function SuppressMapDiff() is incorrect for our resource's usage.
Because of the origin value cannot be obtain in the import phase.
For all origin attributes with the _origin suffix are both support optional behavior and DiffSuppressFunc function to hide the (known after apply) report.

Supports two function to get the script configurion (all and specified nested parameters).

Which issue this PR fixes:
(optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged)
fixes #xxx

Special notes for your reviewer:

Release note:

1. supports compose function to allow mutiple customize diff function
2. using customize diff to refresh origin values

PR Checklist

  • Tests added/passed.
go test -v -run TestResourceDiffunc
=== RUN   TestResourceDiffunc_ContainsAllKeyValues
    resource_diff_test.go:81: All processing results of the ContainsAllKeyValues method meets expectation
--- PASS: TestResourceDiffunc_ContainsAllKeyValues (0.00s)
=== RUN   TestResourceDiffunc_FindDecreaseKeys
    resource_diff_test.go:124: All processing results of the FindDecreaseKeys method meets expectation
--- PASS: TestResourceDiffunc_FindDecreaseKeys (0.00s)
=== RUN   TestResourceDiffunc_TakeObjectsDifferent
    resource_diff_test.go:167: All processing results of the TakeObjectsDifferent method meets expectation
--- PASS: TestResourceDiffunc_TakeObjectsDifferent (0.00s)
PASS
ok      github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils 0.010s
go test -v -run TestStateManagementFunc
=== RUN   TestStateManagementFunc_GetObjectFromRawConfig
=== RUN   TestStateManagementFunc_GetObjectFromRawConfig/null_value
=== RUN   TestStateManagementFunc_GetObjectFromRawConfig/string_value
=== RUN   TestStateManagementFunc_GetObjectFromRawConfig/number_value
=== RUN   TestStateManagementFunc_GetObjectFromRawConfig/float_value
=== RUN   TestStateManagementFunc_GetObjectFromRawConfig/bool_value
=== RUN   TestStateManagementFunc_GetObjectFromRawConfig/simple_object
=== RUN   TestStateManagementFunc_GetObjectFromRawConfig/nested_object
=== RUN   TestStateManagementFunc_GetObjectFromRawConfig/list_of_objects
=== RUN   TestStateManagementFunc_GetObjectFromRawConfig/complex_nested_structure
=== CONT  TestStateManagementFunc_GetObjectFromRawConfig
    state_management_test.go:159: All processing results of the GetObjectFromRawConfig method meets expectation
--- PASS: TestStateManagementFunc_GetObjectFromRawConfig (0.00s)
    --- PASS: TestStateManagementFunc_GetObjectFromRawConfig/null_value (0.00s)
    --- PASS: TestStateManagementFunc_GetObjectFromRawConfig/string_value (0.00s)
    --- PASS: TestStateManagementFunc_GetObjectFromRawConfig/number_value (0.00s)
    --- PASS: TestStateManagementFunc_GetObjectFromRawConfig/float_value (0.00s)
    --- PASS: TestStateManagementFunc_GetObjectFromRawConfig/bool_value (0.00s)
    --- PASS: TestStateManagementFunc_GetObjectFromRawConfig/simple_object (0.00s)
    --- PASS: TestStateManagementFunc_GetObjectFromRawConfig/nested_object (0.00s)
    --- PASS: TestStateManagementFunc_GetObjectFromRawConfig/list_of_objects (0.00s)
    --- PASS: TestStateManagementFunc_GetObjectFromRawConfig/complex_nested_structure (0.00s)
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/simple_property_access
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/nested_object_access
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/list_element_access
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/list_element_access_with_number
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/non-existent_path
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/empty_path
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/get_policy_object
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/get_annotations_list
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/get_first_annotation
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/get_second_annotation_key1
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/get_config_key1
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/get_first_owner_name
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/GetAttrFromRawConfig_limitation
=== CONT  TestStateManagementFunc_GetNestedObjectFromRawConfig
    state_management_test.go:418: All processing results of the GetNestedObjectFromRawConfig method meets expectation
--- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/simple_property_access (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/nested_object_access (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/list_element_access (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/list_element_access_with_number (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/non-existent_path (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/empty_path (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/get_policy_object (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/get_annotations_list (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/get_first_annotation (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/get_second_annotation_key1 (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/get_config_key1 (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/get_first_owner_name (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/GetAttrFromRawConfig_limitation (0.00s)
=== RUN   TestStateManagementFunc_RefreshObjectParamOriginValues
=== RUN   TestStateManagementFunc_RefreshObjectParamOriginValues/update_map_nested_key
=== RUN   TestStateManagementFunc_RefreshObjectParamOriginValues/update_list_element
=== CONT  TestStateManagementFunc_RefreshObjectParamOriginValues
    state_management_test.go:533: All RefreshObjectParamOriginValues safety tests passed
--- PASS: TestStateManagementFunc_RefreshObjectParamOriginValues (0.00s)
    --- PASS: TestStateManagementFunc_RefreshObjectParamOriginValues/update_map_nested_key (0.00s)
    --- PASS: TestStateManagementFunc_RefreshObjectParamOriginValues/update_list_element (0.00s)
PASS
ok      github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils 0.011s
  1. plan output (the remote tags configuration more than the local tags configuration)
image
  1. plan output (the local tags configuration more than the remote tags configuration)
image
  1. plan output (the local tags configuration have a new key/value pair and the remote tags configuration also have a new one)
image
  1. plan output (the local tags configuration want to add a new key/value pair and remove a key/value pair compared with history and the remote tags configuration have a new key/value pair)
image
  1. plan output (import function and the local tags configuration missing a key/value pair compared with the remote tags configuration)
image
  1. plan output (import function and the local tags configuration have a new key/value pair and missing a key/value pair compared with the remote tags configuration)
image
  • Documentation updated.

  • Schema updated.

  • CheckDeleted.

    • a. During query operation (Read Context)
      aa. Resource not found
      >>>>>> Paste the screenshot here <<<<<<

    • b. During delete/disassociate/unbind operation (Delete Context)
      ba. Resource not found
      >>>>>> Paste the screenshot here <<<<<<

@github-ci-robot github-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 28, 2025
@github-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This PR has been approved by: @Lance52259

@Lance52259 Lance52259 force-pushed the br_map_suppress_diff_refactor branch from 760bd7c to d423005 Compare July 31, 2025 01:50
@github-ci-robot github-ci-robot added the needs-rebase This branch has conflicts that must be resolved. label Jul 31, 2025
@Lance52259 Lance52259 force-pushed the br_map_suppress_diff_refactor branch from d423005 to b321ce0 Compare July 31, 2025 08:07
@github-actions github-actions bot added the chore label Jul 31, 2025
@github-ci-robot github-ci-robot removed the needs-rebase This branch has conflicts that must be resolved. label Jul 31, 2025
@Lance52259 Lance52259 force-pushed the br_map_suppress_diff_refactor branch 4 times, most recently from ec1dfb4 to 56c0d5f Compare August 4, 2025 03:53
@github-ci-robot github-ci-robot added the needs-rebase This branch has conflicts that must be resolved. label Aug 6, 2025
@Lance52259 Lance52259 force-pushed the br_map_suppress_diff_refactor branch from 56c0d5f to 3e69ed5 Compare August 19, 2025 02:24
@github-ci-robot github-ci-robot removed the needs-rebase This branch has conflicts that must be resolved. label Aug 19, 2025
@Lance52259
Copy link
Contributor Author

go test -v -run TestStateManagementFunc
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/empty_path_returns_entire_object
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/simple_string_field_access
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/simple_number_field_access
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/simple_boolean_field_access
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/null_field_access
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/list_field_access
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/list_element_access_by_index
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/list_element_access_by_index_1
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/list_element_access_by_index_2
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/nested_object_access
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/nested_object_property_access
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/nested_object_number_property_access
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/nested_list_access
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/nested_list_element_access
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/nested_list_element_property_access
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/nested_list_element_property_access_2
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/deep_nested_access_level1
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/deep_nested_access_level2
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/deep_nested_access_level3
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/deep_nested_final_value_access
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/mixed_types_strings_access
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/mixed_types_numbers_access
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/mixed_types_booleans_access
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/mixed_types_specific_string_element
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/mixed_types_specific_number_element
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/mixed_types_specific_boolean_element
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/non-existent_path_returns_nil
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/invalid_list_index_returns_nil
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/negative_list_index_returns_nil
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/non-numeric_list_index_returns_nil
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/accessing_property_on_primitive_type_returns_primitive_value
=== RUN   TestStateManagementFunc_GetNestedObjectFromRawConfig/accessing_property_on_null_value_returns_nil
--- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/empty_path_returns_entire_object (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/simple_string_field_access (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/simple_number_field_access (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/simple_boolean_field_access (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/null_field_access (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/list_field_access (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/list_element_access_by_index (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/list_element_access_by_index_1 (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/list_element_access_by_index_2 (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/nested_object_access (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/nested_object_property_access (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/nested_object_number_property_access (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/nested_list_access (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/nested_list_element_access (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/nested_list_element_property_access (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/nested_list_element_property_access_2 (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/deep_nested_access_level1 (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/deep_nested_access_level2 (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/deep_nested_access_level3 (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/deep_nested_final_value_access (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/mixed_types_strings_access (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/mixed_types_numbers_access (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/mixed_types_booleans_access (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/mixed_types_specific_string_element (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/mixed_types_specific_number_element (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/mixed_types_specific_boolean_element (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/non-existent_path_returns_nil (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/invalid_list_index_returns_nil (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/negative_list_index_returns_nil (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/non-numeric_list_index_returns_nil (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/accessing_property_on_primitive_type_returns_primitive_value (0.00s)
    --- PASS: TestStateManagementFunc_GetNestedObjectFromRawConfig/accessing_property_on_null_value_returns_nil (0.00s)
=== RUN   TestStateManagementFunc_RefreshObjectParamOriginValues
=== RUN   TestStateManagementFunc_RefreshObjectParamOriginValues/update_nested_map_key
=== RUN   TestStateManagementFunc_RefreshObjectParamOriginValues/update_list_element
=== RUN   TestStateManagementFunc_RefreshObjectParamOriginValues/error_on_non-existent_map_key
=== CONT  TestStateManagementFunc_RefreshObjectParamOriginValues
    state_management_test.go:569: All RefreshObjectParamOriginValues component tests passed successfully
--- PASS: TestStateManagementFunc_RefreshObjectParamOriginValues (0.00s)
    --- PASS: TestStateManagementFunc_RefreshObjectParamOriginValues/update_nested_map_key (0.00s)
    --- PASS: TestStateManagementFunc_RefreshObjectParamOriginValues/update_list_element (0.00s)
    --- PASS: TestStateManagementFunc_RefreshObjectParamOriginValues/error_on_non-existent_map_key (0.00s)
PASS
ok      github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils 0.012s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. chore refactor size/L size/M size/XL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants