Skip to content

Commit 935015a

Browse files
committed
Rewrite provider in Go
1 parent 99cb45a commit 935015a

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

mmv1/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ func setProvider(forceProvider, version string, productApi *api.Product, startTi
331331
return provider.NewTerraformGoogleConversionV6(productApi, version, startTime)
332332
case "oics":
333333
return provider.NewTerraformOiCS(productApi, version, startTime)
334+
case "tflint":
335+
return provider.NewTFLint(productApi, version, startTime)
334336
default:
335337
return provider.NewTerraform(productApi, version, startTime)
336338
}

mmv1/provider/tflint.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package provider
2+
3+
import (
4+
"fmt"
5+
"path"
6+
"time"
7+
8+
"github.com/GoogleCloudPlatform/magic-modules/mmv1/api"
9+
"github.com/GoogleCloudPlatform/magic-modules/mmv1/google"
10+
)
11+
12+
type TFLint struct {
13+
Terraform
14+
}
15+
16+
func NewTFLint(product *api.Product, versionName string, startTime time.Time) TFLint {
17+
return TFLint{
18+
Terraform: NewTerraform(product, versionName, startTime),
19+
}
20+
}
21+
22+
func (t *TFLint) GenerateResource(object api.Resource, templateData TemplateData, outputFolder string, generateCode, generateDocs bool) {
23+
terraformName := object.LegacyName
24+
if terraformName == "" {
25+
terraformName = t.FullResourceName(object)
26+
}
27+
28+
for _, prop := range object.AllUserProperties() {
29+
if prop.Output {
30+
continue
31+
}
32+
if len(prop.EnumValues) == 0 && prop.Validation.Regex == "" {
33+
continue
34+
}
35+
36+
ruleName := fmt.Sprintf("%s_invalid_%s", terraformName, google.Underscore(prop.Name))
37+
targetFilePath := path.Join(outputFolder, fmt.Sprintf("%s.go", ruleName))
38+
39+
templateData.GenerateFile(targetFilePath, "templates/tflint/rule.go.tmpl", object, true)
40+
}
41+
}
42+
43+
func (t *TFLint) CopyCommonFiles(outputFolder string, generateCode, generateDocs bool) {
44+
}
45+
46+
func (t *TFLint) CompileCommonFiles(outputFolder string, products []*api.Product, overridePath string) {
47+
}

0 commit comments

Comments
 (0)