Fix GlobalCredentials flattening function #277
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.
The
flattenDiscoveryGetGlobalCredentialsItemsfunction was attempting to set ALL possible credential fields for every credential type, causing "Invalid address to set" errors and JSON unmarshaling failures when creating and reading global credentials.Problem
When executing
terraform applyon the device-credentials example, users encountered errors like:The root cause was that the flattening function tried to set SNMPv3-specific fields (like
auth_password,privacy_type,snmp_mode) on CLI credentials, HTTP-specific fields on SNMP credentials, etc., causing type mismatches and invalid field assignments.Solution
Modified
flattenDiscoveryGetGlobalCredentialsItemsincatalystcenter/data_source_global_credential.goto use defensive field setting:id,comments,description,credential_type,instance_tenant_id,instance_uuiditem.Port != nil && *item.Port != 0before setting port valuesExample
Before (CLI credential would incorrectly try to set SNMPv3 fields):
After (only sets fields with meaningful values):
Result
The fix is backward-compatible and defensive - it only improves behavior without breaking existing functionality.