Skip to content

Commit fd62c38

Browse files
c2thornNickElliotshuyama1paridhishah18wyardley
authored
Plugin Framework feature branch merge (#14977)
Signed-off-by: drfaust92 <[email protected]> Signed-off-by: Cezary Sobczak <[email protected]> Signed-off-by: James Alseth <[email protected]> Signed-off-by: Misha Efimov <[email protected]> Co-authored-by: Nick Elliot <[email protected]> Co-authored-by: Shuya Ma <[email protected]> Co-authored-by: paridhishah18 <[email protected]> Co-authored-by: William Yardley <[email protected]> Co-authored-by: Stephen Lewis (Burrows) <[email protected]> Co-authored-by: shantstepanian <[email protected]> Co-authored-by: Zhenhua Li <[email protected]> Co-authored-by: Yanwei Guo <[email protected]> Co-authored-by: Scott Suarez <[email protected]> Co-authored-by: skysarthak <[email protected]> Co-authored-by: Sarthak Tandon <[email protected]> Co-authored-by: Ramon Vermeulen <[email protected]> Co-authored-by: bcreddy-gcp <[email protected]> Co-authored-by: Stephen Lewis (Burrows) <[email protected]> Co-authored-by: govardhanitallam <[email protected]> Co-authored-by: xuebaoZ <[email protected]> Co-authored-by: Michael Turgeman <[email protected]> Co-authored-by: gurusai-voleti <[email protected]> Co-authored-by: jkrish-c <[email protected]> Co-authored-by: Wiktor Niesiobędzki <[email protected]> Co-authored-by: dorianverna <[email protected]> Co-authored-by: Andras Kerekes <[email protected]> Co-authored-by: Raj Anand <[email protected]> Co-authored-by: ML <[email protected]> Co-authored-by: Marek Lipert <[email protected]> Co-authored-by: James Cherry <[email protected]> Co-authored-by: Hengfeng Li <[email protected]> Co-authored-by: Jeremie Stordeur <[email protected]> Co-authored-by: abhilashsamgoogle <[email protected]> Co-authored-by: ArtoriaRen <[email protected]> Co-authored-by: Nandini Agrawal <[email protected]> Co-authored-by: Aiden Grossman <[email protected]> Co-authored-by: Rohan Chawla <[email protected]> Co-authored-by: ma-g-22 <[email protected]> Co-authored-by: Rajesh Guptha <[email protected]> Co-authored-by: Parker DeWilde <[email protected]> Co-authored-by: Thomas Rodgers <[email protected]> Co-authored-by: sachin purohit <[email protected]> Co-authored-by: karolgorc <[email protected]> Co-authored-by: Rachel Thornton <[email protected]> Co-authored-by: Alex Morozov <[email protected]> Co-authored-by: Alex Morozov <[email protected]> Co-authored-by: Lingkai Shen <[email protected]> Co-authored-by: Ilia Lazebnik <[email protected]> Co-authored-by: Betto Cerrillos <[email protected]> Co-authored-by: Riley Karson <[email protected]> Co-authored-by: Ron Gal <[email protected]> Co-authored-by: Akshat Jindal <[email protected]> Co-authored-by: Swamita Gupta <[email protected]> Co-authored-by: Bob "Wombat" Hogg <[email protected]> Co-authored-by: hao-nan-li <[email protected]> Co-authored-by: NA2047 <[email protected]> Co-authored-by: sahil-mahajan-google <[email protected]> Co-authored-by: Arpit Gupta <[email protected]> Co-authored-by: ahmed-laiq <[email protected]> Co-authored-by: stevenyang72 <[email protected]> Co-authored-by: Sam Levenick <[email protected]> Co-authored-by: Haoting.C <[email protected]> Co-authored-by: Daniel Dubnikov <[email protected]> Co-authored-by: Pawel Jasinski <[email protected]> Co-authored-by: Sachin_R <[email protected]> Co-authored-by: Cezary Sobczak <[email protected]> Co-authored-by: wj-chen <[email protected]> Co-authored-by: Kian Jones <[email protected]> Co-authored-by: uaditya70 <[email protected]> Co-authored-by: pujawadare <[email protected]> Co-authored-by: Sachin_R <[email protected]> Co-authored-by: Jaylon McShan <[email protected]> Co-authored-by: tulika-aakriti <[email protected]> Co-authored-by: anthonyrtong <[email protected]> Co-authored-by: Chris Hawk <[email protected]> Co-authored-by: Shrishty Chandra <[email protected]> Co-authored-by: Shrishty Chandra <[email protected]> Co-authored-by: Sharan Teja M <[email protected]> Co-authored-by: James Alseth <[email protected]> Co-authored-by: stevenyang72 <[email protected]> Co-authored-by: oferhandel-google <[email protected]> Co-authored-by: Jatin Miglani <[email protected]> Co-authored-by: translucens <[email protected]> Co-authored-by: Sing <[email protected]> Co-authored-by: Ronson Xaviour <[email protected]> Co-authored-by: Ronson Xaviour <[email protected]> Co-authored-by: Iris Chen <[email protected]> Co-authored-by: Or Sela <[email protected]> Co-authored-by: Samir Ribeiro <[email protected]> Co-authored-by: Mauricio Alvarez Leon <[email protected]> Co-authored-by: kigesui <[email protected]> Co-authored-by: Meng Yang <[email protected]> Co-authored-by: Ashwin G <[email protected]> Co-authored-by: Allison Fisher <[email protected]> Co-authored-by: mihhalj <[email protected]> Co-authored-by: Guy Bidkar <[email protected]> Co-authored-by: Dawid212 <[email protected]> Co-authored-by: Michael Lopez <[email protected]> Co-authored-by: kautikdk <[email protected]> Co-authored-by: harshithpatte-g <[email protected]> Co-authored-by: ML <[email protected]> Co-authored-by: James Alseth <[email protected]> Co-authored-by: Madhura Phadnis <[email protected]> Co-authored-by: YashTayal04 <[email protected]> Co-authored-by: Misha Efimov <[email protected]> Co-authored-by: Aiden Grossman <[email protected]> Co-authored-by: MatthewVu-dev <[email protected]> Co-authored-by: Madhu Suraj <[email protected]> Co-authored-by: Matheus Guilherme Souza Aleixo <[email protected]> Co-authored-by: Jun Luo <[email protected]> Co-authored-by: Tommy Reddad <[email protected]>
1 parent 13886db commit fd62c38

File tree

40 files changed

+4190
-911
lines changed

40 files changed

+4190
-911
lines changed

.ci/magician/cmd/test_terraform_vcr.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ func execTestTerraformVCR(prNumber, mmCommitSha, buildID, projectID, buildStep,
237237
}
238238

239239
notRunBeta, notRunGa := notRunTests(tpgRepo.UnifiedZeroDiff, tpgbRepo.UnifiedZeroDiff, replayingResult)
240-
241240
postReplayData := postReplay{
242241
RunFullVCR: runFullVCR,
243242
AffectedServices: sort.StringSlice(servicesArr),

mmv1/api/resource.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,9 @@ type Resource struct {
308308
// control if a resource is continuously generated from public OpenAPI docs
309309
AutogenStatus string `yaml:"autogen_status"`
310310

311+
// If true, this resource generates with the new plugin framework resource template
312+
FrameworkResource bool `yaml:"plugin_framework,omitempty"`
313+
311314
// The three groups of []*Type fields are expected to be strictly ordered within a yaml file
312315
// in the sequence of Virtual Fields -> Parameters -> Properties
313316

mmv1/api/type.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,15 @@ func (t Type) ResourceType() string {
551551
return path[len(path)-1]
552552
}
553553

554+
func (t Type) FWResourceType() string {
555+
r := t.ResourceRef()
556+
if r == nil {
557+
return ""
558+
}
559+
path := strings.Split(r.BaseUrl, "/")
560+
return path[len(path)-1]
561+
}
562+
554563
// TODO rewrite: validation
555564
// func (t *Type) check_default_value_property() {
556565
// return if @default_value.nil?
@@ -821,6 +830,45 @@ func (t Type) TFType(s string) string {
821830
return "schema.TypeString"
822831
}
823832

833+
func (t Type) GetFWType() string {
834+
switch t.Type {
835+
case "Boolean":
836+
return "Bool"
837+
case "Double":
838+
return "Float64"
839+
case "Integer":
840+
return "Int64"
841+
case "String":
842+
return "String"
843+
case "Time":
844+
return "String"
845+
case "Enum":
846+
return "String"
847+
case "ResourceRef":
848+
return "String"
849+
case "NestedObject":
850+
return "Nested"
851+
case "Array":
852+
return "List"
853+
case "KeyValuePairs":
854+
return "Map"
855+
case "KeyValueLabels":
856+
return "Map"
857+
case "KeyValueTerraformLabels":
858+
return "Map"
859+
case "KeyValueEffectiveLabels":
860+
return "Map"
861+
case "KeyValueAnnotations":
862+
return "Map"
863+
case "Map":
864+
return "Map"
865+
case "Fingerprint":
866+
return "String"
867+
}
868+
869+
return "String"
870+
}
871+
824872
// TODO rewrite: validation
825873
// // Represents an enum, and store is valid values
826874
// class Enum < Primitive

mmv1/products/datafusion/Instance.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
---
1515
name: 'Instance'
16+
# plugin_framework: true
1617
description: |
1718
Represents a Data Fusion instance.
1819
references:

mmv1/provider/template_data.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ func (td *TemplateData) GenerateResourceFile(filePath string, resource api.Resou
8585
td.GenerateFile(filePath, templatePath, resource, true, templates...)
8686
}
8787

88+
func (td *TemplateData) GenerateFWResourceFile(filePath string, resource api.Resource) {
89+
templatePath := "templates/terraform/resource_fw.go.tmpl"
90+
templates := []string{
91+
templatePath,
92+
"templates/terraform/schema_property_fw.go.tmpl",
93+
}
94+
td.GenerateFile(filePath, templatePath, resource, true, templates...)
95+
}
96+
8897
func (td *TemplateData) GenerateMetadataFile(filePath string, resource api.Resource) {
8998
templatePath := "templates/terraform/metadata.yaml.tmpl"
9099
templates := []string{

mmv1/provider/terraform.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,13 @@ func (t *Terraform) GenerateResource(object api.Resource, templateData TemplateD
128128
if err := os.MkdirAll(targetFolder, os.ModePerm); err != nil {
129129
log.Println(fmt.Errorf("error creating parent directory %v: %v", targetFolder, err))
130130
}
131-
targetFilePath := path.Join(targetFolder, fmt.Sprintf("resource_%s.go", t.ResourceGoFilename(object)))
132-
templateData.GenerateResourceFile(targetFilePath, object)
131+
if object.FrameworkResource {
132+
targetFilePath := path.Join(targetFolder, fmt.Sprintf("resource_fw_%s.go", t.ResourceGoFilename(object)))
133+
templateData.GenerateFWResourceFile(targetFilePath, object)
134+
} else {
135+
targetFilePath := path.Join(targetFolder, fmt.Sprintf("resource_%s.go", t.ResourceGoFilename(object)))
136+
templateData.GenerateResourceFile(targetFilePath, object)
137+
}
133138
}
134139

135140
if generateDocs {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{{/*
2+
The license inside this block applies to this file
3+
Copyright 2024 Google Inc.
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/ -}}
13+
updateMask := []string{}
14+
15+
if !plan.EnableStackdriverLogging.Equal(state.EnableStackdriverLogging) {
16+
updateMask = append(updateMask, "enableStackdriverLogging")
17+
}
18+
19+
if !plan.EnableStackdriverMonitoring.Equal(state.EnableStackdriverMonitoring) {
20+
updateMask = append(updateMask, "enableStackdriverMonitoring")
21+
}
22+
23+
if !plan.EnableRbac.Equal(state.EnableRbac) {
24+
updateMask = append(updateMask, "enableRbac")
25+
}
26+
27+
28+
// updateMask is a URL parameter but not present in the schema, so ReplaceVars
29+
// won't set it
30+
31+
url, err := transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
32+
if err != nil {
33+
resp.Diagnostics.AddError("Error, failure building update mask query parameters in {{ $.Name -}}", err.Error())
34+
return
35+
}

0 commit comments

Comments
 (0)