Skip to content

Commit

Permalink
Generate a standalone "zz_generated.terraformed.go" file for each res…
Browse files Browse the repository at this point in the history
…ource

- Each resource will now have its own resource.Terraformed interface
  implementation file.
- The per-group "zz_generated_terraformed.go" is now split into
  per-resource "zz_generated.terraformed.go" files.
- This helps while generating multiple versions for the CRDs.

Signed-off-by: Alper Rifat Ulucinar <ulucinar@users.noreply.github.com>
  • Loading branch information
ulucinar committed Jan 9, 2024
1 parent 1976411 commit 8e3db0f
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions pkg/pipeline/terraformed.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ type TerraformedGenerator struct {

// Generate writes generated Terraformed interface functions
func (tg *TerraformedGenerator) Generate(cfgs []*terraformedInput, apiVersion string) error {
trFile := wrapper.NewFile(tg.pkg.Path(), tg.pkg.Name(), templates.TerraformedTemplate,
wrapper.WithGenStatement(GenStatement),
wrapper.WithHeaderPath(tg.LicenseHeaderPath),
)
filePath := filepath.Join(tg.LocalDirectoryPath, "zz_generated_terraformed.go")
vars := map[string]any{
"APIVersion": apiVersion,
}
resources := make([]map[string]any, len(cfgs))
index := 0
for _, cfg := range cfgs {
trFile := wrapper.NewFile(tg.pkg.Path(), tg.pkg.Name(), templates.TerraformedTemplate,
wrapper.WithGenStatement(GenStatement),
wrapper.WithHeaderPath(tg.LicenseHeaderPath),
)
filePath := filepath.Join(tg.LocalDirectoryPath, "zz_generated.terraformed.go")
vars := map[string]any{
"APIVersion": apiVersion,
}
resources := make([]map[string]any, len(cfgs))
index := 0
resources[index] = map[string]any{
"CRD": map[string]string{
"Kind": cfg.Kind,
Expand All @@ -64,10 +64,10 @@ func (tg *TerraformedGenerator) Generate(cfgs []*terraformedInput, apiVersion st
},
}
index++
vars["Resources"] = resources
if err := trFile.Write(filePath, vars, os.ModePerm); err != nil {
return errors.Wrapf(err, "cannot write the Terraformed interface implementation file %s", filePath)
}
}
vars["Resources"] = resources
return errors.Wrap(
trFile.Write(filePath, vars, os.ModePerm),
"cannot write terraformed conversion methods file",
)
return nil
}

0 comments on commit 8e3db0f

Please sign in to comment.