Add custom external name configurations #43
+154
−7
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.
Fix: Handle empty external-name in GetIDFn to prevent incomplete composite IDs
Description
This PR fixes an issue where resources with composite ID formats were generating incomplete IDs in Terraform state when the
external-namewas empty (during initial resource creation). This caused Terraform refresh operations to fail with OVH API errors.Problem
When resources are being created, they don't yet have an
external-nameannotation set. However, theGetIDFnfunction was still being called during state initialization, causing it to construct incomplete composite IDs such as:f93f1228ddd841578fc3069b5cf2fd7d/(missing user_id for User resource)f93f1228ddd841578fc3069b5cf2fd7d/EU-WEST-PAR/(missing gateway_id for Gateway resource)f93f1228ddd841578fc3069b5cf2fd7d/network-id/(missing subnet_id for Subnet resource)These incomplete IDs were then set in the Terraform state, causing subsequent refresh operations to fail with OVH API errors:
Root Cause
The issue occurs in the following flow:
external-nameEnsureTFState()is called to initialize Terraform stateGetIDFn()is called with emptyexternalNameparameterGetIDFn()constructs partial composite ID (e.g.,service_name/)Solution
Updated
GetIDFnimplementations for resources with composite ID formats to check ifexternalNameis empty and return an empty string instead of constructing an incomplete ID.Changes
Modified
config/external_name.goto add emptyexternalNamechecks inGetIDFnfor:PrivateNetwork (
ovh_cloud_project_network_private)service_name/network_id""ifexternalNameis emptySubnet (
ovh_cloud_project_network_private_subnet)service_name/network_id/subnet_id""ifexternalNameis emptyUser (
ovh_cloud_project_user)service_name/user_id""ifexternalNameis emptyS3Credentials (
ovh_cloud_project_user_s3_credential)service_name/user_id/access_key_id""ifexternalNameis emptyGateway (
ovh_cloud_project_gateway)service_name/region/gateway_id""ifexternalNameis emptyS3Policy (
ovh_cloud_project_user_s3_policy)service_name/user_idexternalNamein ID, only added documentation commentTest Scenarios
Impact
externalNameis emptyRelated Work
ovh_cloud_project_storageNotes
This fix is essential for resources that use composite IDs (IDs composed of multiple parameters). When combined with the upjet Import fallback for async resources, it provides a complete solution for handling resource state across pod restarts and Velero backup/restore operations.
The S3Policy resource configuration was updated with documentation comments but doesn't require the empty check since its ID format (
service_name/user_id) doesn't depend on theexternalNamevalue.