Skip to content
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

[engine/import] Guess ID references of dependant resources when generating code for import operations #16208

Merged
merged 1 commit into from
May 20, 2024

Conversation

Zaid-Ajaj
Copy link
Contributor

Description

Taking an initial attempt at #10025 where we now try to guess ID references of dependant resources instead of writing out the IDs as literal values.
Instead of:

// has ID=provider-generated-bucket-id-abc123
resource exampleBucket "aws:s3/bucket:Bucket" {}

resource exampleBucketObject "aws:s3/bucketObject:BucketObject" {
    bucket = "provider-generated-bucket-id-abc123"
    storageClass = "STANDARD"
}

We generate:

resource exampleBucket "aws:s3/bucket:Bucket" {}

resource exampleBucketObject "aws:s3/bucketObject:BucketObject" {
    bucket = exampleBucket.id
    storageClass = "STANDARD"
}

This implies a dependency between exampleBucketObject and exampleBucket without explicitly being added into the dependsOn array (it would be redundant)

Checklist

  • I have run make tidy to update any new dependencies
  • I have run make lint to verify my code passes the lint check
    • I have formatted my code using gofumpt
  • I have added tests that prove my fix is effective or that my feature works
  • I have run make changelog and committed the changelog/pending/<file> documenting my change
  • Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version

@pulumi-bot
Copy link
Contributor

pulumi-bot commented May 15, 2024

Changelog

[uncommitted] (2024-05-20)

Features

  • [engine] Guess ID references of dependant resources when generating code for import operations
    #16208

Copy link
Member

@Frassle Frassle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if multiple resources have the same ID? Do we just pick one randomly, or fall back to the literal string?

@Zaid-Ajaj
Copy link
Contributor Author

What if multiple resources have the same ID? Do we just pick one randomly, or fall back to the literal string?

I didn't think about that 🤔 right now this will pick the first ID that was detected. I think if we want to be deterministic, we would have to remove ambiguous references to the same ID and the program would fall back to the literal value. However, if this is a highly unlikely event, we can maybe keep it as is.

@Zaid-Ajaj Zaid-Ajaj force-pushed the zaid/import-codegen-guessing-id-references branch 2 times, most recently from d351184 to 9d873a6 Compare May 16, 2024 12:11
@Zaid-Ajaj Zaid-Ajaj marked this pull request as ready for review May 16, 2024 13:48
@Zaid-Ajaj Zaid-Ajaj requested a review from a team as a code owner May 16, 2024 13:48
@Zaid-Ajaj Zaid-Ajaj force-pushed the zaid/import-codegen-guessing-id-references branch from bdda341 to 7db586a Compare May 17, 2024 16:58
@Zaid-Ajaj
Copy link
Contributor Author

@Frassle I've updated the PR such that now when multiple resources have the same ID, we don't make a reference to any of them and instead use the literal value instead. More generally, pathed values with different paths but equal values are removed. This will work nicely without any ambiguity when we extend the pathed values not just for {resource}.id but for any output of a resource used an input for another resource

@@ -307,6 +353,8 @@ func simplerType(t, u schema.Type) bool {

// zeroValue constructs a zero value of the given type.
func zeroValue(t schema.Type) model.Expression {
emptyImportState := ImportState{}
onRefereceAdded := func(string) {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
onRefereceAdded := func(string) {}
onReferenceAdded := func(string) {}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done ✅

@Zaid-Ajaj Zaid-Ajaj force-pushed the zaid/import-codegen-guessing-id-references branch from 9d7b6a5 to 4c4d51c Compare May 20, 2024 16:26
@Zaid-Ajaj Zaid-Ajaj enabled auto-merge May 20, 2024 16:26
@Zaid-Ajaj Zaid-Ajaj added this pull request to the merge queue May 20, 2024
Merged via the queue into master with commit bf606d3 May 20, 2024
49 checks passed
@Zaid-Ajaj Zaid-Ajaj deleted the zaid/import-codegen-guessing-id-references branch May 20, 2024 17:57
github-merge-queue bot pushed a commit that referenced this pull request May 24, 2024
Tentative changelog:

### Features

- [engine] Guess ID references of dependant resources when generating
code for import operations
  [#16208](#16208)


### Bug Fixes

- [engine] Check property dependencies and deleted-with relationships
for target dependents
  [#16220](#16220)

- [engine] Propagate dependencies of untargeted resources correctly
during targeted updates
  [#16247](#16247)

- [backend/diy] Rewrite DeletedWith references when renaming stacks
  [#16216](#16216)

- [sdk/python] Use a separate type variable for static methods on Output
  [#16172](#16172)

- [sdk/python] Relax Output.all types to better match the implementation
  [#16172](#16172)

- [sdkgen/python] Generate __init__.py files for modules that only
contain enumerations
  [#16229](#16229)
@justinvp justinvp mentioned this pull request May 24, 2024
github-merge-queue bot pushed a commit that referenced this pull request May 24, 2024
To be merged after:
- #16261
- pulumi/pulumi-docker-containers#195

Tentative changelog...

### Features

- [engine] Guess ID references of dependant resources when generating
code for import operations
  [#16208](#16208)


### Bug Fixes

- [engine] Check property dependencies and deleted-with relationships
for target dependents
  [#16220](#16220)

- [engine] Propagate dependencies of untargeted resources correctly
during targeted updates
  [#16247](#16247)

- [backend/diy] Rewrite DeletedWith references when renaming stacks
  [#16216](#16216)

- [cli/state] Fix state renames involving DeletedWith

- [sdk/python] Use a separate type variable for static methods on Output
  [#16172](#16172)

- [sdk/python] Relax Output.all types to better match the implementation
  [#16172](#16172)

- [sdkgen/python] Generate __init__.py files for modules that only
contain enumerations
  [#16229](#16229)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants