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

Moving from GetOlds to GetOldInputs to avoid having to manually remove properties #309

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
- Fixed environment tests breaking due to name collision [#296](https://github.com/pulumi/pulumi-pulumiservice/issues/296)

### Miscellaneous

- Migrated all Diff methods to use GetOldInputs instead of GetOlds to avoid manually removing properties [#297](https://github.com/pulumi/pulumi-pulumiservice/issues/297)
2 changes: 1 addition & 1 deletion provider/pkg/internal/serde/property_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func FromPropertyMap(properties resource.PropertyMap, structTagName string, out

// DiffOldsAndNews unmarshals a DiffRequest and runs a diff on them. It returns any keys changed
func DiffOldsAndNews(req *pulumirpc.DiffRequest) ([]string, error) {
olds, err := plugin.UnmarshalProperties(req.GetOlds(), plugin.MarshalOptions{KeepUnknowns: false, SkipNulls: true})
olds, err := plugin.UnmarshalProperties(req.GetOldInputs(), plugin.MarshalOptions{KeepUnknowns: false, SkipNulls: true})
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion provider/pkg/provider/access_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (at *PulumiServiceAccessTokenResource) deleteAccessToken(ctx context.Contex
}

func diffAccessTokenProperties(req *pulumirpc.DiffRequest, replaceProps []string) (*pulumirpc.DiffResponse, error) {
olds, err := plugin.UnmarshalProperties(req.GetOlds(), plugin.MarshalOptions{KeepUnknowns: false, SkipNulls: true})
olds, err := plugin.UnmarshalProperties(req.GetOldInputs(), plugin.MarshalOptions{KeepUnknowns: false, SkipNulls: true})
if err != nil {
return nil, err
}
Expand Down
11 changes: 2 additions & 9 deletions provider/pkg/provider/agent_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,11 @@ func (ap *PulumiServiceAgentPoolResource) Name() string {
}

func (ap *PulumiServiceAgentPoolResource) Diff(req *pulumirpc.DiffRequest) (*pulumirpc.DiffResponse, error) {
olds, err := plugin.UnmarshalProperties(req.GetOlds(), plugin.MarshalOptions{KeepUnknowns: false, SkipNulls: true})
olds, err := plugin.UnmarshalProperties(req.GetOldInputs(), plugin.MarshalOptions{KeepUnknowns: false, SkipNulls: true})
if err != nil {
return nil, err
}

// preprocess olds to remove the `tokenValue & agentPoolId` property since it's only an output and shouldn't cause a diff
for _, p := range []resource.PropertyKey{"tokenValue", "agentPoolId"} {
if olds[p].HasValue() {
delete(olds, p)
}
}

news, err := plugin.UnmarshalProperties(req.GetNews(), plugin.MarshalOptions{KeepUnknowns: true, SkipNulls: true})
if err != nil {
return nil, err
Expand Down Expand Up @@ -167,7 +160,7 @@ func (ap *PulumiServiceAgentPoolResource) Update(req *pulumirpc.UpdateRequest) (
return nil, fmt.Errorf("invalid resource id: %v", err)
}

olds, err := plugin.UnmarshalProperties(req.GetOlds(), plugin.MarshalOptions{KeepUnknowns: true, SkipNulls: true})
olds, err := plugin.UnmarshalProperties(req.GetOldInputs(), plugin.MarshalOptions{KeepUnknowns: true, SkipNulls: true})
if err != nil {
return nil, err
}
Expand Down
7 changes: 1 addition & 6 deletions provider/pkg/provider/deployment_schedules.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func ToPulumiServiceSharedScheduleOutput(properties *structpb.Struct) (*PulumiSe
}

func ScheduleSharedDiff(req *pulumirpc.DiffRequest) (*pulumirpc.DiffResponse, error) {
olds, err := plugin.UnmarshalProperties(req.GetOlds(), plugin.MarshalOptions{KeepUnknowns: false, SkipNulls: true})
olds, err := plugin.UnmarshalProperties(req.GetOldInputs(), plugin.MarshalOptions{KeepUnknowns: false, SkipNulls: true})
if err != nil {
return nil, err
}
Expand All @@ -151,11 +151,6 @@ func ScheduleSharedDiff(req *pulumirpc.DiffRequest) (*pulumirpc.DiffResponse, er
}

func ScheduleSharedDiffMaps(olds resource.PropertyMap, news resource.PropertyMap) (*pulumirpc.DiffResponse, error) {
// preprocess olds to remove the `scheduleId` property since it's only an output and shouldn't cause a diff
if olds["scheduleId"].HasValue() {
delete(olds, "scheduleId")
}

diffs := olds.Diff(news)
if diffs == nil {
return &pulumirpc.DiffResponse{
Expand Down
2 changes: 1 addition & 1 deletion provider/pkg/provider/deployment_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ func getSecretOrStringValue(prop resource.PropertyValue) string {
}

func (ds *PulumiServiceDeploymentSettingsResource) Diff(req *pulumirpc.DiffRequest) (*pulumirpc.DiffResponse, error) {
olds, err := plugin.UnmarshalProperties(req.GetOlds(), plugin.MarshalOptions{KeepUnknowns: true, SkipNulls: true})
olds, err := plugin.UnmarshalProperties(req.GetOldInputs(), plugin.MarshalOptions{KeepUnknowns: true, SkipNulls: true})
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion provider/pkg/provider/drift_schedules.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func ToPulumiServiceDriftScheduleInput(properties *structpb.Struct) (*PulumiServ
}

func (st *PulumiServiceDriftScheduleResource) Diff(req *pulumirpc.DiffRequest) (*pulumirpc.DiffResponse, error) {
olds, err := plugin.UnmarshalProperties(req.GetOlds(), plugin.MarshalOptions{KeepUnknowns: false, SkipNulls: true})
olds, err := plugin.UnmarshalProperties(req.GetOldInputs(), plugin.MarshalOptions{KeepUnknowns: false, SkipNulls: true})
if err != nil {
return nil, err
}
Expand Down
7 changes: 1 addition & 6 deletions provider/pkg/provider/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func ToPulumiServiceEnvironmentInput(properties *structpb.Struct) (*PulumiServic
}

func (st *PulumiServiceEnvironmentResource) Diff(req *pulumirpc.DiffRequest) (*pulumirpc.DiffResponse, error) {
olds, err := plugin.UnmarshalProperties(req.GetOlds(), plugin.MarshalOptions{KeepUnknowns: true, SkipNulls: true})
olds, err := plugin.UnmarshalProperties(req.GetOldInputs(), plugin.MarshalOptions{KeepUnknowns: true, SkipNulls: true})
if err != nil {
return nil, err
}
Expand All @@ -92,11 +92,6 @@ func (st *PulumiServiceEnvironmentResource) Diff(req *pulumirpc.DiffRequest) (*p
return nil, err
}

// preprocess olds to remove the `revision` property since it's only an output and shouldn't cause a diff
if olds["revision"].HasValue() {
delete(olds, "revision")
}

diffs := olds.Diff(news)
if diffs == nil {
return &pulumirpc.DiffResponse{
Expand Down
2 changes: 1 addition & 1 deletion provider/pkg/provider/environment_version_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (evt *PulumiServiceEnvironmentVersionTagResource) Name() string {
}

func (evt *PulumiServiceEnvironmentVersionTagResource) Diff(req *pulumirpc.DiffRequest) (*pulumirpc.DiffResponse, error) {
olds, err := plugin.UnmarshalProperties(req.GetOlds(), plugin.MarshalOptions{KeepUnknowns: false, SkipNulls: true})
olds, err := plugin.UnmarshalProperties(req.GetOldInputs(), plugin.MarshalOptions{KeepUnknowns: false, SkipNulls: true})
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion provider/pkg/provider/stack_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (st *PulumiServiceStackTagResource) Name() string {
}

func (st *PulumiServiceStackTagResource) Diff(req *pulumirpc.DiffRequest) (*pulumirpc.DiffResponse, error) {
olds, err := plugin.UnmarshalProperties(req.GetOlds(), plugin.MarshalOptions{KeepUnknowns: false, SkipNulls: true})
olds, err := plugin.UnmarshalProperties(req.GetOldInputs(), plugin.MarshalOptions{KeepUnknowns: false, SkipNulls: true})
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion provider/pkg/provider/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (t *PulumiServiceTeamResource) Delete(req *pulumirpc.DeleteRequest) (*pbemp
}

func (t *PulumiServiceTeamResource) Diff(req *pulumirpc.DiffRequest) (*pulumirpc.DiffResponse, error) {
olds, err := plugin.UnmarshalProperties(req.GetOlds(), plugin.MarshalOptions{KeepUnknowns: false, SkipNulls: true})
olds, err := plugin.UnmarshalProperties(req.GetOldInputs(), plugin.MarshalOptions{KeepUnknowns: false, SkipNulls: true})
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion provider/pkg/provider/ttl_schedules.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func ToPulumiServiceTtlScheduleInput(properties *structpb.Struct) (*PulumiServic
}

func (st *PulumiServiceTtlScheduleResource) Diff(req *pulumirpc.DiffRequest) (*pulumirpc.DiffResponse, error) {
olds, err := plugin.UnmarshalProperties(req.GetOlds(), plugin.MarshalOptions{KeepUnknowns: false, SkipNulls: true})
olds, err := plugin.UnmarshalProperties(req.GetOldInputs(), plugin.MarshalOptions{KeepUnknowns: false, SkipNulls: true})
if err != nil {
return nil, err
}
Expand Down
7 changes: 1 addition & 6 deletions provider/pkg/provider/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,16 +246,11 @@ func (wh *PulumiServiceWebhookResource) createWebhook(input PulumiServiceWebhook
}

func (wh *PulumiServiceWebhookResource) Diff(req *pulumirpc.DiffRequest) (*pulumirpc.DiffResponse, error) {
olds, err := plugin.UnmarshalProperties(req.GetOlds(), plugin.MarshalOptions{KeepUnknowns: false, SkipNulls: true})
olds, err := plugin.UnmarshalProperties(req.GetOldInputs(), plugin.MarshalOptions{KeepUnknowns: false, SkipNulls: true})
if err != nil {
return nil, err
}

// preprocess olds to remove the `name` property since it's only an output and shouldn't cause a diff
if olds["name"].HasValue() {
delete(olds, "name")
}

news, err := plugin.UnmarshalProperties(req.GetNews(), plugin.MarshalOptions{KeepUnknowns: true, SkipNulls: true})
if err != nil {
return nil, err
Expand Down
Loading