Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions mmv1/api/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@ type Resource struct {
// control if a resource is continuously generated from public OpenAPI docs
AutogenStatus string `yaml:"autogen_status"`

// If true, this resource generates with the new plugin framework resource template
FrameworkResource bool `yaml:"plugin_framework,omitempty"`

// The three groups of []*Type fields are expected to be strictly ordered within a yaml file
// in the sequence of Virtual Fields -> Parameters -> Properties

Expand Down
48 changes: 48 additions & 0 deletions mmv1/api/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,15 @@ func (t Type) ResourceType() string {
return path[len(path)-1]
}

func (t Type) FWResourceType() string {
r := t.ResourceRef()
if r == nil {
return ""
}
path := strings.Split(r.BaseUrl, "/")
return path[len(path)-1]
}

// TODO rewrite: validation
// func (t *Type) check_default_value_property() {
// return if @default_value.nil?
Expand Down Expand Up @@ -785,6 +794,45 @@ func (t Type) TFType(s string) string {
return "schema.TypeString"
}

func (t Type) GetFWType() string {
switch t.Type {
case "Boolean":
return "Bool"
case "Double":
return "Float64"
case "Integer":
return "Int64"
case "String":
return "String"
case "Time":
return "String"
case "Enum":
return "String"
case "ResourceRef":
return "String"
case "NestedObject":
return "Nested"
case "Array":
return "List"
case "KeyValuePairs":
return "Map"
case "KeyValueLabels":
return "Map"
case "KeyValueTerraformLabels":
return "Map"
case "KeyValueEffectiveLabels":
return "Map"
case "KeyValueAnnotations":
return "Map"
case "Map":
return "Map"
case "Fingerprint":
return "String"
}

return "String"
}

// TODO rewrite: validation
// // Represents an enum, and store is valid values
// class Enum < Primitive
Expand Down
9 changes: 9 additions & 0 deletions mmv1/provider/template_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ func (td *TemplateData) GenerateResourceFile(filePath string, resource api.Resou
td.GenerateFile(filePath, templatePath, resource, true, templates...)
}

func (td *TemplateData) GenerateFWResourceFile(filePath string, resource api.Resource) {
templatePath := "templates/terraform/resource_fw.go.tmpl"
templates := []string{
templatePath,
"templates/terraform/schema_property_fw.go.tmpl",
}
td.GenerateFile(filePath, templatePath, resource, true, templates...)
}

func (td *TemplateData) GenerateMetadataFile(filePath string, resource api.Resource) {
templatePath := "templates/terraform/metadata.yaml.tmpl"
templates := []string{
Expand Down
9 changes: 7 additions & 2 deletions mmv1/provider/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,13 @@ func (t *Terraform) GenerateResource(object api.Resource, templateData TemplateD
if err := os.MkdirAll(targetFolder, os.ModePerm); err != nil {
log.Println(fmt.Errorf("error creating parent directory %v: %v", targetFolder, err))
}
targetFilePath := path.Join(targetFolder, fmt.Sprintf("resource_%s.go", t.ResourceGoFilename(object)))
templateData.GenerateResourceFile(targetFilePath, object)
if object.FrameworkResource {
targetFilePath := path.Join(targetFolder, fmt.Sprintf("resource_fw_%s.go", t.ResourceGoFilename(object)))
templateData.GenerateFWResourceFile(targetFilePath, object)
} else {
targetFilePath := path.Join(targetFolder, fmt.Sprintf("resource_%s.go", t.ResourceGoFilename(object)))
templateData.GenerateResourceFile(targetFilePath, object)
}
}

if generateDocs {
Expand Down
Loading