Skip to content

Commit

Permalink
Replace templated kong2tf with recursive implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mheap committed Sep 9, 2024
1 parent 283b09a commit 92bcb48
Show file tree
Hide file tree
Showing 43 changed files with 1,522 additions and 1,053 deletions.
3 changes: 2 additions & 1 deletion cmd/file_kong2tf.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ into Terraform resources.`,
kong2TfCmd.Flags().StringVarP(&cmdKong2TfGenerateImportsForControlPlaneID, "generate-imports-for-control-plane-id", "g", "",
"decK file to process. Use - to read from stdin.")
kong2TfCmd.Flags().BoolVar(&cmdKong2TfIgnoreCredentialChanges, "ignore-credential-changes", false,
"Enable flag to add a 'lifecycle' block to each consumer credential, that ignores any changes from local to remote state.")
"Enable flag to add a 'lifecycle' block to each consumer credential, " +
"that ignores any changes from local to remote state.")

return kong2TfCmd
}
41 changes: 23 additions & 18 deletions kong2tf/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ import (
)

type ITerraformBuilder interface {
buildServices(*file.Content, *string, bool)
buildRoutes(*file.Content, *string, bool)
buildGlobalPlugins(*file.Content, *string, bool)
buildControlPlaneVar(*string)
buildServices(*file.Content, *string)
buildRoutes(*file.Content, *string)
buildGlobalPlugins(*file.Content, *string)
buildConsumers(*file.Content, *string, bool)
buildConsumerGroups(*file.Content, *string, bool)
buildUpstreams(*file.Content, *string, bool)
buildCACertificates(*file.Content, *string, bool)
buildCertificates(*file.Content, *string, bool)
buildVaults(*file.Content, *string, bool)
buildConsumerGroups(*file.Content, *string)
buildUpstreams(*file.Content, *string)
buildCACertificates(*file.Content, *string)
buildCertificates(*file.Content, *string)
buildVaults(*file.Content, *string)
getContent() string
}

Expand All @@ -31,16 +32,20 @@ func newDirector(builder ITerraformBuilder) *Director {
}
}

func (d *Director) builTerraformResources(content *file.Content, generateImportsForControlPlaneID *string, ignoreCredentialChanges bool) string {

d.builder.buildGlobalPlugins(content, generateImportsForControlPlaneID, ignoreCredentialChanges)
d.builder.buildServices(content, generateImportsForControlPlaneID, ignoreCredentialChanges)
d.builder.buildUpstreams(content, generateImportsForControlPlaneID, ignoreCredentialChanges)
d.builder.buildRoutes(content, generateImportsForControlPlaneID, ignoreCredentialChanges)
func (d *Director) builTerraformResources(
content *file.Content,
generateImportsForControlPlaneID *string,
ignoreCredentialChanges bool,
) string {
d.builder.buildControlPlaneVar(generateImportsForControlPlaneID)
d.builder.buildGlobalPlugins(content, generateImportsForControlPlaneID)
d.builder.buildServices(content, generateImportsForControlPlaneID)
d.builder.buildUpstreams(content, generateImportsForControlPlaneID)
d.builder.buildRoutes(content, generateImportsForControlPlaneID)
d.builder.buildConsumers(content, generateImportsForControlPlaneID, ignoreCredentialChanges)
d.builder.buildConsumerGroups(content, generateImportsForControlPlaneID, ignoreCredentialChanges)
d.builder.buildCACertificates(content, generateImportsForControlPlaneID, ignoreCredentialChanges)
d.builder.buildCertificates(content, generateImportsForControlPlaneID, ignoreCredentialChanges)
d.builder.buildVaults(content, generateImportsForControlPlaneID, ignoreCredentialChanges)
d.builder.buildConsumerGroups(content, generateImportsForControlPlaneID)
d.builder.buildCACertificates(content, generateImportsForControlPlaneID)
d.builder.buildCertificates(content, generateImportsForControlPlaneID)
d.builder.buildVaults(content, generateImportsForControlPlaneID)
return d.builder.getContent()
}
Loading

0 comments on commit 92bcb48

Please sign in to comment.