Skip to content

Commit

Permalink
feat: Update fogg cdktf templates to use helpers pkg (#360)
Browse files Browse the repository at this point in the history
- chore: remove component src/helpers pkg
- chore: rename envtio to terraconstructs
- feat: Add Javascript package Scopes support
- feat: Add AWS CodeArtifact login helper script
- feat(cdktf-fogg-helpers): Add `FoggTerraStack` for terraconstructs support
- chore(cdktf-fogg-helpers): Add npmignore to exclude node_modules from pkg
- chore(cdktf-fogg-helpers): Update Usage in README
- chore: Bump turbo, vitest versions
- feat: Add cdktf-cli and `cdktf get` scripts to cdktf templates
  • Loading branch information
vincenthsh authored Jan 1, 2025
1 parent 29422f2 commit 3ff113e
Show file tree
Hide file tree
Showing 144 changed files with 1,421 additions and 2,560 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export GO111MODULE=on
all: test install

fmt:
~/go/bin/goimports -w -l .
~/go/bin/goimports -w -l $(shell find . -type f -name '*.go' -not -path "./node_modules/*")
.PHONY: fmt

lint-setup: ## setup linter dependencies
Expand Down
43 changes: 1 addition & 42 deletions apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"strings"

"github.com/pkg/errors"
"github.com/tkrajina/typescriptify-golang-structs/typescriptify"
"golang.org/x/exp/slices"

v2 "github.com/chanzuckerberg/fogg/config/v2"
Expand Down Expand Up @@ -384,17 +383,6 @@ func applyEnvs(
logrus.Debug("applying envs")
pathModuleConfigs = make(PathModuleConfigs)
for env, envPlan := range p.Envs {

foggTSConverter := typescriptify.New().WithInterface(true).WithCustomJsonTag("yaml").Add(plan.Component{})

// TODO: Handle tscriptify customCode?
customCode := map[string]string{}
// TODO: move to fogg npm package
foggTS, err := foggTSConverter.Convert(customCode)
if err != nil {
return nil, errs.WrapUserf(err, "unable to convert Golang structs")
}

logrus.Debugf("applying %s", env)
path := fmt.Sprintf("%s/envs/%s", util.RootPath, env)
err = fs.MkdirAll(path, 0755)
Expand Down Expand Up @@ -483,12 +471,8 @@ func applyEnvs(
if err != nil {
return nil, errs.WrapUser(err, "unable to apply module invocation")
}
} else if kind == v2.ComponentKindCDKTF || kind == v2.ComponentKindEnvtio {
} else if kind == v2.ComponentKindCDKTF || kind == v2.ComponentKindTerraConstruct {
logrus.Warn("module invocations not templated for kind CDKTF")
err := writeStructToTS(fs, foggTS, fmt.Sprintf("%s/src/helpers/fogg-types.generated.ts", path))
if err != nil {
panic(err.Error())
}
writeYamlFile(fs, componentPlan, fmt.Sprintf("%s/.fogg-component.yaml", path))
}
}
Expand Down Expand Up @@ -769,31 +753,6 @@ func writeYamlFile(dest afero.Fs, in interface{}, path string) error {
return afero.WriteFile(dest, path, out, 0644)
}

// helper method supporting afero.Fs to write converted golang structs to a file
func writeStructToTS(dest afero.Fs, converted string, path string) error {
dir, _ := filepath.Split(path)
ospath := filepath.FromSlash(dir)
err := dest.MkdirAll(ospath, 0775)
if err != nil {
return errs.WrapUserf(err, "couldn't create %s directory", dir)
}

f, err := dest.Create(path)
if err != nil {
return errs.WrapUserf(err, "unable to open %q", path)
}
defer f.Close()
if _, err := f.WriteString("/* Do not change, this code is generated from Golang structs */\n\n"); err != nil {
return errs.WrapUserf(err, "unable to write to %q", path)
}
if _, err := f.WriteString(converted); err != nil {
return errs.WrapUserf(err, "unable to write to %q", path)
}

logrus.Infof("%s updated", path)
return nil
}

func removeExtension(path string) string {
return strings.TrimSuffix(path, filepath.Ext(path))
}
Expand Down
2 changes: 1 addition & 1 deletion apply/golden_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestIntegration(t *testing.T) {
{"v2_github_actions_with_pre_commit"},
{"v2_atlantis_depends_on"},
{"v2_cdktf_components"},
{"v2_envtio_components"},
{"v2_terraconstruct_components"},
{"generic_providers_yaml"},
}

Expand Down
13 changes: 10 additions & 3 deletions config/v2/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,14 +578,21 @@ type TurboConfig struct {
RootName *string `yaml:"root_name,omitempty"` // Optional Name for the root package, default: "fogg-monorepo"
SCMBase *string `yaml:"scm_base,omitempty"` // Optional Git comparison base override, default: "main"

DevDependencies []JavascriptDependency `yaml:"dev_dependencies,omitempty"` // Optional additional root dev dependencies, default: []
Scopes []JavascriptPackageScope `yaml:"scopes,omitempty"` // Optional additional scopes, default: []
DevDependencies []JavascriptDependency `yaml:"dev_dependencies,omitempty"` // Optional additional root dev dependencies, default: []
}

type JavascriptDependency struct {
Name string `yaml:"name"` // npm package name
Version string `yaml:"version"` // npm package version
}

type JavascriptPackageScope struct {
Name string `yaml:"name"` // name for example "@vincenthsh"
RegistryUrl string `yaml:"registry_url"` // registry url for example "https://npm.pkg.github.com"
AlwaysAuth bool `yaml:"always_auth"` // always auth flag, default: false
}

// EKSConfig is the configuration for an eks cluster
type EKSConfig struct {
ClusterName string `yaml:"cluster_name"`
Expand Down Expand Up @@ -666,8 +673,8 @@ const (
ComponentKindTerraform = DefaultComponentKind
// ComponentKindCDKTF is a CDKTF component
ComponentKindCDKTF ComponentKind = "cdktf"
// ComponentKindEnvtio is a CDKTF component using the envtio framework
ComponentKindEnvtio ComponentKind = "envtio"
// ComponentKindTerraConstruct is a CDKTF component using the TerraConstructs framework
ComponentKindTerraConstruct ComponentKind = "terraconstruct"
// DefaultComponentKind defaults to terraform component
DefaultModuleKind ModuleKind = "terraform"
// ModuleKindTerraform is a terraform Module
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ require (
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.10.0
github.com/tkrajina/typescriptify-golang-structs v0.2.0
github.com/zclconf/go-cty v1.15.1
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
gopkg.in/go-playground/validator.v9 v9.31.0
Expand Down Expand Up @@ -112,7 +111,6 @@ require (
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/skeema/knownhosts v1.3.0 // indirect
github.com/tkrajina/go-reflector v0.5.5 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -809,10 +809,6 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tencentcloud/tencentcloud-sdk-go v3.0.82+incompatible/go.mod h1:0PfYow01SHPMhKY31xa+EFz2RStxIqj6JFAJS+IkCi4=
github.com/tencentyun/cos-go-sdk-v5 v0.0.0-20190808065407-f07404cefc8c/go.mod h1:wk2XFUg6egk4tSDNZtXeKfe2G6690UVyt163PuUxBZk=
github.com/tkrajina/go-reflector v0.5.5 h1:gwoQFNye30Kk7NrExj8zm3zFtrGPqOkzFMLuQZg1DtQ=
github.com/tkrajina/go-reflector v0.5.5/go.mod h1:ECbqLgccecY5kPmPmXg1MrHW585yMcDkVl6IvJe64T4=
github.com/tkrajina/typescriptify-golang-structs v0.2.0 h1:ZedWk82egydDspGTryAatbX0/1NZDQbdiZLoCbOk4f8=
github.com/tkrajina/typescriptify-golang-structs v0.2.0/go.mod h1:sjU00nti/PMEOZb07KljFlR+lJ+RotsC0GBQMv9EKls=
github.com/tmc/grpc-websocket-proxy v0.0.0-20171017195756-830351dc03c6/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tombuildsstuff/giovanni v0.15.1/go.mod h1:0TZugJPEtqzPlMpuJHYfXY6Dq2uLPrXf98D2XQSxNbA=
github.com/ugorji/go v0.0.0-20180813092308-00b869d2f4a5/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ=
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@biomejs/biome": "1.9.4",
"sherif": "^1.0.2",
"turbo": "^2.3.3",
"vitest": "^2.1.6"
"vitest": "^2.1.7"
},
"packageManager": "[email protected]",
"engines": {
Expand Down
22 changes: 11 additions & 11 deletions packages/cdktf-fogg-constructs/.hack/fogg-types/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/sprig v2.22.0+incompatible // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v1.1.0-alpha.2 // indirect
github.com/ProtonMail/go-crypto v1.1.3 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
Expand All @@ -31,15 +31,15 @@ require (
github.com/blang/semver v3.5.1+incompatible // indirect
github.com/chanzuckerberg/go-misc v1.11.1 // indirect
github.com/cloudflare/circl v1.3.9 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/cyphar/filepath-securejoin v0.2.5 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fatih/color v1.18.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-errors/errors v1.5.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/go-git/go-git/v5 v5.12.0 // indirect
github.com/go-git/go-billy/v5 v5.6.0 // indirect
github.com/go-git/go-git/v5 v5.13.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible // indirect
Expand Down Expand Up @@ -88,7 +88,7 @@ require (
github.com/runatlantis/atlantis v0.30.0 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/skeema/knownhosts v1.2.2 // indirect
github.com/skeema/knownhosts v1.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/tkrajina/go-reflector v0.5.5 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
Expand All @@ -102,15 +102,15 @@ require (
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.18.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
golang.org/x/tools v0.23.0 // indirect
google.golang.org/api v0.171.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9 // indirect
Expand Down
Loading

0 comments on commit 3ff113e

Please sign in to comment.