pulumi-terraform-bridge: Validation errors not actionable during resource import

What happened?

Lifting https://github.com/pulumi/pulumi-gitlab/issues/293 issue to the bridge. It appears that a resource import on a bridged provider can generate code that returns TF validation errors that are not really actionable as the user cannot edit the code as suggested, as the code is abbreviated and only pointing to the imported resource.

import * as pulumi_gitlab from "@pulumi/gitlab";
new pulumi_gitlab.Project("import_test", {}, {import: "qerub/import_test", ignoreChanges: ["containerExpirationPolicy"]});
error: gitlab:index/project:Project resource 'import_test' has a problem: Conflicting configuration arguments: "container_expiration_policy.0.name_regex": conflicts with container_expiration_policy.0.name_regex_delete. Examine values at 'Project.ContainerExpirationPolicy.NameRegex'.
error: gitlab:index/project:Project resource 'import_test' has a problem: Conflicting configuration arguments: "container_expiration_policy.0.name_regex_delete": conflicts with container_expiration_policy.0.name_regex. Examine values at 'Project.ContainerExpirationPolicy.NameRegexDelete'.
error: Preview failed: one or more inputs failed to validate
error: preview failed

Expected Behavior

Importing a resource should not work harder to not generate code that’s invalid (fails validators) on pulumi up; if this cannot be accomplished then an escape hatch needs to be provided so the user can make progress in this situation.

Steps to reproduce

See above.

Output of pulumi about

See original ticket.

Additional context

N/A

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you’ve opened one already).

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 16 (16 by maintainers)

Commits related to this issue

Most upvoted comments

https://github.com/pulumi/pulumi-aws/issues/2318#issuecomment-2071042174 I’ve got some really good information from debugging 2318 further! This works fine in TF because it doesn’t do import the same way Pulumi does at all.

https://pulumi-developer-docs.readthedocs.io/en/latest/architecture/import.html is the algorithm involved here.

In the case of 2318 Check fails - check is called by the algorithm above. TF does not assume that Read results will pass Check validation. Note also that in 2318 refresh already works perfectly fine because it correctly decides that these fields are outputs, not inputs.

I’d love to fix this surgically for import only. I think we need to enable Read to return inputs that can pass Check. This essentially involves changing the behavior of https://github.com/pulumi/pulumi-terraform-bridge/blob/master/pkg/tfbridge/schema.go#L1757

We can:

  • teach this function an automated mechanism to respect conflicts and at random (alphabetically biased to be deterministic?) remove entries that would conflict; bridge decides this
  • add a hook to this function so that affected resources can override or augment the behavior, say never copy both availability_zone_id and availability_zone to inputs during import; pick one - but now provider decides
  • add a PropertyInfo property that would inform the behavior of this function, say never copy availability_zone_id to an input but always copy availability_zone

I think it would be great to lineup a few more issues that we’re confident we can fix here to decide which route we take, but also welcoming comments/ideas here.