Repository navigation
fix: align external names with Terraform state IDs and remove unused import IDs - #201
Closed
fernandezcuesta wants to merge 1 commit into
Closed
fernandezcuesta wants to merge 1 commit into
fernandezcuesta wants to merge 1 commit into
Conversation
…import IDs - project_api_key: use api_key_id only (project IDs are only in project_assignment) - cloud_user_team_assignment: template uses user_id; add userId reference to UserOrgAssignment - resource_policy, encryption_at_rest_private_endpoint: use the plain provider-assigned ID - ai_model_api_key, cloud_backup_collection_restore_job, metric_integration, stream_connection_failover, log_integration: new computedKeyID constructor for plugin-framework resources without an id attribute - ai_model_rate_limit: read the external name from model_group_name - x509_authentication_database_user: add username to the state ID - cluster: add provider_name to the state ID - encodedStateGetIDFn: decode external names written as full state IDs by v1.1.x - remove GetImportIDFn and the separator argument; the no-fork connectors never run terraform import - refs.ExtractParamPath: rename the second parameter to isObservation Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>
fernandezcuesta
force-pushed
the
fix/resource-policy-ear-endpoint-external-name
branch
from
October 5, 2026 23:15
e276c59 to
89194cc
Compare
fernandezcuesta
marked this pull request as draft
October 5, 2026 23:16
55 of 78 tasks
Collaborator
Author
|
Superseded by #206 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description of your changes
This PR fixes the external name configuration of 12 resources. In each one, the configured ID does not match the Terraform schema or the ID that Terraform Read expects. The PR also removes the import-ID code, because the no-fork connectors never call it.
All controllers in this provider use the no-fork connectors, which never run
terraform import.Only
GetIDFn(external name to Terraform state ID) andGetExternalNameFn(state to external name) have an effect, so the import formats in the Terraform docs (for example{ORG_ID}-{POLICY_ID}) do not apply.Resources where create fails
mongodbatlas_project_api_key:GetIDFnneeds a top-levelproject_id, but this resource has project IDs only inproject_assignment. Create and import fail withforProvider is missing [project_id]. Terraform reads onlyapi_key_idfrom the state ID, so the config now usesapi_key_idonly. Supersedes fix(project): build the APIKey Terraform ID from api_key_id #199.mongodbatlas_cloud_user_team_assignment: the template usesusername, which is computed. The required argument isuser_id. The template now usesuser_id, anduserIdcan reference aUserOrgAssignment(status.atProvider.userId).mongodbatlas_resource_policyandmongodbatlas_encryption_at_rest_private_endpoint:GetIDFnsends<orgId>-<policyId>(or<projectId>-<cloudProvider>-<endpointId>) to Read, which expects the plain provider-assigned ID.GetExternalNameFnalso fails on the real state ID withexpected at least 1 left segments. Both resources now use the defaultidentifierFromProvider().mongodbatlas_ai_model_api_key,mongodbatlas_cloud_backup_collection_restore_job,mongodbatlas_metric_integration,mongodbatlas_stream_connection_failoverandmongodbatlas_log_integrationare plugin-framework resources with noidattribute.GetExternalNameFnreadsid, so it fails after create withid not found in Terraform state. Before create, the Read path parameter is empty, and an import with only the annotation cannot work. This is the same root cause asServiceAccountresources (bothmongodbatlas.crossplane.ioandproject.mongodbatlas.crossplane.io) reportReady=Trueone second after they are applied, never reachSynced=True, and never create anything in Atlas. #189.log_integrationalso usedtypeas external name, which does not identify one integration. A new constructor,computedKeyID(key), reads the external name from the computed key, copies the annotation into the key for imports, and does not overwrite a key that is already in the state. Each of these resources also setsStateEmptyWhenAttributeUnset(key), so that Create runs.mongodbatlas_ai_model_rate_limithas noidattribute either, and itsGetExternalNameFnfailed the same way. It now reads the external name frommodel_group_name.Resources where observed state is incomplete
mongodbatlas_x509_authentication_database_user: the state ID had nousername, so Terraform Read skipped the user certificates. The state ID now includesusernamewhen it is set.mongodbatlas_cluster: the state ID had noprovider_name, which Terraform Read uses to read containers. The state ID now includes it.External names from v1.1.x
In v1.1.x, the external name of resources that use
EncodeStateIDwas the full encoded state ID.encodedStateGetIDFnencoded that value a second time, and Read did not find the resource.encodedStateGetIDFnnow decodes the external name first, for allimportJoinedID*resources.Code cleanup
GetImportIDFn,plainImportGetIDFnandcollectImportValues. Upjet readsGetImportIDFnonly in the fork workspace path (pkg/terraform/store.go). No controller in this provider uses that path.separatorparameter ofimportJoinedIDandimportJoinedIDAssigned. Only the import ID used it. The state ID always uses theEncodeStateIDformat.refs.ExtractParamPath: the second parameter is nowisObservation(wassensitive). Upjet uses it to selectstatus.atProviderorspec.forProvider. No caller or generated code changes.Missing references
UserTeamAssignment: new optionaluserIdRefanduserIdSelectorfields.LogIntegrationcontrollers: the name initializer is removed (computedKeyIDdisables it).Points for reviewers
LogIntegrationobjects change behavior. On the first reconcile after the upgrade, the external name changes from the integrationtype(for exampleS3) to the integration ID. The realintegration_idcomes fromstatus.atProvider, and the guard incomputedKeyIDkeeps it. Tools that read this annotation will see the new value.docs/import.mdis updated for all changed resources. New rows are added for the resources that can now be imported.project_service_account_secretandservice_account_secretare not changed. The secret value is only available at create, so an import is not useful.Refs #113, #189, #199
I have:
make reviewable testto ensure this PR is ready for review.How has this code been tested
config/external_name_test.gocall the configuredGetIDFn,GetExternalNameFn,SetIdentifierArgumentFnandTerraformPluginFrameworkIsStateEmptyFnof each changed resource. Each test failed before its fix.GetIDFnoutput for all resources, before and after the change, shows differences only in the resources above.DisableNameInitializerchanges only forlog_integration.EncodeStateIDcalls,ReadandImportStatefunctions).go test ./config/...,make lint(0 issues),go build ./...andmake generatepass.