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

Add a new configuration option for required field generation #381

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions pkg/config/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func MoveToStatus(sch *schema.Resource, fieldpaths ...string) {
// 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.
func MarkAsRequired(sch *schema.Resource, fieldpaths ...string) {
for _, fieldpath := range fieldpaths {
if s := GetSchema(sch, fieldpath); s != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/config/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ 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.
sergenyalcin marked this conversation as resolved.
Show resolved Hide resolved
RequiredFields []string
sergenyalcin marked this conversation as resolved.
Show resolved Hide resolved
}

// References represents reference resolver configurations for the fields of a
Expand Down
3 changes: 3 additions & 0 deletions pkg/types/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,9 @@ func newTopLevelRequiredParam(path string, includeInit bool) *topLevelRequiredPa

func (r *resource) addParameterField(f *Field, field *types.Var) {
requiredBySchema := !f.Schema.Optional
if f.Required {
requiredBySchema = f.Required
}
sergenyalcin marked this conversation as resolved.
Show resolved Hide resolved
// Note(turkenh): We are collecting the top level required parameters that
// are not identifier fields. This is for generating CEL validation rules for
// those parameters and not to require them if the management policy is set
Expand Down
7 changes: 7 additions & 0 deletions pkg/types/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type Field struct {
TransformedName string
SelectorName string
Identifier bool
Required bool
// Injected is set if this Field is an injected field to the Terraform
// schema as an object list map key for server-side apply merges.
Injected bool
Expand Down Expand Up @@ -120,6 +121,12 @@ func NewField(g *Builder, cfg *config.Resource, r *resource, sch *schema.Schema,
}
}

for _, required := range cfg.ExternalName.RequiredFields {
if required == snakeFieldName {
f.Required = true
}
}

var commentText string
docString := getDocString(cfg, f, tfPath)
if len(docString) > 0 {
Expand Down
Loading