Skip to content

Commit 17f70a4

Browse files
committed
Only set Compiler on product
1 parent e57ba91 commit 17f70a4

37 files changed

+58
-71
lines changed

mmv1/api/product.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ type Product struct {
7878
// The compiler to generate the downstream files, for example "terraformgoogleconversion-codegen".
7979
Compiler string `yaml:"-"`
8080

81-
ProviderName string `yaml:"-"`
82-
8381
// ImportPath contains the prefix used for importing packages in generated files.
8482
ImportPath string `yaml:"-"`
8583
}
@@ -147,6 +145,10 @@ func (p *Product) SetCompiler(t string) {
147145
p.Compiler = fmt.Sprintf("%s-codegen", strings.ToLower(t))
148146
}
149147

148+
func (p Product) IsTgcCompiler() bool {
149+
return p.Compiler == "terraformgoogleconversionnext-codegen"
150+
}
151+
150152
// ====================
151153
// Version-related methods
152154
// ====================

mmv1/api/resource.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,6 @@ type Resource struct {
340340
// The version name provided by the user through CI
341341
TargetVersionName string `yaml:"-"`
342342

343-
// The compiler to generate the downstream files, for example "terraformgoogleconversion-codegen".
344-
Compiler string `yaml:"-"`
345-
346343
// The API "resource type kind" used for this resource e.g., "Function".
347344
// If this is not set, then :name is used instead, which is strongly
348345
// preferred wherever possible. Its main purpose is for supporting
@@ -898,7 +895,7 @@ func (r *Resource) addWriteOnlyFields(props []*Type, propWithWoConfigured *Type)
898895
}
899896
// Don't add write only fields to tgc, as write only fields don't exist in tfplan json,
900897
// the input of tfplan2cai.
901-
if !strings.HasPrefix(r.ProductMetadata.ProviderName, "tgc") {
898+
if !r.ProductMetadata.IsTgcCompiler() {
902899
woFieldName := fmt.Sprintf("%sWo", propWithWoConfigured.Name)
903900
woVersionFieldName := fmt.Sprintf("%sVersion", woFieldName)
904901
writeOnlyField := buildWriteOnlyField(woFieldName, woVersionFieldName, propWithWoConfigured)
@@ -1448,10 +1445,6 @@ func ignoreReadFields(props []*Type) []string {
14481445
return fields
14491446
}
14501447

1451-
func (r *Resource) SetCompiler(t string) {
1452-
r.Compiler = fmt.Sprintf("%s-codegen", strings.ToLower(t))
1453-
}
1454-
14551448
// Returns the id format of an object, or self_link_uri if none is explicitly defined
14561449
// We prefer the long name of a resource as the id so that users can reference
14571450
// resources in a standard way, and most APIs accept short name, long name or self_link
@@ -2596,5 +2589,5 @@ func (r Resource) CaiResourceName() string {
25962589
}
25972590

25982591
func (r Resource) IsTgcCompiler() bool {
2599-
return r.Compiler == "terraformgoogleconversionnext-codegen"
2592+
return r.ProductMetadata.Compiler == "terraformgoogleconversionnext-codegen"
26002593
}

mmv1/api/resource_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,13 +399,14 @@ func TestResourceAddExtraFields(t *testing.T) {
399399
t.Parallel()
400400

401401
createTestResource := func(name, pn string) *Resource {
402-
return &Resource{
402+
r := &Resource{
403403
Name: name,
404404
ProductMetadata: &Product{
405-
Name: "testproduct",
406-
ProviderName: pn,
405+
Name: "testproduct",
407406
},
408407
}
408+
r.ProductMetadata.SetCompiler(pn)
409+
return r
409410
}
410411

411412
createTestType := func(name, typeStr string, options ...func(*Type)) *Type {
@@ -488,7 +489,7 @@ func TestResourceAddExtraFields(t *testing.T) {
488489
t.Run("WriteOnly property doesn't add companion fields for tgc", func(t *testing.T) {
489490
t.Parallel()
490491

491-
resource := createTestResource("testresource", "tgc")
492+
resource := createTestResource("testresource", "terraformgoogleconversionnext")
492493
writeOnlyProp := createTestType("password", "String",
493494
withWriteOnly(true),
494495
withRequired(true),

mmv1/api/type.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ func (t *Type) GetPrefix() string {
607607
if t.ParentMetadata == nil {
608608
nestedPrefix := ""
609609
// TODO: Use the nestedPrefix for tgc provider to be consistent with terraform provider
610-
if t.ResourceMetadata.NestedQuery != nil && !strings.Contains(t.ResourceMetadata.Compiler, "terraformgoogleconversion") {
610+
if t.ResourceMetadata.NestedQuery != nil && !strings.Contains(t.ResourceMetadata.ProductMetadata.Compiler, "terraformgoogleconversion") {
611611
nestedPrefix = "Nested"
612612
}
613613

mmv1/loader/loader.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,7 @@ func (l *Loader) batchLoadProducts(productNames []string, providerName string) m
154154
// Load compiles a product with all its resources from the given path and optional overrides
155155
// This loads the product configuration and all its resources into memory without generating any files
156156
func (l *Loader) LoadProduct(productName, providerName string) (*api.Product, error) {
157-
p := &api.Product{
158-
ProviderName: providerName,
159-
}
157+
p := &api.Product{}
160158
productYamlPath := filepath.Join(productName, "product.yaml")
161159

162160
var productOverridePath string
@@ -202,6 +200,7 @@ func (l *Loader) LoadProduct(productName, providerName string) (*api.Product, er
202200
p.Version = p.VersionObjOrClosest(l.version)
203201

204202
p.Objects = resources
203+
p.SetCompiler(providerName)
205204
p.Validate()
206205

207206
return p, nil

mmv1/provider/terraform.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,8 @@ func NewTerraform(product *api.Product, versionName string, startTime time.Time,
6464
templateFS: templateFS,
6565
}
6666

67-
t.Product.SetCompiler(ProviderName(t))
6867
t.Product.ImportPath = ImportPathFromVersion(versionName)
6968
for _, r := range t.Product.Objects {
70-
r.SetCompiler(ProviderName(t))
7169
r.ImportPath = t.Product.ImportPath
7270
}
7371

mmv1/provider/terraform_tgc.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ func NewTerraformGoogleConversion(product *api.Product, versionName string, star
5858
templateFS: templateFS,
5959
}
6060

61-
t.Product.SetCompiler(ProviderName(t))
6261
for _, r := range t.Product.Objects {
63-
r.SetCompiler(ProviderName(t))
6462
r.ImportPath = ImportPathFromVersion(versionName)
6563
}
6664

mmv1/provider/terraform_tgc_cai2hcl.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ func NewCaiToTerraformConversion(product *api.Product, versionName string, start
4343
templateFS: templateFS,
4444
}
4545

46-
t.Product.SetCompiler(ProviderName(t))
4746
for _, r := range t.Product.Objects {
48-
r.SetCompiler(ProviderName(t))
4947
r.ImportPath = ImportPathFromVersion(versionName)
5048
}
5149

mmv1/provider/terraform_tgc_next.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ func NewTerraformGoogleConversionNext(product *api.Product, versionName string,
7575
templateFS: templateFS,
7676
}
7777

78-
t.Product.SetCompiler(ProviderName(t))
7978
for _, r := range t.Product.Objects {
80-
r.SetCompiler(ProviderName(t))
8179
r.ImportPath = ImportPathFromVersion(versionName)
8280
}
8381

mmv1/templates/terraform/constants/agent_pool.go.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if not (contains $.Compiler "terraformgoogleconversion") }}
1+
{{- if not (contains $.ProductMetadata.Compiler "terraformgoogleconversion") }}
22
// waitForAgentPoolReady waits for an agent pool to leave the
33
// "CREATING" state and become "CREATED", to indicate that it's ready.
44
func waitForAgentPoolReady(d *schema.ResourceData, config *transport_tpg.Config, timeout time.Duration) error {

0 commit comments

Comments
 (0)