Skip to content

Commit

Permalink
add generic rename processor for fields
Browse files Browse the repository at this point in the history
  • Loading branch information
stephybun committed Nov 28, 2023
1 parent b26a553 commit 13e8755
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package processors

import (
"github.com/hashicorp/go-azure-helpers/lang/pointer"
"strings"
)

var _ FieldNameProcessor = fieldNameGenericRename{}

type fieldNameGenericRename struct{}

func (fieldNameGenericRename) ProcessField(fieldName string, metadata FieldMetadata) (*string, error) {
// some simple and flat resources that should be easily generated are blocked because of property names
// that don't follow the naming guidelines we have in the provider. This field processor is a temporary
// means of renaming fields to enable generation of the resource but may want some modifying in future
// e.g. specifying name overrides in the terraform resource configuration (like in devcenter.hcl) instead
// of being hard-coded here

if strings.EqualFold(metadata.TerraformDetails.ResourceName, "dev_center_gallery") {
if strings.EqualFold(strings.ToLower(fieldName), "galleryResourceId") {
return pointer.To("sharedGalleryId"), nil
}
}

return nil, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var NamingRules = []FieldNameProcessor{
fieldNameRenameBoolean{},
fieldNameRenameMislabelledResourceID{},
fieldNameMaxToMaximum{},
fieldNameGenericRename{},
}

//TODO: if it's a List[Reference] and the model contains a single field `Id` then flatten this into `_ids`.
Expand Down

0 comments on commit 13e8755

Please sign in to comment.