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

Diff tests for sdkv2 #2158

Merged
merged 11 commits into from
Jul 17, 2024
Merged

Diff tests for sdkv2 #2158

merged 11 commits into from
Jul 17, 2024

Conversation

VenelinMartinov
Copy link
Contributor

@VenelinMartinov VenelinMartinov commented Jul 3, 2024

This refactors the existing diff tests to work for both sdkv1 and sdkv2 - they were previously v1 only.

To do that I've added a schemaconvert module which takes a v2 schema and converts it to a v1 schema.

Copy link

codecov bot commented Jul 3, 2024

Codecov Report

Attention: Patch coverage is 71.87500% with 27 lines in your changes missing coverage. Please review.

Project coverage is 60.74%. Comparing base (7ce57cb) to head (cbda64a).
Report is 2 commits behind head on master.

Files Patch % Lines
...ridge/internal/test/schemaconvert/schemaconvert.go 71.87% 22 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2158      +/-   ##
==========================================
+ Coverage   60.65%   60.74%   +0.09%     
==========================================
  Files         350      351       +1     
  Lines       45930    46026      +96     
==========================================
+ Hits        27857    27958     +101     
+ Misses      16533    16520      -13     
- Partials     1540     1548       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

pkg/tfbridge/internal/schemaconvert/schemaconvert.go Outdated Show resolved Hide resolved
pkg/tfbridge/internal/schemaconvert/schemaconvert.go Outdated Show resolved Hide resolved
pkg/tfbridge/internal/schemaconvert/schemaconvert.go Outdated Show resolved Hide resolved
pkg/tfbridge/internal/schemaconvert/schemaconvert.go Outdated Show resolved Hide resolved
pkg/tfbridge/internal/schemaconvert/schemaconvert.go Outdated Show resolved Hide resolved
pkg/tfbridge/internal/schemaconvert/schemaconvert.go Outdated Show resolved Hide resolved
pkg/tfbridge/internal/schemaconvert/schemaconvert.go Outdated Show resolved Hide resolved
@VenelinMartinov
Copy link
Contributor Author

GH rate limits ❤️

@t0yv0
Copy link
Member

t0yv0 commented Jul 16, 2024

I didn't review in detail but this is much needed! 🙇

LMK If you need a detailed review from me.

@VenelinMartinov VenelinMartinov enabled auto-merge (squash) July 17, 2024 09:47
@VenelinMartinov VenelinMartinov merged commit 4ae2ad6 into master Jul 17, 2024
11 checks passed
@VenelinMartinov VenelinMartinov deleted the vvm/diff_tests_for_sdkv2 branch July 17, 2024 10:09
@pulumi-bot
Copy link
Contributor

This PR has been shipped in release v3.87.0.

VenelinMartinov added a commit that referenced this pull request Jul 17, 2024
This changes the bridge to correctly return unknowns for objects and
collections in sdkv2.

fixes #1885
fixes #2032

stacked on #2158

Confirmed that TF sdkv2 supports both unknown blocks and unknown
collections of blocks, so we should be fine to pass these into TF
providers.

The TF sdkv1 does not support unknowns for blocks and collections so we
keep the old behaviour of passing empty/ collection of unknown.

<details>

```hcl
provider "google" {
  region       = "us-central1"
}

resource "google_storage_bucket" "bucket" {
  name     = "example-bucket12312322312"
  location = "US"
}

resource "google_storage_bucket" "bucket1" {
  name     = "example-bucket123123223"
  location = "US"
  dynamic "lifecycle_rule" {
    for_each = google_storage_bucket.bucket.effective_labels
    content {
      action {
        type = lifecycle_rule.value
      }
      condition {
        age = 1
      }
    }
  }
}
```

</details>


This returns `"lifecycle_rule":cty.UnknownVal(cty.List(cty.Object))`


Our handling of collections containing unknowns and unknown collections
is significantly better:

Unknown collections:
before:

```
+ prov:index/test:Test: (create)
  [urn=urn:pulumi:test::test::prov:index/test:Test::mainRes]
  tests     : [
      [0]: {}
  ]
```

after:

```
+ prov:index/test:Test: (create)
  [urn=urn:pulumi:test::test::prov:index/test:Test::mainRes]
  tests     : output<string>
```

Note that the array being output as an `output<string>` is an engine
limitation.

Nested unknown collections:
before:

```
+ prov:index/nestedTest:NestedTest: (create)
  [urn=urn:pulumi:test::test::prov:index/nestedTest:NestedTest::mainRes]
  tests     : [
      [0]: {
          nestedProps: [
              [0]: {
                  testProps : [
                      [0]: output<string>
                  ]
              }
          ]
      }
  ]
```

after:

```
+ prov:index/nestedTest:NestedTest: (create)
    [urn=urn:pulumi:test::test::prov:index/nestedTest:NestedTest::mainRes]
    tests     : [
        [0]: {
            nestedProps: [
                [0]: {
                    testProps : output<string>
                }
            ]
        }
    ]
```

The unknown was being put one level lower than it should be.

Quite a few other very wrong outputs in
#2140, including
diff duplications, missing diffs etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants