Skip to content

Commit

Permalink
Merge pull request #41539 from hashicorp/td-rename-calculate-calculat…
Browse files Browse the repository at this point in the history
…ediff

autoflex: Rename Calculate to Diff
  • Loading branch information
YakDriver authored Feb 25, 2025
2 parents ccb8c9c + 9b1e761 commit 6cf413a
Show file tree
Hide file tree
Showing 17 changed files with 25 additions and 23 deletions.
4 changes: 2 additions & 2 deletions internal/framework/flex/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func (r *Results) IgnoredFieldNames() []string {
return r.ignoredFieldNames
}

// Calculate compares the plan and state values and returns whether there are changes
func Calculate(ctx context.Context, plan, state any, options ...ChangeOption) (*Results, diag.Diagnostics) {
// Diff compares the plan and state values and returns whether there are changes
func Diff(ctx context.Context, plan, state any, options ...ChangeOption) (*Results, diag.Diagnostics) {
var diags diag.Diagnostics
opts := NewChangeOptions(options...)

Expand Down
4 changes: 2 additions & 2 deletions internal/framework/flex/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestCalculate(t *testing.T) {
t.Run(name, func(t *testing.T) {
t.Parallel()

results, diags := fwflex.Calculate(context.Background(), test.plan, test.state)
results, diags := fwflex.Diff(context.Background(), test.plan, test.state)

if diff := cmp.Diff(diags.HasError(), test.expectErr); diff != "" {
t.Fatalf("unexpected diff (+wanted, -got): %s", diff)
Expand Down Expand Up @@ -129,7 +129,7 @@ func TestWithException(t *testing.T) {
t.Run(name, func(t *testing.T) {
t.Parallel()

results, _ := fwflex.Calculate(context.Background(), test.plan, test.state, test.withException...)
results, _ := fwflex.Diff(context.Background(), test.plan, test.state, test.withException...)

if diff := cmp.Diff(results.IgnoredFieldNames(), test.expectedIgnoredFieldNames); diff != "" {
t.Errorf("unexpected diff (+wanted, -got): %s", diff)
Expand Down
2 changes: 1 addition & 1 deletion internal/service/apigateway/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (r *resourceAccount) Update(ctx context.Context, request resource.UpdateReq
return
}

diff, d := flex.Calculate(ctx, plan, state)
diff, d := flex.Diff(ctx, plan, state)
response.Diagnostics.Append(d...)
if response.Diagnostics.HasError() {
return
Expand Down
2 changes: 1 addition & 1 deletion internal/service/chatbot/slack_channel_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (r *slackChannelConfigurationResource) Update(ctx context.Context, request

conn := r.Meta().ChatbotClient(ctx)

diff, d := fwflex.Calculate(ctx, new, old)
diff, d := fwflex.Diff(ctx, new, old)
response.Diagnostics.Append(d...)
if response.Diagnostics.HasError() {
return
Expand Down
2 changes: 1 addition & 1 deletion internal/service/chatbot/teams_channel_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (r *teamsChannelConfigurationResource) Update(ctx context.Context, request

conn := r.Meta().ChatbotClient(ctx)

diff, d := fwflex.Calculate(ctx, new, old)
diff, d := fwflex.Diff(ctx, new, old)
response.Diagnostics.Append(d...)
if response.Diagnostics.HasError() {
return
Expand Down
2 changes: 1 addition & 1 deletion internal/service/cleanrooms/membership.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func (r *resourceMembership) Update(ctx context.Context, request resource.Update
return
}

diff, d := fwflex.Calculate(ctx, plan, state)
diff, d := fwflex.Diff(ctx, plan, state)
response.Diagnostics.Append(d...)
if response.Diagnostics.HasError() {
return
Expand Down
2 changes: 1 addition & 1 deletion internal/service/datazone/user_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (r *resourceUserProfile) Update(ctx context.Context, req resource.UpdateReq
return
}

diff, d := flex.Calculate(ctx, plan, state)
diff, d := flex.Diff(ctx, plan, state)
resp.Diagnostics.Append(d...)
if resp.Diagnostics.HasError() {
return
Expand Down
2 changes: 1 addition & 1 deletion internal/service/docdbelastic/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (r *resourceCluster) Update(ctx context.Context, request resource.UpdateReq
return
}

diff, d := fwflex.Calculate(ctx, plan, state)
diff, d := fwflex.Diff(ctx, plan, state)
response.Diagnostics.Append(d...)
if response.Diagnostics.HasError() {
return
Expand Down
2 changes: 1 addition & 1 deletion internal/service/elasticache/serverless_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func (r *serverlessCacheResource) Update(ctx context.Context, request resource.U

conn := r.Meta().ElastiCacheClient(ctx)

diff, d := fwflex.Calculate(ctx, new, old)
diff, d := fwflex.Diff(ctx, new, old)
response.Diagnostics.Append(d...)
if response.Diagnostics.HasError() {
return
Expand Down
2 changes: 1 addition & 1 deletion internal/service/logs/anomaly_detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (r *anomalyDetectorResource) Update(ctx context.Context, request resource.U

conn := r.Meta().LogsClient(ctx)

diff, d := fwflex.Calculate(ctx, new, old)
diff, d := fwflex.Diff(ctx, new, old)
response.Diagnostics.Append(d...)
if response.Diagnostics.HasError() {
return
Expand Down
2 changes: 1 addition & 1 deletion internal/service/medialive/multiplex_program.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func (m *multiplexProgram) Update(ctx context.Context, req resource.UpdateReques
return
}

diff, d := fwflex.Calculate(ctx, plan, state)
diff, d := fwflex.Diff(ctx, plan, state)
resp.Diagnostics.Append(d...)
if resp.Diagnostics.HasError() {
return
Expand Down
2 changes: 1 addition & 1 deletion internal/service/mediapackagev2/channel_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (r *resourceChannelGroup) Update(ctx context.Context, request resource.Upda
return
}

diff, d := fwflex.Calculate(ctx, plan, state)
diff, d := fwflex.Diff(ctx, plan, state)
response.Diagnostics.Append(d...)
if response.Diagnostics.HasError() {
return
Expand Down
2 changes: 1 addition & 1 deletion internal/service/opensearchserverless/security_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func (r *resourceSecurityConfig) Update(ctx context.Context, req resource.Update
return
}

diff, diags := fwflex.Calculate(ctx, plan, state)
diff, diags := fwflex.Diff(ctx, plan, state)
if diags.HasError() {
resp.Diagnostics.Append(diags...)
return
Expand Down
2 changes: 1 addition & 1 deletion internal/service/opensearchserverless/security_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (r *resourceSecurityPolicy) Update(ctx context.Context, req resource.Update
return
}

diff, diags := flex.Calculate(ctx, plan, state)
diff, diags := flex.Diff(ctx, plan, state)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
Expand Down
2 changes: 1 addition & 1 deletion internal/service/resiliencehub/resiliency_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func (r *resourceResiliencyPolicy) Update(ctx context.Context, req resource.Upda
return
}

diff, d := flex.Calculate(ctx, plan, state)
diff, d := flex.Diff(ctx, plan, state)
resp.Diagnostics.Append(d...)
if resp.Diagnostics.HasError() {
return
Expand Down
2 changes: 1 addition & 1 deletion internal/service/timestreamquery/scheduled_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ func (r *resourceScheduledQuery) Update(ctx context.Context, req resource.Update
return
}

diff, d := flex.Calculate(ctx, plan, state)
diff, d := flex.Diff(ctx, plan, state)
resp.Diagnostics.Append(d...)
if resp.Diagnostics.HasError() {
return
Expand Down
12 changes: 7 additions & 5 deletions skaff/resource/resourcefw.gtpl
Original file line number Diff line number Diff line change
Expand Up @@ -423,13 +423,15 @@ func (r *resource{{ .Resource }}) Update(ctx context.Context, req resource.Updat
return
}
{{ if .IncludeComments }}
// TIP: -- 3. Populate a modify input structure and check for changes
// TIP: -- 3. Get the difference between the plan and state, if any
{{- end }}
if !plan.Name.Equal(state.Name) ||
!plan.Description.Equal(state.Description) ||
!plan.ComplexArgument.Equal(state.ComplexArgument) ||
!plan.Type.Equal(state.Type) {
diff, d := flex.Diff(ctx, plan, state)
resp.Diagnostics.Append(d...)
if resp.Diagnostics.HasError() {
return
}

if diff.HasChanges() {
var input {{ .SDKPackage }}.Update{{ .Resource }}Input
resp.Diagnostics.Append(flex.Expand(ctx, plan, &input, flex.WithFieldNamePrefix("Test"))...)
if resp.Diagnostics.HasError() {
Expand Down

0 comments on commit 6cf413a

Please sign in to comment.