From 59ac05cde4763d838efbf0313635d0e19b6d3612 Mon Sep 17 00:00:00 2001 From: Joyce Ma Date: Thu, 19 Sep 2024 02:07:38 +0000 Subject: [PATCH] Set default values to immutable and optional spec fields for certain kinds --- pkg/krmtotf/krmtotf.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pkg/krmtotf/krmtotf.go b/pkg/krmtotf/krmtotf.go index ba60c22168..10d51468cb 100644 --- a/pkg/krmtotf/krmtotf.go +++ b/pkg/krmtotf/krmtotf.go @@ -124,6 +124,25 @@ func KRMResourceToTFResourceConfigFull(r *Resource, c client.Client, smLoader *s if err != nil { return nil, nil, fmt.Errorf("error running custom flatteners: %w", err) } + // Set desired state with default values. + defaultingMap := map[string]map[string]string{ + "CloudBuildTrigger": { + "location": "global", + }, + "CloudIdentityGroup": { + "initialGroupConfig": "EMPTY", + }, + "FirestoreIndex": { + "database": "(default)", + }, + } + if defaults, ok := defaultingMap[r.Kind]; ok { + for field, value := range defaults { + if v, ok := config[field]; !ok || v == "" { + config[field] = value + } + } + } state := InstanceStateToMap(r.TFResource, liveState) config, err = withResourceCustomResolvers(config, state, r.Kind, r.TFResource) if err != nil {