Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add example envtio component #348

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ func applyEnvs(
if err != nil {
return nil, errs.WrapUser(err, "unable to apply module invocation")
}
} else if kind == v2.ComponentKindCDKTF {
} else if kind == v2.ComponentKindCDKTF || kind == v2.ComponentKindEnvtio {
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 {
Expand Down
1 change: 1 addition & 0 deletions apply/golden_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func TestIntegration(t *testing.T) {
{"v2_github_actions_with_pre_commit"},
{"v2_atlantis_depends_on"},
{"v2_cdktf_components"},
{"v2_envtio_components"},
{"generic_providers_yaml"},
}

Expand Down
2 changes: 2 additions & 0 deletions config/v2/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,8 @@ const (
ComponentKindTerraform = DefaultComponentKind
// ComponentKindCDKTF is a CDKTF component
ComponentKindCDKTF ComponentKind = "cdktf"
// ComponentKindEnvtio is a CDKTF component using the envtio framework
ComponentKindEnvtio ComponentKind = "envtio"
// DefaultComponentKind defaults to terraform component
DefaultModuleKind ModuleKind = "terraform"
// ModuleKindTerraform is a terraform Module
Expand Down
2 changes: 1 addition & 1 deletion plan/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ func (p *Plan) buildTurboRootConfig(c *v2.Config) *TurboConfig {
for env, envPlan := range p.Envs {
for component, componentPlan := range envPlan.Components {
kind := componentPlan.Kind.GetOrDefault()
if kind == v2.ComponentKindCDKTF {
if kind == v2.ComponentKindCDKTF || kind == v2.ComponentKindEnvtio {
// applyEnvs implementation detail
pkgs = append(pkgs, fmt.Sprintf("%s/envs/%s/%s", util.RootPath, env, component))
}
Expand Down
6 changes: 4 additions & 2 deletions plan/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,9 @@ func (p *Plan) buildEnvs(conf *v2.Config) (map[string]Env, error) {
"prettier": "^3.3.3",
"typescript": "^5.4.0",
}
if componentConf.Kind.GetOrDefault() == v2.ComponentKindEnvtio {
componentPlan.CdktfDependencies["@envtio/base"] = "0.0.7"
}

for _, dep := range componentConf.CdktfDependencies {
componentPlan.CdktfDependencies[dep.Name] = dep.Version
Expand All @@ -740,9 +743,8 @@ func (p *Plan) buildEnvs(conf *v2.Config) (map[string]Env, error) {
componentBackends := make(map[string]Backend)

for componentName, component := range envPlan.Components {
// FIXME (el): get rid of non-terraform component kinds
kind := component.Kind.GetOrDefault()
if !(kind == v2.ComponentKindTerraform || kind == v2.ComponentKindCDKTF) {
if !(kind == v2.ComponentKindTerraform || kind == v2.ComponentKindCDKTF || kind == v2.ComponentKindEnvtio) {
continue
}

Expand Down
1 change: 1 addition & 0 deletions templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ var Templates = &T{
Components: map[v2.ComponentKind]fs.FS{
v2.ComponentKindTerraform: mustFSSub("templates/component/terraform"),
v2.ComponentKindCDKTF: mustFSSub("templates/component/cdktf"),
v2.ComponentKindEnvtio: mustFSSub("templates/component/envtio"),
},
Env: mustFSSub("templates/env"),
Module: map[v2.ModuleKind]fs.FS{
Expand Down
78 changes: 78 additions & 0 deletions templates/templates/component/envtio/.eslintrc.json.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"env": {
"node": true
},
"root": true,
"plugins": ["@typescript-eslint", "import"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "commonjs",
"project": "./tsconfig.dev.json"
},
"extends": ["plugin:import/typescript", "plugin:prettier/recommended"],
"settings": {
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"]
},
"import/resolver": {
"node": {},
"typescript": {
"project": "./tsconfig.dev.json",
"alwaysTryTypes": true
}
}
},
"ignorePatterns": ["*.js", "*.d.ts", "node_modules/", "*.generated.ts"],
"rules": {
"@typescript-eslint/no-require-imports": ["error"],
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": ["**/test/**"],
"optionalDependencies": false,
"peerDependencies": true
}
],
"import/no-unresolved": ["error"],
"import/order": [
"warn",
{
"groups": ["builtin", "external"],
"alphabetize": {
"order": "asc",
"caseInsensitive": true
}
}
],
"no-duplicate-imports": ["error"],
"no-shadow": ["off"],
"@typescript-eslint/no-shadow": ["error"],
"key-spacing": ["error"],
"no-multiple-empty-lines": ["error"],
"@typescript-eslint/no-floating-promises": ["error"],
"no-return-await": ["off"],
"@typescript-eslint/return-await": ["error"],
"no-trailing-spaces": ["error"],
"dot-notation": ["error"],
"no-bitwise": ["error"],
"@typescript-eslint/member-ordering": [
"error",
{
"default": [
"public-static-field",
"public-static-method",
"protected-static-field",
"protected-static-method",
"private-static-field",
"private-static-method",
"field",
"constructor",
"method"
]
}
],
"eol-last": ["error", "always"],
"space-in-parens": ["error", "never"]
}
}
4 changes: 4 additions & 0 deletions templates/templates/component/envtio/.gitattributes.create
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/.eslintrc.json linguist-generated
/.prettierrc.json linguist-generated
/.gitattributes linguist-generated
/.fogg-component.yaml linguist-generated
17 changes: 17 additions & 0 deletions templates/templates/component/envtio/.gitignore.create
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
*.d.ts
*.js
node_modules
cdktf.out
cdktf.log
*terraform.*.tfstate*
.gen
.terraform
.terraform.lock.hcl
tsconfig.tsbuildinfo
!jest.config.js
!setup.js

// build outputs
cdk.tf.json
assets
dist
3 changes: 3 additions & 0 deletions templates/templates/component/envtio/.prettierrc.json.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"overrides": []
}
32 changes: 32 additions & 0 deletions templates/templates/component/envtio/Makefile.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{ template "fogg_header" }}
lint:
pnpm run eslint
.PHONY: lint

fmt:
pnpm run prettier
.PHONY: fmt

check-plan: cdk.tf.json
terraform init
terraform plan
.PHONY: check-plan

docs:
.PHONY: docs

clean:
rm -rf cdk.tf.json
rm -rf assets
rm -rf node_modules
.PHONY: clean

cdk.tf.json:
pnpm i
pnpm turbo synth
.PHONY: cdk.tf.json

check-updates:
pnpx npm-check-updates@latest --target=minor
@echo "WARNING: update fogg.yml for target package versions"
.PHONY: check-updates
5 changes: 5 additions & 0 deletions templates/templates/component/envtio/README.md.create
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Envtio Component

```console
make check-plan
```
14 changes: 14 additions & 0 deletions templates/templates/component/envtio/package.json.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "{{ list .Env .Name | join "-" }}",
"author": "{{ .Owner }}",
"version": "0.0.0",
"private": true,
"scripts": {
"eslint": "eslint . --ext .ts",
"prettier": "prettier --write .",
"synth": "npx ts-node --swc -P ./tsconfig.dev.json src/index.ts"
},
"dependencies": {{ .CdktfDependencies | toPrettyJson | indent 2 }},
"devDependencies": {{ .CdktfDevDependencies | toPrettyJson | indent 2 }},
"//" : "Auto-generated by fogg. Do not edit"
}
Loading
Loading