Skip to content

Commit

Permalink
Prevent the provider from panicking if referenced secrets for spec.fo…
Browse files Browse the repository at this point in the history
…rProvider.apnsCredential.tokenSecretRef or

spec.forProvider.gcmCredential.apiKeySecretRef of NotificationHub.notificationhubs are not found.

Signed-off-by: Alper Rifat Ulucinar <[email protected]>
  • Loading branch information
ulucinar committed May 27, 2024
1 parent 6c130a1 commit d065e1c
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions config/notificationhubs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,43 @@
package notificationhubs

import (
"strings"

"github.com/crossplane/upjet/pkg/config"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

// Configure configures notificationhubs group
func Configure(p *config.Provider) {
p.AddResourceConfigurator("azurerm_notification_hub", func(r *config.Resource) {
r.Kind = "NotificationHub"
r.TerraformCustomDiff = func(diff *terraform.InstanceDiff, _ *terraform.InstanceState, _ *terraform.ResourceConfig) (*terraform.InstanceDiff, error) {
if diff == nil {
return diff, nil
}
remove := func(prefix string) bool {
for k := range diff.Attributes {
if strings.HasPrefix(k, prefix+".") && k != prefix+".#" {
return false
}
}
return true
}
// the underlying Terraform resource implementation currently fails
// if empty credentials are provided. And in order not to block
// MR deletions when the referenced secret is deleted before
// the MR, upjet passes empty credentials if the referenced
// secret it not found. These are workarounds to prevent the
// provider from panicking if the referenced credentials
// secret is not found.
if remove("gcm_credential") {
delete(diff.Attributes, "gcm_credential.#")
}
if remove("apns_credential") {
delete(diff.Attributes, "apns_credential.#")
}
return diff, nil
}
})

p.AddResourceConfigurator("azurerm_notification_hub_namespace", func(r *config.Resource) {
Expand Down

0 comments on commit d065e1c

Please sign in to comment.