Skip to content

Commit

Permalink
Add a new `Required configuration option
Browse files Browse the repository at this point in the history
Signed-off-by: Sergen Yalçın <yalcinsergen97@gmail.com>
  • Loading branch information
sergenyalcin committed Mar 18, 2024
1 parent 2ef7077 commit 811aab6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
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.
RequiredFields []string
}

// 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
}
// 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

0 comments on commit 811aab6

Please sign in to comment.