diff --git a/pkg/config/common.go b/pkg/config/common.go index 132c6709..56838e15 100644 --- a/pkg/config/common.go +++ b/pkg/config/common.go @@ -124,11 +124,16 @@ func MoveToStatus(sch *schema.Resource, fieldpaths ...string) { } } +func (r *Resource) MarkAsRequired(fieldpaths ...string) { + r.requiredFields = append(r.requiredFields, fieldpaths...) +} + // MarkAsRequired marks the schema of the given fieldpath as required. It's most // useful in cases where external name contains an optional parameter that is // defaulted by the provider but we need it to exist or to fix plain buggy // schemas. -// Deprecated: Use RequiredFields API instead. +// Deprecated: Use Resource.MarkAsRequired instead. +// This function will be removed in future versions. func MarkAsRequired(sch *schema.Resource, fieldpaths ...string) { for _, fieldpath := range fieldpaths { if s := GetSchema(sch, fieldpath); s != nil { diff --git a/pkg/config/resource.go b/pkg/config/resource.go index bfe6b746..160ca70f 100644 --- a/pkg/config/resource.go +++ b/pkg/config/resource.go @@ -162,10 +162,6 @@ type ExternalName struct { // management policy is including the Observe Only, different from other // (required) fields. IdentifierFields []string - - // RequiredFields are the fields that are marked as required, although - // it is not required in the TF schema. - RequiredFields []string } // References represents reference resolver configurations for the fields of a @@ -493,6 +489,14 @@ type Resource struct { // the value of the generated Kind, for example: // "TagParameters": "ClusterTagParameters" OverrideFieldNames map[string]string + + // requiredFields are the fields that will be marked as required in the + // generated CRD schema, although they are not required in the TF schema. + requiredFields []string +} + +func (r *Resource) RequiredFields() []string { + return r.requiredFields } // ShouldUseTerraformPluginSDKClient returns whether to generate an SDKv2-based diff --git a/pkg/types/field.go b/pkg/types/field.go index 8e74de97..61e2afae 100644 --- a/pkg/types/field.go +++ b/pkg/types/field.go @@ -121,7 +121,7 @@ func NewField(g *Builder, cfg *config.Resource, r *resource, sch *schema.Schema, } } - for _, required := range cfg.ExternalName.RequiredFields { + for _, required := range cfg.RequiredFields() { if required == snakeFieldName { f.Required = true }