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

Ensure all sdkv2 test providers have an id and an update method #2723

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion pkg/internal/tests/pulcheck/pulcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func propNeedsUpdate(prop *schema.Schema) bool {
return true
}

// resourceNeedsUpdate returns true if the TF SDK schema validation would consider the
// resource to need an update method.
func resourceNeedsUpdate(res *schema.Resource) bool {
// If any of the properties need an update, then the resource needs an update.
for _, s := range res.Schema {
Expand All @@ -53,6 +55,26 @@ func resourceNeedsUpdate(res *schema.Resource) bool {
// This is an experimental API.
func EnsureProviderValid(t T, tfp *schema.Provider) {
for _, r := range tfp.ResourcesMap {
if r.Schema["id"] == nil {
r.Schema["id"] = &schema.Schema{
Type: schema.TypeString,
Computed: true,
}
}

// If the resource will be flagged as not needing an Update method by the TF SDK schema
// validation then add a no-op update_prop property that will instead force the resource
// to need an Update method.
// This is necessary to work around a bug in the TF SDK schema validation where some resources which
// do need an Update method will instead be flagged as not needing an Update method.
// See https://github.com/pulumi/pulumi-terraform-bridge/pull/2723#issuecomment-2541518646
if !resourceNeedsUpdate(r) {
r.Schema["update_prop"] = &schema.Schema{
Type: schema.TypeString,
Optional: true,
}
}

if r.ReadContext == nil {
r.ReadContext = func(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
return nil
Expand All @@ -75,7 +97,9 @@ func EnsureProviderValid(t T, tfp *schema.Provider) {
}
}

if resourceNeedsUpdate(r) && r.UpdateContext == nil {
// Because of the no-op update_prop property added above, all resources will now
// need an Update method.
if r.UpdateContext == nil {
r.UpdateContext = func(
ctx context.Context, rd *schema.ResourceData, i interface{},
) diag.Diagnostics {
Expand Down
Loading