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

fix Secret/secretmanager.aws custom diff logic when replica config is empty #1144

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
14 changes: 13 additions & 1 deletion config/secretsmanager/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,25 @@ func Configure(p *config.Provider) { //nolint:gocyclo
return diff, nil
}

resData, err := schema.InternalMap(r.TerraformResource.SchemaMap()).Data(state, diff)
if err != nil {
return nil, errors.New("could not construct resource data")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this really something we want to fail the whole observe loop for? I don't fully understand when this could happen, so I don't know how bad it is.

Copy link
Collaborator Author

@erhancagirici erhancagirici Feb 15, 2024

Choose a reason for hiding this comment

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

under "normal" operation this should never return an error. An error here indicates an issue with the resource schema or the produced state. More specifically, this is a very fundamental statement and the same line is also run by the terraform SDK library already in earlier stages of observe, so any error should be already emitted if any before visiting the custom diff function.So, IMHO it is OK to fail the whole observe here

}

// do not customize diff if replica field has no change
if !resData.HasChange("replica") {
return diff, nil
}
currentReplicaSet, ok := r.TerraformResource.Data(state).Get("replica").(*schema.Set)
if !ok {
return nil, errors.New("could not read \"replica\" from state")
}

nisReplica, ok := config.Get("replica")
if !ok {
return nil, errors.New("could not read replica block from config")
// config is empty for replica, no need for custom diff logic
// this is already handled correctly with the built-in diff logic
return diff, nil
}
desiredReplicaList := nisReplica.([]interface{})
// this is the hash implementation of *schema.Set, which is unexported
Expand Down
2 changes: 2 additions & 0 deletions examples/secretsmanager/v1beta1/secret-withreplica.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ metadata:
name: example-withreplica
annotations:
meta.upbound.io/example-id: secretsmanager/v1beta1/secret
uptest.upbound.io/update-parameter: '{"tags":{"updated-by":"crossplane"}}'
labels:
testing.upbound.io/example-name: secretsmanager
spec:
forProvider:
name: example-withreplica-${Rand.RFC1123Subdomain}
recoveryWindowInDays: 0
region: us-west-1
replica:
- region: us-west-2
2 changes: 2 additions & 0 deletions examples/secretsmanager/v1beta1/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ metadata:
name: example
annotations:
meta.upbound.io/example-id: secretsmanager/v1beta1/secret
uptest.upbound.io/update-parameter: '{"tags":{"updated-by":"crossplane"}}'
labels:
testing.upbound.io/example-name: secretsmanager
spec:
forProvider:
name: example-${Rand.RFC1123Subdomain}
region: us-west-1
recoveryWindowInDays: 0
Loading