Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
config: call the groupsuffix rootgroup because it is not just a strin…
Browse files Browse the repository at this point in the history
…g suffix anymore

Signed-off-by: Muvaffak Onus <me@muvaf.com>
  • Loading branch information
muvaf committed Nov 17, 2021
1 parent 6d20ea2 commit f089628
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
17 changes: 11 additions & 6 deletions pkg/config/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,17 @@ type Provider struct {
// for "aws_rds_cluster", we drop "aws_" prefix and its group ("rds") to set
// Kind of the resource as "Cluster".
TerraformResourcePrefix string
// GroupSuffix is the suffix to append to resource groups, e.g.
// ".aws.tf.crossplane.io". Defaults to ".<prefix>.tf.crossplane.io".
GroupSuffix string

// RootGroup is the root group that all CRDs groups in the provider are based
// on, e.g. "aws.tf.crossplane.io".
// Defaults to "<TerraformResourcePrefix>.tf.crossplane.io".
RootGroup string

// ShortName is the short name of the provider. Typically, added as a CRD
// category, e.g. "tfaws". Default to "tf<prefix>". For more details on CRD
// categories, see: https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#categories
ShortName string

// ModulePath is the go module path for the tf based provider repo, e.g.
// "github.com/crossplane-contrib/provider-tf-aws"
ModulePath string
Expand All @@ -77,6 +81,7 @@ type Provider struct {
// can add "aws_shield_protection_group$". To skip whole aws waf group, one
// can add "aws_waf.*" to the list.
SkipList []string

// IncludeList is a list of regex for the Terraform resources to be
// skipped. For example, to include "aws_shield_protection_group" into
// the generated resources, one can add "aws_shield_protection_group$".
Expand All @@ -96,10 +101,10 @@ type Provider struct {
// A ProviderOption configures a Provider.
type ProviderOption func(*Provider)

// WithGroupSuffix configures GroupSuffix for resources of this Provider.
// WithGroupSuffix configures RootGroup for resources of this Provider.
func WithGroupSuffix(s string) ProviderOption {
return func(p *Provider) {
p.GroupSuffix = s
p.RootGroup = s
}
}

Expand Down Expand Up @@ -143,7 +148,7 @@ func NewProvider(resourceMap map[string]*schema.Resource, prefix string, moduleP
p := &Provider{
ModulePath: modulePath,
TerraformResourcePrefix: fmt.Sprintf("%s_", prefix),
GroupSuffix: fmt.Sprintf(".%s.tf.crossplane.io", prefix),
RootGroup: fmt.Sprintf("%s.tf.crossplane.io", prefix),
ShortName: fmt.Sprintf("tf%s", prefix),
BasePackages: DefaultBasePackages,
DefaultResourceFn: DefaultResource,
Expand Down
16 changes: 9 additions & 7 deletions pkg/pipeline/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ func Run(pc *config.Provider, rootDir string) { // nolint:gocyclo
}
count := 0
for shortGroup, versions := range resourcesGroups {
group := pc.GroupSuffix
group := pc.RootGroup
if shortGroup != "" {
group = strings.ToLower(shortGroup) + "." + pc.GroupSuffix
group = strings.ToLower(shortGroup) + "." + pc.RootGroup
}
for version, resources := range versions {
versionGen := NewVersionGenerator(rootDir, pc.ModulePath, group, version)
Expand Down Expand Up @@ -108,13 +108,15 @@ func Run(pc *config.Provider, rootDir string) { // nolint:gocyclo
// NOTE(muvaf): gosec linter requires that the whole command is hard-coded.
// So, we set the directory of the command instead of passing in the directory
// as an argument to "find".
goimportsCmd := exec.Command("bash", "-c", "goimports -w $(find . -iname 'zz_*')")
goimportsCmd.Dir = filepath.Clean(filepath.Join(rootDir, "apis"))
if out, err := goimportsCmd.CombinedOutput(); err != nil {
apisCmd := exec.Command("bash", "-c", "goimports -w $(find . -iname 'zz_*')")
apisCmd.Dir = filepath.Clean(filepath.Join(rootDir, "apis"))
if out, err := apisCmd.CombinedOutput(); err != nil {
panic(errors.Wrap(err, "cannot run goimports for apis folder: "+string(out)))
}
goimportsCmd.Dir = filepath.Clean(filepath.Join(rootDir, "internal"))
if out, err := goimportsCmd.CombinedOutput(); err != nil {

internalCmd := exec.Command("bash", "-c", "goimports -w $(find . -iname 'zz_*')")
internalCmd.Dir = filepath.Clean(filepath.Join(rootDir, "internal"))
if out, err := internalCmd.CombinedOutput(); err != nil {
panic(errors.Wrap(err, "cannot run goimports for internal folder: "+string(out)))
}

Expand Down

0 comments on commit f089628

Please sign in to comment.